struts2struts-1struts1

select drop down in struts2, migrating from struts1 to struts2


Below is Struts1 code snippet from jsp

<logic:notEmpty name="user" property="myLanguages" scope="session">
                       <html:select name="user" property="defaultLanguage">
                         <html:optionsCollection label="languageName" name="user" property="myLanguages" value="languageCode"/>
                       </html:select>
</logic:notEmpty>

Below is Struts2 (2.5.16 version) code snippet from jsp which is not working

<s:if test="%{#session.user.myLanguages != null && #session.user.myLanguages != ''}">
                          <s:select list="{#session.user.myLanguages}"
                                      listKey="languageCode" listValue="languageName"
                                      name="user"  value="defaultLanguage"/>
</s:if>

Below is the scriplet code from jsp

<%
User user = (User) session.getAttribute("user");
Vector vMyLang = user.getMyLanguages();
        System.out.println("logon.jsp:vMyLang--- "+vMyLang);
        if(null != vMyLang){
            System.out.println("logon.jsp:vMyLang-----  "+vMyLang.size());//here output(i.e size) is 20
        }
%>

So values exists in the session but i'm not able to get using strut2 tags, there are no error/exception in the logs

Struts1 code is working fine, Struts2 code is not working(i mean drop down is not shown in the UI)

Please help me out what mistake i have done.


Solution

  • Fixed with below piece of code

    <s:if test="%{#session.user.myLanguages != null}">
                              <s:select list="%{#session.user.myLanguages}"
                                          listKey="languageCode" listValue="languageName"
                                          value="%{#session.user.defaultOperaLanguage}/>
    </s:if>