Tuesday, January 25, 2005

Struts and checkboxes

The following is a reminder to those working on implementing checkboxes on their pages.


It is essential that you implement the ActionForm's reset() method. In this method, you must set the fields that populate the checkboxes to false. The reason is that an HTTP request only includes values for selected checkboxes. Any de-selected box will not be a part of the request and so the server-side will be none the wiser that a user un-checked a box.

An important side note (one that cost me quite a while): The reset() method is overloaded with the following variants

 

void reset(ActionMapping mapping, ServletRequest request)

and

void reset(ActionMapping mapping, HttpServletRequest request)


For a web UI, you need to implement the latter. If you use your IDE's intellisense, it is easy to accidentally pick the former since it shows up first in the list of choices.

Tweety thoughts

    follow me on Twitter