wood burning stoves 2.0*
The moose likes Struts and the fly likes Struts form not holding values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts form not holding values" Watch "Struts form not holding values" New topic
Author

Struts form not holding values

A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
I am certain it is me missing something blatently obvious, but can anyone offer me any ideas as to why my form won't hold the values after I submit the page ? I have a page where I search for users, the page is then given back a list. I want to be able to modify the users permissions and then submit the page and have the changes take effect, but when I submit the page there is nothing for the action to work on - the data seems to have been lost along the way.

Any thoughts ?
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
I'm not sure if this is the problem or not, but I'd suggest you read the FAQ entry on indexed properties (question 6).


Merrill
Consultant, Sima Solutions
xu yuanzhi
Greenhorn

Joined: Nov 20, 2007
Posts: 6
Many things will cause this problem. I think you may give some reference codes,then others can help you.
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
I think I am working through it now, the issue that is causing me particular grief is working with checkboxes. I will put an update in here when I make some more headway, or if I run into another issue. Again thanks for the help.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
What scope are you using? If your action mapping is using request scope then keep in mind that when your page is submitted a brand new instance of your action form is created and the only fields populated will be the fields submitted as part of the page. This includes fields on your page like text boxes, checkboxes and hidden fields but it does not include values that are just displayed on the screen (such as from c ut or bean:write). If you only have a few fields, you can define them using hidden fields. If you have lots of data then you might have to run the search again.

- Brent
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
(Firstly please let me know if I am using any terms incorrectly, as I often find that I seem to use terms that aren't the generally accepted terms and I am trying to learn all I can ). The scope is request. I am setting the values of the fields each time the page is requested. I know it's something simple that I am missing, as you helped me with a similiar issue in the past. I now have the form to the point where it will start out as false, will allow me to set it to true submit the page and retain that information, but subsequently attempting to set the checkbox back to false does not work. As there is minimal amounts of data involved in this case, I suspect a hidden checkbox would be sufficient. Is it simply a matter of putting a checkbox with the same info only putting hidden instead of checkbox in the tags ?

I have continued to play with the application and discovered something.
Submitting the form several times with the value of false and the form remains false. Submitting one true and then either true or false afterwards always remains true. For this reason I suspect it's an issue with resetting the value of the checkbox upon completion. Is there any quirks with regards to checkboxes ? In the value field should I be putting in something like bean:write individual value of checkbox - or is leaving it blank sufficient ?

thanks as always.
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
So my issue seems to fall down to the fact that I don't have anything in the reset of the bean form. It seems the only way to go about recognizing that a value has been reset is if you first set them all to false. Does that make sense ? I am going based on the docs of the checkbox in struts.

thanks again.
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Right...you need to set the values to false in your reset method...if you are using session scope. When using request scope then a brand new instance of your form is created and the value is set to whatever you do in your constructor (or the declaration of the property). The scope is set by the scope attribute on your action mapping. The default scope is session (though that can be changed).

- Brent
A knibbs
Ranch Hand

Joined: Aug 23, 2006
Posts: 158
Originally posted by Brent Sterling:
Right...you need to set the values to false in your reset method...if you are using session scope. When using request scope then a brand new instance of your form is created and the value is set to whatever you do in your constructor (or the declaration of the property). The scope is set by the scope attribute on your action mapping. The default scope is session (though that can be changed).

- Brent

I am using request scope (the value set in struts config for the action I have scope="request") so unless I am way off that is request scope. I suspect most of my confusion is due to the fact that I am not working with the property directly as it is in a list. I am going to attempt to test a few more things.

thanks again for the help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts form not holding values
 
Similar Threads
submit button + selecting content of field automatically
How to validates fields before submit?
Another simple question
Jsp-page populated after succesful insert
How to clear history of submitted page