You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Prior, Simon" <Si...@ds-s.com> on 2002/10/09 11:58:14 UTC
Multibox Problem
> Hi,
>
> I am trying to use the Multibox tag to generate a number of checkboxes on
> a page. This I have done successfully and the generated HTML appears to
> be correct. My problem occurs after selecting a checkbox and then
> submitting the form.
>
> From the documentation I have read, I would expect my FormBean String[]
> property to be populated only with the Value attribute of the selected
> checkboxes. Instead, I am finding my array contains a number of elements
> equal to the number of checkboxes generated on my page with the value set
> to true or false depending on whether the checkbox had been selected.
>
> From my JSP:
>
> <logic:iterate id="workGroup" name="AddProfilesForm"
> property="workGroupsList" type="com.serco.tih.common.shared.WorkGroupVO">
> <TR>
> <TD>
> <html:multibox name="AddProfilesForm"
> property="selectedWorkGroups">
> <bean:write name="workGroup"
> property="workGroupId"/>
> </html:multibox>
> </TD>
> <TD class="standard"><IMG
> src="/SercoTIH/images/clearpixel.gif" alt="" width="1" height="1"
> border="0">
> <bean:write name="workGroup"
> property="workGroupName"/>
> </TD>
> </TR>
> </logic:iterate>
>
> Which generates the following HTML:
>
> <TR>
> <TD>
> <input type="checkbox" name="selectedWorkGroups"
> value="1">
> </TD>
> <TD class="standard"><IMG
> src="/SercoTIH/images/clearpixel.gif" alt="" width="1" height="1"
> border="0">
> Work Group 1
> </TD>
> </TR>
>
> <TR>
> <TD>
> <input type="checkbox" name="selectedWorkGroups"
> value="2">
> </TD>
> <TD class="standard"><IMG
> src="/SercoTIH/images/clearpixel.gif" alt="" width="1" height="1"
> border="0">
> Work Group 2
> </TD>
> </TR>
>
> From my FormBean:
>
> private List workGroupsList;
> private String[] selectedWorkGroups;
>
> /**
> * @return the array of selected work groups
> */
> public String[] getSelectedWorkGroups()
> {
> return selectedWorkGroups;
> }
>
> /**
> * Sets the array of selected work groups
> * @param selectedWorkGroups
> */
> public void setSelectedWorkGroups( String[] selectedWorkGroups )
> {
> this.selectedWorkGroups = selectedWorkGroups;
> }
>
> /**
> * @return the list of all existing work groups
> */
> public List getWorkGroupsList()
> {
> return workGroupsList;
> }
>
> /**
> * Sets the list of all existing work groups
> * @param workGroupsList
> */
> public void setWorkGroupsList( List workGroupsList )
> {
> this.workGroupsList = workGroupsList;
> }
>
> As I explained above, if I selected just the first checkbox, I had
> expected selectedWorkGroups to containing one String with the value of
> "1". However, iterating over selectedWorkGroups I find it contains two
> elements, the first being true and the second false. Similarly, if I only
> select the second checkbox, rather than finding selectedWorkGroups
> contains just "2", it has false and true.
>
> In addition, if I manipulate the selectedWorkGroups String array in my
> Action class such that I add the element "1", my JSP will pick this up and
> check the relevant checkbox. It seems that the JSP can "read" from the
> String array correctly, but not "write".
>
> I am using Struts 1.0.2.
>
> Any suggestions / ideas - I could do without spending another day on this!
>
> Thanks,
>
Simon.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>