2017-08-14 22 views
0

我正在将struts1迁移到struts2 web项目。 以下是struts1的代码。使用struts2选择不应用列表属性,而是使用选项 - >是否可以?

<html:select property="dobYear" styleId="dobYear" styleClass="text_field text2" style="width:70px" onchange="loadDayOptions(this.options[this.options.selectedIndex].value, getElement('dobMonth').options[getElement('dobMonth').options.selectedIndex].value, getElement('dobDay'));"> 
    <html:option value="">--</html:option> 
    <% 
     int thisYear = Calendar.getInstance().get(Calendar.YEAR); 
     int fromYear = thisYear - 17; 
     int toYear = 1900; 
     for(int i=fromYear; i>=toYear; i--){ 

    %> 
    <html:option value="<%=String.valueOf(i) %>"><%=String.valueOf(i) %></html:option> 
    <% } %> 
</html:select> 

如果我想下面使用S在Struts2代码:选择但不使用列表属性,而不是使用<option>,是它好吗?我的语法正确吗?

<s:select value="#{editForm.dobYear}" name="editForm.dobYear" id="dobYear" styleClass="text_field text2" style="width:70px" onchange="loadDayOptions(this.options[this.options.selectedIndex].value, getElement('dobMonth').options[getElement('dobMonth').options.selectedIndex].value, getElement('dobDay'));"> 
    <option value="">--</option> 
    <% 
     int thisYear = Calendar.getInstance().get(Calendar.YEAR); 
     int fromYear = thisYear - 17; 
     int toYear = 1900; 
     for(int i=fromYear; i>=toYear; i--){ 

    %> 
    <option value="<%=String.valueOf(i) %>"><%=String.valueOf(i) %></option> 
    <% } %> 
</s:select> 

回答

0

语法不正确。根据TLD,struts选择标签应该有一个空的主体。

您不能以这种方式使用struts选择标签。但你可以将它转换为html选择

<select value="${editForm.dobYear}" name="editForm.dobYear" id="dobYear" styleClass="text_field text2" style="width:70px" onchange="loadDayOptions(this.options[this.options.selectedIndex].value, getElement('dobMonth').options[getElement('dobMonth').options.selectedIndex].value, getElement('dobDay'));"> 
    <option value="">--</option> 
    <% 
     int thisYear = Calendar.getInstance().get(Calendar.YEAR); 
     int fromYear = thisYear - 17; 
     int toYear = 1900; 
     for(int i=fromYear; i>=toYear; i--){ 

    %> 
    <option value="<%=String.valueOf(i) %>"><%=String.valueOf(i) %></option> 
    <% } %> 
</select> 
相关问题