屬性值如何轉換爲?即在java中如何得到struts的bean:write的值

在項目中,原本一個下拉框 代碼如下:

<html:select property="orgClassList" style="display:none">
<option value="" selected="selected"></option>
<html:optionsCollection name="orgClassList" value="itemId" label="itemName"/>
</html:select>

   以上代碼等同於

<html:select property="p_org_class" style="display:none">
<logic:present name="orgClassList">
<option value="" selected="selected" >默認值</option>
<logic:iterate id="orgClassList" name="orgClassList">
<option value="<bean:write name="orgClassList" property="itemId"/>">
<bean:write name="orgClassList" property="itemName"/>
</option>
</logic:iterate>
</logic:present>
</html:select>

 ,現在要在實現在打開頁面的時候默認值不爲空而爲指定的List中的一個值,則需要通過bean:define,在<%%>中得到List中的值進行判斷 然後在option中加上selected

屬性,代碼如下(假設默認值爲‘省公司’)

寫道
<html:select property="p_org_class" style="display:none">
<!--
<html:optionsCollection name="orgClassList" value="itemId" label="itemName"/>
<option value="" ></option>
-->
<logic:present name="orgClassList">
<option value="" ></option>
<logic:iterate id="orgClassList" name="orgClassList">
<bean:define id="orgClassName" name="orgClassList" property="itemId">
</bean:define>
<%
if(orgClassName.equals("省公司")){
%>
<option selected="selected" value="<bean:write name="orgClassList" property="itemId"/>">
<bean:write name="orgClassList" property="itemName"/>
</option>
<%}else{ %>
<option value="<bean:write name="orgClassList" property="itemId"/>">
<bean:write name="orgClassList" property="itemName"/>
</option>
<%} %>
</logic:iterate>
</logic:present>
</html:select>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章