0

I am having issue on migrating some struts 1 code to struts 2. In this case Instead of selecting one single value for the deptIdFromGrid Variable, the value of each iterating element is getting appended on the variable. This was a perfectly working case in struts one, and java pojo classes are not causing any issues either which I have already verified. (getters and setters are correctly in place)

This is the exception i am seeing Unexpected Exception caught setting 'searchUser.deptIdFromGrid' on 'class com.bofa.gems.controller.action.UserRoleAction: Error setting expression 'searchUser.deptIdFromGrid' with value ['-1', '-1', '-1', '-1', '-1', '', '-1', '-1', ]

Code snippet

<select name="searchUser.deptIdFromGrid" id="departmentL<s:property value="%{#count.index}"/>" styleClass="smallselectfordept"
       onKeyDown="javascript:keydownEvent()" onmouseover="onchangeShowTitle(this)"style="width: 250px">

                          <option value="-1" >Select One</option>
                    <s:iterator var="departmentL" value="deptListInGrid">

                    <s:if test="%{searchUser.deptId==#departmentL.id}">
                          <option
                          title='<s:property value="{#departmentL.value}"/>'
                        label='<s:property value="{#departmentL.value"/>'
                          value='<s:property value="{#departmentL.id"/>'
                    selected="selected"><s:property value="{#departmentL.value}" /></option>
                    </s:if>
                          <s:else>
                          <option
                    title='<s:property value="{#departmentL.value}"/>'
                    label='<s:property value="{#departmentL.value"/>'
                    value='<s:property value="{#departmentL.id"/>'
                    ><s:property value="{#departmentL.value}" /></option>
                    </s:else>
                    </s:iterator>
                    </select>
                    </td>
               </s:if>

             <s:else>
             <s:hidden name="searchUser.deptIdFromGrid" value=""></s:hidden>
             <td class="generaltext"><span><s:property value="%{#users.deptName}"/></span></td>
       </s:else>

Struts 1 equivalent code

<html:select property="searchUser.deptIdFromGrid" styleId='<%="departmentL"+count%>' styleClass="smallselectfordept" onKeyDown="javascript:keydownEvent()" onmouseover="onchangeShowTitle(this)">
                                                    <html:option value="-1" >Select One</html:option>
                                                    <%-- <html:optionsCollection    name="UserRoleForm" property="departmentList" label="value" value="id" />  --%> 
                                                        <logic:iterate id="departmentL" name="UserRoleForm"
                                                                        property="deptListInGrid">
                                                                        <bean:define id="selectedId" name="departmentL" property="id" />
                                                                        <logic:equal name="UserRoleForm" property="searchUser.deptId"
                                                                            value="<%=(String)selectedId %>">
                                                                            <option
                                                                                title="<bean:write name="departmentL" property="value"/>"
                                                                                label="<bean:write name="departmentL" property="value"/>"
                                                                                value="<bean:write name="departmentL" property="id"/>"
                                                                                selected="selected"><bean:write name="departmentL"
                                                                                property="value" /></option>
                                                                        </logic:equal>
                                                                        <logic:notEqual name="UserRoleForm" property="searchUser.deptId"
                                                                            value="<%=(String)selectedId %>">
                                                                            <option
                                                                                title="<bean:write name="departmentL" property="value"/>"
                                                                                label="<bean:write name="departmentL" property="value"/>"
                                                                                value="<bean:write name="departmentL" property="id"/>"><bean:write
                                                                                name="departmentL" property="value" /></option>
                                                                        </logic:notEqual>
                                                                    </logic:iterate>
                                                    </html:select>
shashwatZing
  • 1,550
  • 1
  • 17
  • 24
  • What's `deptIdFromGrid`? – Dave Newton Jan 21 '20 at 13:51
  • its defined as int deptIdFromGrid (hence it fails the second time because it tried to append other values as comma seperated string instead of unique value for each iterated item) – shashwatZing Jan 21 '20 at 14:00
  • I have also added the equivalent struts 1 code. – shashwatZing Jan 21 '20 at 14:07
  • How is it being set? Is it loaded on initial rendering? Is there JS that does something? There's not really enough here to help, and the code is hard to read as currently formatted. – Dave Newton Jan 21 '20 at 14:52
  • You have put many values to the single field and it requires to convert them the array on the backend. https://stackoverflow.com/a/25698962/573032 – Roman C Jan 22 '20 at 11:25

0 Answers0