Using Multibox in Struts

By: Ivan Lim Viewed: 153352 times  Printer Friendly Format    


Multibox is a collection of checkbox. When a single checkbox exists, it should be mapped to a Boolean. Such condition does not apply to collection of checkboxes. Here we map it to a String array

  1. Recall that Checkbox cannot exist outside a form. Hence start by defining a form to handle the
    checkboxes around the search display list as follows (Simplified for clarity):

    <html:form action="/manageCustomerList">

    <c:if test='${not empty CUSTOMER_SUMMARY_OBJECTS}'>
    ..
    <html-el:multibox property="idSelections">
    <c:out value='${customer.id}'/>
    </html-el:multibox>

    ..
    </c:if>
    </html:form>
  2. Define ManageCustomersForm to hold the checkbox information and initialize the string array
    as follows.

    public class ManageCustomersForm extends ActionForm {
    private String[] idSelections;
    //getters and setters
    public ManageCustomersForm() {
    init();
    }
    protected void init() {
    idSelections = new String[] { "" };
    }
    ..
    }
  3. Create a ManageCustomersAction to handle it in the package struts.example.search. Leave its execute() method empty.
  4. Add an ActionMapping in struts-config.xml. to associate /manageCustomerList.do with
    ManageCustomersAction and ManageCustomersForm Build Deploy and See how the page displays at this point. This should give you a clear picture of using multibox.


Most Viewed Articles (in Struts )

Latest Articles (in Struts)

Comment on this tutorial