• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

No request parameter found in reset method of ActionForm

 
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic