1

Below is the html tag multibox which i want to migrate it to struts 2

<html:multibox name="unitForm" property="eservices">
    <bean:write name="service"/>
</html:multibox>

as it is checkbox so thought of using simple checkbox which is in the iterator so i used below code

<s:checkbox theme="simple" name="unitForm.eservices"></s:checkbox>

in action

String[] toArray = new String[selectedadminVOs.size()];
unitForm.setEservices(selectedadminVOs.toArray(toArray));

stuck here,without or minimal changes in action code how can i migrate it to struts2

Roman C
  • 49,761
  • 33
  • 66
  • 176
happy
  • 2,550
  • 17
  • 64
  • 109

1 Answers1

2

The <html:multibox> equivalent in Struts 2 is

<s:iterator var="row" value="%{unitForm.eservices}">
    <input type="checkbox" name="unitForm.checked" 
        value="${row.service}" ${unitForm.checked.contains(row.service)?'checked="checked"':''}/>    
</s:iterator>

or you can use s:property tag

<s:iterator var="row" value="%{unitForm.eservices}">
    <input type="checkbox" name="unitForm.checked" 
        value="${row.service}" <s:property value="%{unitForm.checked.contains(#row.service)?'checked="checked"':''}"/>/>    
</s:iterator>
Roman C
  • 49,761
  • 33
  • 66
  • 176
  • I tried your solution but I have this error: Encountered "(". Expected one of : "}", ".", "[", ">", "gt", "<", "lt", ">=", "ge", "<=", "le", "==", "eq", "!=", "ne", "&&", "and", "||", "or", "*", "+", "-", "?", "/", "div", "%", "mod", [java] value="${row.service}" ${selectedfiles.contains(row.service)?'checked="checked"':''}/> where selectedfiles is name of input – Ariana Mar 24 '17 at 10:30
  • Hi Roman (this is not a rhetorical question), but wondering why you havn't mentioned an s:checkboxlist... is it not appropriate in this case? – johnm Apr 02 '20 at 08:48
  • @johnm it could be appropriate if you find a solution to the problem like I did in this answer before. – Roman C Apr 03 '20 at 10:27