重新總結(jié)struts標(biāo)簽嵌套錯(cuò)誤
首先,上一篇中轉(zhuǎn)的html:select標(biāo)簽的示例二中的嵌套是錯(cuò)誤的。
//比較beanname中的id是否和cl中的id相同,如果相同就顯示cl中的name
<bean:write name="cl" property="name"/>
</logic:equal>
</logic:iterate>
<bean:define id="temId" name="cl" property="id" type="java.lang.String"/>
<logic:equal name="beanname" property="id" value="<%=temId%>">
<bean:write name="cl" property="name"/>
</logic:equal>
</logic:iterate>
<bean:message key = "welcome.logon" bundle = "base"/>
</html:submit>
剛開(kāi)始使用struts標(biāo)簽時(shí),很痛苦,三個(gè)人窩在實(shí)驗(yàn)室里把struts罵了個(gè)遍,但用還是得用,而且強(qiáng)制用,必須學(xué)會(huì)。我因?yàn)橹坝玫氖莣ebwork,所以老是拿兩個(gè)做對(duì)比,不過(guò)現(xiàn)在好了,struts2出來(lái)啦!!
struts標(biāo)簽的用法網(wǎng)上很多,這里也就不說(shuō)了,要說(shuō)的是在這次運(yùn)用struts標(biāo)簽過(guò)程中的一些問(wèn)題和經(jīng)驗(yàn)。
1、頁(yè)面action嵌套,因?yàn)槭欠止ず献鳎齻€(gè)人分別完成各自模塊,最后進(jìn)行組裝。所以避免不了,一個(gè)頁(yè)面會(huì)有多個(gè)action組成。那么怎么運(yùn)用struts標(biāo)簽進(jìn)行action組裝呢?
<bean:include id="liststeptype" page="/step/steptype.html?event=listStepType" />
<bean:write name="liststeptype" filter="false"/>
先利用include創(chuàng)建一個(gè)id為liststeptype的模塊,page的值為指定action的url,再通過(guò)write將其顯示出來(lái),filter如果為ture則顯示頁(yè)面源碼,為false顯示html頁(yè)面。
2、Date型數(shù)據(jù)的頁(yè)面顯示,理想狀態(tài)是顯示為“YYYY-mm-DD”,如果是formbean中的屬性還好辦一點(diǎn),直接在進(jìn)行數(shù)據(jù)類(lèi)型轉(zhuǎn)換的時(shí)候就 把樣式給format了,但是如果是對(duì)象列表呢,通過(guò)循環(huán)標(biāo)簽顯示,沒(méi)法利用struts標(biāo)簽調(diào)用format函數(shù)(struts標(biāo)簽不支持此功能),對(duì) 此想個(gè)多個(gè)方案,最高的一個(gè)是重寫(xiě)Date的toString方法,最簡(jiǎn)單的是利用bean:write 中的format的屬性(這是郁悶了很久后無(wú)意中發(fā)現(xiàn)的)。
3、formbean中不能接收Object類(lèi)型的屬性,這點(diǎn)著實(shí)郁悶了很久,所以遇到需要用到Object類(lèi)型的數(shù)據(jù)時(shí)只能再手動(dòng)轉(zhuǎn)換。
4、復(fù)選框的運(yùn)用。struts標(biāo)簽中,到系統(tǒng)完成都沒(méi)能很好運(yùn)用的便是復(fù)選框,所以每次遇到需要用到復(fù)選框就直接使用jsp標(biāo)簽替代了,簡(jiǎn)單快速。
5、struts標(biāo)簽不能嵌套。struts標(biāo)簽中的html標(biāo)簽,一般來(lái)說(shuō)value值為與property同名的formbean中的屬性值,當(dāng)然value的值也能指定,但卻不能動(dòng)態(tài)獲取,比如要想property1的value等于formbean中property2的值。對(duì)此討論除了兩個(gè)方案,使用jsp標(biāo)簽或者EL表達(dá)式(即${property2})。
6、下拉框的運(yùn)用。
<html:select property="mnEquipmentId">
<html:option value="0">------請(qǐng)選擇------</html:option>
<html:optionsCollection property="equipmentList" label="name" value="id"/>
或<html:options collection="equipmentList" labelProperty="name" property="id" />
</html:select>
把結(jié)果存入一個(gè)ArrayList作為 request 的一個(gè)屬性傳到頁(yè)面上, 這時(shí)一般用 <html:options .../> 標(biāo)簽;如果數(shù)據(jù)放到 formbean里,作為屬性在頁(yè)面上取,這時(shí)一般用 <html:optionsCollection ... />
posted on 2011-05-30 15:33 強(qiáng)強(qiáng) 閱讀(659) 評(píng)論(0) 編輯 收藏 所屬分類(lèi): Java