Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2007

Tip: Looking for answers? Try searching our database.

Struts checkbox with ActionForm in request scope

Thread view: 
sameergn@gmail.com - 12 Jan 2007 18:21 GMT
Hi,

I am trying to render check boxes using an indexed property say
selectedRole[0..n]. Since the Form is request scope, how one should
code the setter method setSelectedRole(int idx), when the form is
submitted. The number of submitted checkboxes are not known and
setSelectedRole(n) can be called in any order.

Is there any better option than keeping the ActionForm in session? With
session scope also, we will end up in same scenario when session
timeout occurs before user submits the page.

We can count #of request parameters starting with "selectedRole[" in
reset() method and then allocate the array, but this looks ugly.

Thanks,
Sameer
Manish Pandit - 12 Jan 2007 20:04 GMT
samee...@gmail.com wrote:
> Hi,
>
[quoted text clipped - 13 lines]
> Thanks,
> Sameer

One option is to not use an action form for this, and have the action
(the one to which this form is submitted) do a request.getParameter( ).
Note that this will not work if it is a multipart request. You can name
the checkboxes consistently (like cb0 through cb10) and then in a for
loop, check for "presence" of this parameter. If the checkbox is
checked, it'd be present in the request. This way you can know which
ones were checked, and which ones were unchecked (by looking into the
previous state, maybe in the database).

I hope I understood your question correctly, and this helps.

-cheers,
Manish


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.