mana
mana

Reputation: 6547

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

Upvotes: 4

Views: 22164

Answers (5)

Yasser
Yasser

Reputation: 64

I had a similar problem.

The solution was to add attribute scope="request" in the action tag in struts-config.xml

Upvotes: 2

sateesh
sateesh

Reputation: 1

prototype of reset() method is:

public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request)

If we are not using reset() method when that time we are trying to open our application then previous values will be coming automatically.
If we are using this reset() method the previous values will be reset into empty values. So by using this reset() method we can avoid previous values.

Upvotes: 0

Azam Abdul Rahim
Azam Abdul Rahim

Reputation: 51

The correct method signature to override is

public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request)

Upvotes: 4

user159088
user159088

Reputation:

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.

Upvotes: 2

Buhake Sindi
Buhake Sindi

Reputation: 89169

Reset is never called by default, you have to call it through your actions (if you want to reset your form),

alternatively, on your jsp, you'll have <html:reset /> tag and override the reset method of ActionForm. this helps.

Upvotes: 0

Related Questions