Search code examples
struts

struts reset() is not called before populating the form


I got a strange (and probably) wrong behaviour here. I was trying to put a checkbox on the page, and you know it: unchecked checkboxes are not written to the request (only checked boxes are)

What struts normally offers is to override:

@Override
public void reset(ActionMapping mapping, ServletRequest request)

to reset all the checkboxes to "false". But in my case, this reset() is never called!

Someone got an idea?

Thanks in advance,

mana


Solution

  • The reset method is automatically called by the Struts framework (your observation on The Elite Gentleman's answer is correct)... that is if you did everything by the book.

    Check the following:

    1. are you extending an ActionForm class or something else?
    2. did you by any chance overwrite the reset method in a subclass of the one you are not getting the method called and you use that for your action?
    3. are you managing the form life cycle by hand, instead of letting Struts do it?
    4. in struts-config, did you specify that your action uses that particular form by specifying the name attribute on the action tag?

    My money is on number 4.