File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes how to populate formbean property using html:checkbox  values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to populate formbean property using html:checkbox  values" Watch "how to populate formbean property using html:checkbox  values" New topic
Author

how to populate formbean property using html:checkbox values

Poonam Kadu
Ranch Hand

Joined: Jul 21, 2006
Posts: 49
Hi Friends,
I have been facing this problem since a couple of days...
I have a FormBean whose one the property is a collection of a type of objects.Using the formbean , logic:iterate and html:checkbox i could display the content in the jsp... but in the same jsp when the user changes the checboxes (check/uncheck) ...the values don't reflect in the next action..Also my form bean is in session scope...






I am expecting this to happen:
when the user checks/unchecks ...the email/sms property inside the Category bean which is the basic element of the memberAlertList ArrayList (and memberAlertList is a property of the form bean ListMemberAlertsForm) should get set...

Please advice ...

Thanks and regards
Poonam.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Is it rendering the way you think it should? (Note that the nested tags handle this kind of thing for you.)

I can't really read your JSP, and please, when posting code samples, remove stuff that isn't necessary, like the bizarre empty table rows.
Poonam Kadu
Ranch Hand

Joined: Jul 21, 2006
Posts: 49
Hi David,
Yes it does displays the way i want ...it looks something like a table with its last two cols as checkboxes.The checkboxes are checked/unchecked using the values from the formbean property.But when i check /uncheck and click on submit , it shows the old values of the checkbox in the new Action class . Why doesn't it show the updated values?
Sorry for the unnecesary code included.

Thanks,
Poonam
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I asked because only some of the checkboxes appear to have anything indicated they're a nested/array structure in their name, and that by looking at the rendered HTML you'd be able to determine if the names were rendering correctly.
Gian Franco
blacksmith
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
Hi Poonam,

...have a look at this post, are you having the same issue?


"Eppur si muove!"
Poonam Kadu
Ranch Hand

Joined: Jul 21, 2006
Posts: 49
Hi,
I guess its not the same problem.i dont get any null values in the next action...but i get values which were displayed before the next action was invoked.I don't know how to capture the checkbox checked/unchecked value in the boolean variable email,sms in basic element of the collection property of the formbean.
Thanks,
Poonam
Gian Franco
blacksmith
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
Ok. How are you processing the response you get from the user doing next?
Tim Kernan
Greenhorn

Joined: Aug 25, 2010
Posts: 16
Poonam
You may be having the same problem I am having, that is, the HTML pages is correct, indexed properties appear as the should (view html source), data is being displayed correctly.

BUT, when submitted, your ActionForm does not pick up the indexed properties. It appears that the indexed properties in the query string returned to the ActionForm are skipped over, all other properties are parsed by the ActionForm.

If this seems to be your problem, see if the query string (request.getQueryString() ) has actual brackets ("[" and "]" ) around the index or not. That is does it look like: lines%5B0%5D.name=tim or like: lines[0].name=tim ?

See my post: http://www.coderanch.com/t/508028/Struts/Struts-queryString-indexed-properties-not

I have not found a solution other that to write a parser in the Action.execute() method, which seems unnecessary. I am still looking for the right solution.

Hope this helps.
Tim
Poonam Kadu
Ranch Hand

Joined: Jul 21, 2006
Posts: 49
Hi Guys,
Thanks for your quick response,but its still not working
I am posting a simplified version of my problem:

struts-config.xml


ActionForm1.java


TestAction1.java


testcheck.jsp



TestAction2.java


The entry point is type /TestCheck1.do in the browser it invokes TestAction1.java action,populates TestForm1.java and forwards the request to testcheck.jsp.Inside testcheck.jsp ,when the user hits submit button it invokes TestAction2.java Action.TestForm1.java is in session scope and has been tied to both the Action classes.


Hope this example will make my problem more clear.
Thanks,
Poonam
Poonam Kadu
Ranch Hand

Joined: Jul 21, 2006
Posts: 49
Hi Guys,
Thanks for your quick response,but its still not working
I am posting a simplified version of my problem:

struts-config.xml


ActionForm1.java


TestAction1.java


testcheck.jsp



TestAction2.java


The entry point is type /TestCheck1.do in the browser it invokes TestAction1.java action,populates TestForm1.java and forwards the request to testcheck.jsp.Inside testcheck.jsp ,when the user hits submit button it invokes TestAction2.java Action.TestForm1.java is in session scope and has been tied to both the Action classes.


Hope this example will make my problem more clear.
Thanks,
Poonam
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to populate formbean property using html:checkbox values