Hm, I guess this is a less intrusive solution for posting the checkbox array through a page which it is not visible on:
<c:forEach items="${myform.personIds}" var="id"> <input type="hidden" name="personIds" value="${id}"> </c:forEach> Mike > I have the following problem with checkbox arrays. I would > really appreciate clues on what is the best workaround. > > PROJECT SETUP > ------------- > The situation is this: > - I have a data entry page flow with multiple pages > entering data into a form bean stored on the session > (all the actions share the same form bean). > - Several pages contain checkboxes so I have to reset > their corresponding form properties in an overridden > ActionForm.reset() method. > - Some of these checkboxes appear on the first page only > and causes a problem as the form will reset their > properties when navigating to the second page, but they > will not be repopulated as they don't have a control on > this page and therefore will remain cleared. > > For simple checkboxes I just put a corresponding > <html:hidden> field on the pages that shouldn't render that > particular checkbox. The hidden field makes sure the non- > existing (on this page) checkbox's value is posted through > to the action and thus repopulated into the form, so it > will still keep its value despite the reset code. > > PROBLEM > ------- > But, for array checkboxes created with <html:multibox> I > don't succeed with this solution. The solution with the > hidden field I used for simple checkboxes will only hold > one value, and thus will only keep one of potentially many > selections in the checkbox array. > > How should this best be solved? > > CURRENT WORKAROUND > ------------------ > At the moment I have implemented a workaround that will only > reset the checkbox array when populating from a page that > actually contains the corresponding checkboxes. I do this by > adding a hidden "flag" field that signals that the page > contains the checkboxes and I can later use this as a > conditional in the reset method: > > page1.jsp > <input type="hidden" name="hasPersonCheckboxes"> > <c:forEach items="${personList}" var="person"> > <html:multibox property="personIds"> > <c:out value="${person.id}"/> > </html:multibox> > <c:out value="${person.name}"/> > </c:forEach> > > MyActionForm.java: > public void reset(ActionMapping mapping, HttpServletRequest request) > { > if ( request.getParameter("hasPersonCheckboxes") != null ) > personIds = new Long[0]; > } > > This way, if page2.jsp doesn't contain a hasPersonCheckboxes > field, the personIds attribute will not be cleared when > navigating to this page and will retain its value (given > that the form bean scope remains on the session). > > But, there may be a better and cleaner solution? > (Sometimes I wish that Struts would include support for > handling all this checkbox reset stuff. F ex, each rendering > of Struts' checkbox or multibox tags could make additions to > some Struts managed hidden field that records what checkboxes > are placed in the form, and could use this for automagically > clearing the appropriate properties.) > > Mike --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]