This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Struts and the fly likes No request parameter found in reset method of ActionForm Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Frameworks » Struts
Bookmark "No request parameter found in reset method of ActionForm" Watch "No request parameter found in reset method of ActionForm" New topic
Author

No request parameter found in reset method of ActionForm

peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
struts Implementation-Version: 1.2.7

I use javascript to submit a form and in the reset method of the ActionForm, I check the request.getParameter("xxx") and found that they are null.
But when I check the same parameter in execute method of Action, it can show correctly, that is, request.getParameter("xxx") != null, what is the reason?

what I want to do is detect the checked status of a checkbox (let say ck1), if it is unchecked, the request parameter
"ck1" should be null, if it is checked, the request parameter "ck1" is not null, but I found request.getParameter("ck1") is always null in reset method of actionForm, so what is the correct method to implement it?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

peter tong wrote:I use javascript to submit a form and in the reset method of the ActionForm, I check the request.getParameter("xxx") and found that they are null.
But when I check the same parameter in execute method of Action, it can show correctly, that is, request.getParameter("xxx") != null, what is the reason?

They haven't been set yet. Resetting ActionForm values *after* they've been set by the form submission would be pointless.

Checkboxes should be set to their default value in reset, the rest is handled by Struts.
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
David Newton wrote:
peter tong wrote:I use javascript to submit a form and in the reset method of the ActionForm, I check the request.getParameter("xxx") and found that they are null.
But when I check the same parameter in execute method of Action, it can show correctly, that is, request.getParameter("xxx") != null, what is the reason?

They haven't been set yet. Resetting ActionForm values *after* they've been set by the form submission would be pointless.

Checkboxes should be set to their default value in reset, the rest is handled by Struts.


I still cannot catch the idea...why all parameter in request.getParameter("xxx") return null in reset method after form submission but before execute method in
Action??
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Because Struts hasn't copied the values from the HTML form to the ActionForm yet.

If it did, the reset() method would overwrite the values from the HTML form, which would be incorrect behavior: the reset() method exists to set form values to their defaults *before* getting the HTML form values. This is particularly useful for checkboxes, which when unchecked, aren't sent at all.
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
David Newton wrote:Because Struts hasn't copied the values from the HTML form to the ActionForm yet.

If it did, the reset() method would overwrite the values from the HTML form, which would be incorrect behavior: the reset() method exists to set form values to their defaults *before* getting the HTML form values. This is particularly useful for checkboxes, which when unchecked, aren't sent at all.


but the problem is not the form bean variable is null, but is all parameter in request is null...why will this happen??
anyway, for checkbox, is it need to set all checkbox to false in reset method and then if the html form checkbox element is checked, then it will cause the corresponding boolean varialbe in form bean to true after reset method is executed, if the html form checkbox is not checked, then the reset method cause the corresponding form bean boolean vairable to false?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Oh, I'm sorry; I misunderstood what you were saying. I have no idea, I've never needed to look at the request in a reset method().

I'm not sure what your last question was, though.
peter tong
Ranch Hand

Joined: Mar 15, 2008
Posts: 240
David Newton wrote:Oh, I'm sorry; I misunderstood what you were saying. I have no idea, I've never needed to look at the request in a reset method().

I'm not sure what your last question was, though.


my last question was is it need to set all checkbox to false in reset method of ActionForm? the logic I think is:
if the checkbox is checked in html form, then after reset method, setter method will be called in ActionForm and set the property to true again.
if the checkbox is not checked in html form, then after reset method, setter method will not be called for that checkbox and so it is false.

Also, if anyone knows why all parameters in request is null in reset method of ActionForm, please advise, thanks.
 
GeeCON Prague 2014
 
subject: No request parameter found in reset method of ActionForm