I would like to have the value of my multibox to be set dynamically from the form. I'm using a <display:table />
tag to show a list in my form in a table however, I have checboxes on every row on the table which I would like the value
and disabled
attributes set depending on the object in the list that corresponds with that row in the table. This is what I'm currently doing.
<display:table name="sessionScope.SearchForm.companyDevices" requestURI="my/action.jspa">
<display:column>
<html:multibox property="selectedDevices"
value="${macAddress}" <!-- HERE -->
disabled="${isAssigned}"/> <!-- AND HERE -->
</display:column>
<display:column property="macAddress" title="Mac Address" />
<display:column property="vendor" title="Vendor"/>
<display:column property="model" title="Model"/>
<display:column property="deviceStatus" title="Device Status" />
</display:table>
As you can see a column property uses the same macAddress
bean value and it displays the macAddress there successfully, however in the multibox it doesn't set the value to the macAddress for some reason. Same goes for the disabled
attribute.
I can't seem to identify what is wrong. How do I set dynamic values for multiboxes in a display:table
?
I figured out a way. I replaced the multibox tag above with
<display:table name="sessionScope.SearchForm.companyDevices" requestURI="my/action.jspa" id="device"> <!-- ID ATTRIBUTE ADDED -->
<html:multibox property="selectedDevices"><bean:write name="searchForm" property="companyDevices[${row_rowNum - 1}].macAddress" /></html:multibox>
rowNum
is an implicitly created variable in struts and to retrieve the row Number for a particular row. To identify a row an Id needs to be assigned. By setting the id to 'device' in the display:table
I use device_rowNum
(the implicitly created variable from the combination of my the id
attribute and rowNum
) get a row's particular number which is associated with its position in the list to be able to retrieve the value that I want.