Re: Struts checkbox with ActionForm in request scope
- From: "Manish Pandit" <pandit.manish@xxxxxxxxx>
- Date: 12 Jan 2007 12:04:16 -0800
samee...@xxxxxxxxx wrote:
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
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
.
- References:
- Struts checkbox with ActionForm in request scope
- From: sameergn
- Struts checkbox with ActionForm in request scope
- Prev by Date: Re: sending Objects and Strings over TCP/IP
- Next by Date: Re: File Read in 2 JVM
- Previous by thread: Struts checkbox with ActionForm in request scope
- Index(es):
Relevant Pages
|