You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by vasudevrao gupta <va...@wipro.com> on 2003/12/18 06:00:52 UTC

Check-boxes and formbeans

Hi All, 
I have many checkboxes with the same name in my html form. I use struts
framework. When i submit the form, will i be able to access the
checkboxes as an array in the form bean? Or should i have a seperate
field for each checkbox in the formbean? 

Regards
Vasudevrao gupta


Confidentiality Notice 

The information contained in this electronic message and any attachments to this message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged information. If
you are not the intended recipient, please notify the sender at Wipro or Mailadmin@wipro.com immediately
and destroy all copies of this message and any attachments.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Check-boxes and formbeans

Posted by Andrew Hill <an...@gridnode.com>.
And it wont populate the unchecked ones... which means if each checkbox
doesnt have a unique value (ie: they all have value "true" or "on") you will
get an array containing n instances of "on" where n is equal to the number
of checked checkboxes of that name. Not very helpful.

Best bet is to give them individual values, or individual names, so you can
tell them apart when submitted.

ie: submission of the following:
<input type="checkbox" name="bob" value="on" checked="checked"/>
<input type="checkbox" name="bob" value="on"/>
<input type="checkbox" name="bob" value="on" checked="checked"/>
<input type="checkbox" name="bob" value="on" checked="checked"/>
<input type="checkbox" name="bob" value="on" checked="checked"/>

will give you:
bob == String[] { "on","on","on","on" }

The idea is to use something like:
<input type="checkbox" name="bob" value="1" checked="checked"/>
<input type="checkbox" name="bob" value="2"/>
<input type="checkbox" name="bob" value="3" checked="checked"/>
<input type="checkbox" name="bob" value="4" checked="checked"/>
<input type="checkbox" name="bob" value="5" checked="checked"/>

which will give you:
bob == String[] { "1","3","4","5" }

OR

<input type="checkbox" name="bob1" value="on" checked="checked"/>
<input type="checkbox" name="bob2" value="on"/>
<input type="checkbox" name="bob3" value="on" checked="checked"/>
<input type="checkbox" name="bob4" value="on" checked="checked"/>
<input type="checkbox" name="bob5" value="on" checked="checked"/>

bob1 == "on"
bob2 == null (assuming you reset it or its a request scoped form etc...)
bob3 == "on"
bob4 == "on"
bob5 == "on"

OR (maybe)

You could probably make use of indexed property names too (and init the
array of appropriate length in the reset method)

<input type="checkbox" name="bob[0]" value="on" checked="checked"/>
<input type="checkbox" name="bob[1]" value="on"/>
<input type="checkbox" name="bob[2]" value="on" checked="checked"/>
<input type="checkbox" name="bob[3]" value="on" checked="checked"/>
<input type="checkbox" name="bob[4]" value="on" checked="checked"/>

to get:

bob == String[] { "on",null,"on","on","on" }
Though I havent tried this variant, so I could be wrong, or the semantics
could be subtly different!

-----Original Message-----
From: Gurpreet Dhanoa [mailto:gurpreetd@smartdatainc.com]
Sent: Thursday, 18 December 2003 15:58
To: Struts Users Mailing List; vasudevrao.gupta@wipro.com
Subject: Re: Check-boxes and formbeans


hi

Just declare a property field with the datatype as array like

String[] mycheckBox

It will automatically populate all of the checkbox selected into the array
property


Regards
Gary
----- Original Message -----
From: "vasudevrao gupta" <va...@wipro.com>
To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
Sent: Thursday, December 18, 2003 10:30 AM
Subject: Check-boxes and formbeans


>
> Hi All,
> I have many checkboxes with the same name in my html form. I use struts
> framework. When i submit the form, will i be able to access the
> checkboxes as an array in the form bean? Or should i have a seperate
> field for each checkbox in the formbean?
>
> Regards
> Vasudevrao gupta
>
>
> Confidentiality Notice
>
> The information contained in this electronic message and any attachments
to this message are intended
> for the exclusive use of the addressee(s) and may contain confidential or
privileged information. If
> you are not the intended recipient, please notify the sender at Wipro or
Mailadmin@wipro.com immediately
> and destroy all copies of this message and any attachments.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Re: Check-boxes and formbeans

Posted by Gurpreet Dhanoa <gu...@smartdatainc.com>.
hi

Just declare a property field with the datatype as array like

String[] mycheckBox

It will automatically populate all of the checkbox selected into the array
property


Regards
Gary
----- Original Message -----
From: "vasudevrao gupta" <va...@wipro.com>
To: "'Struts Users Mailing List'" <st...@jakarta.apache.org>
Sent: Thursday, December 18, 2003 10:30 AM
Subject: Check-boxes and formbeans


>
> Hi All,
> I have many checkboxes with the same name in my html form. I use struts
> framework. When i submit the form, will i be able to access the
> checkboxes as an array in the form bean? Or should i have a seperate
> field for each checkbox in the formbean?
>
> Regards
> Vasudevrao gupta
>
>
> Confidentiality Notice
>
> The information contained in this electronic message and any attachments
to this message are intended
> for the exclusive use of the addressee(s) and may contain confidential or
privileged information. If
> you are not the intended recipient, please notify the sender at Wipro or
Mailadmin@wipro.com immediately
> and destroy all copies of this message and any attachments.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Help needed in form beans

Posted by Robert Taylor <rt...@mulework.com>.
You may want to consider creating a separate object to hold these
values in the session and use your form beans for data input.
This way you can decide when to populate your form beans with
the data that you've captured in the session. 

To control when reset() affects my form properties I subclassed
the action form and subclassed ActionMapping to add an isReset()
setReset(boolean reset) methods so I can declaratively define
when reset is to be used by adding the following line in my struts-config
file:

<set-property property="reset" value="false"/>

robert

> -----Original Message-----
> From: vasudevrao gupta [mailto:vasudevrao.gupta@wipro.com]
> Sent: Thursday, December 18, 2003 12:30 AM
> To: 'Struts Users Mailing List'
> Subject: Help needed in form beans
> 
> 
> 
> Hi All,
> 
> I have a same form bean for 5 JSP's(JSP1,JSP2,JSP3,JSP4,JSP5)
> 
> All the JSP's use the same form bean.I am keeping the form bean in the
> session scope.
> 
> When ever I use JSP1, JSP3, I want to see the blank screen even if there
> are some values in the formbean.
> But, in other JSP's, I want to see the screen with prepopulated values.
> I tried using reset() for this and I have set all the values in formbean
> to null.But reset is getting called 
> for all the action.I want reset to be called only for JSP1,JSP3.
> 
> Please provide any direction on this
> 
> Regards
> VasudevRaoGupta
> 
> 
> Confidentiality Notice 
> 
> The information contained in this electronic message and any 
> attachments to this message are intended
> for the exclusive use of the addressee(s) and may contain 
> confidential or privileged information. If
> you are not the intended recipient, please notify the sender at 
> Wipro or Mailadmin@wipro.com immediately
> and destroy all copies of this message and any attachments.
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: struts-user-help@jakarta.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


Help needed in form beans

Posted by vasudevrao gupta <va...@wipro.com>.
Hi All,

I have a same form bean for 5 JSP's(JSP1,JSP2,JSP3,JSP4,JSP5)

All the JSP's use the same form bean.I am keeping the form bean in the
session scope.

When ever I use JSP1, JSP3, I want to see the blank screen even if there
are some values in the formbean.
But, in other JSP's, I want to see the screen with prepopulated values.
I tried using reset() for this and I have set all the values in formbean
to null.But reset is getting called 
for all the action.I want reset to be called only for JSP1,JSP3.

Please provide any direction on this

Regards
VasudevRaoGupta


Confidentiality Notice 

The information contained in this electronic message and any attachments to this message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged information. If
you are not the intended recipient, please notify the sender at Wipro or Mailadmin@wipro.com immediately
and destroy all copies of this message and any attachments.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Check-boxes and formbeans

Posted by Amit Kumar Sharma <am...@sysarris.soft.net>.
what is the solution for that than ?we can't keep two array to maintain the
values attached....because of this limitation I had to change the complete
logic of the page...
If anybody also has encountered the same problem please do share and the
solution too.

-----Original Message-----
From: Jitesh Sinha [mailto:jsinha@cisco.com]
Sent: Thursday, December 18, 2003 11:27 AM
To: Struts Users Mailing List; amit.ks@sysarris.soft.net
Subject: RE: Check-boxes and formbeans


that's correct...you won't be able to get unchecked checkboxes....

-----Original Message-----
From: Amit Kumar Sharma [mailto:amit.ks@sysarris.soft.net]
Sent: Thursday, December 18, 2003 10:57 AM
To: Struts Users Mailing List
Subject: RE: Check-boxes and formbeans


I had the same problem....when we do
request.getParameterValues(ARRAY_OF_CHECKBOX) the unchecked checkboxes didnt
appeared in the new array...only the checked ones were there.

-----Original Message-----
From: Jitesh Sinha [mailto:jsinha@cisco.com]
Sent: Thursday, December 18, 2003 10:47 AM
To: Struts Users Mailing List
Subject: RE: Check-boxes and formbeans


you will be able to access fields with same name as an array...

-----Original Message-----
From: vasudevrao gupta [mailto:vasudevrao.gupta@wipro.com]
Sent: Thursday, December 18, 2003 10:31 AM
To: 'Struts Users Mailing List'
Subject: Check-boxes and formbeans



Hi All,
I have many checkboxes with the same name in my html form. I use struts
framework. When i submit the form, will i be able to access the
checkboxes as an array in the form bean? Or should i have a seperate
field for each checkbox in the formbean?

Regards
Vasudevrao gupta


Confidentiality Notice

The information contained in this electronic message and any attachments to
this message are intended
for the exclusive use of the addressee(s) and may contain confidential or
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or
Mailadmin@wipro.com immediately
and destroy all copies of this message and any attachments.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Check-boxes and formbeans

Posted by Jitesh Sinha <js...@cisco.com>.
that's correct...you won't be able to get unchecked checkboxes....

-----Original Message-----
From: Amit Kumar Sharma [mailto:amit.ks@sysarris.soft.net]
Sent: Thursday, December 18, 2003 10:57 AM
To: Struts Users Mailing List
Subject: RE: Check-boxes and formbeans


I had the same problem....when we do
request.getParameterValues(ARRAY_OF_CHECKBOX) the unchecked checkboxes didnt
appeared in the new array...only the checked ones were there.

-----Original Message-----
From: Jitesh Sinha [mailto:jsinha@cisco.com]
Sent: Thursday, December 18, 2003 10:47 AM
To: Struts Users Mailing List
Subject: RE: Check-boxes and formbeans


you will be able to access fields with same name as an array...

-----Original Message-----
From: vasudevrao gupta [mailto:vasudevrao.gupta@wipro.com]
Sent: Thursday, December 18, 2003 10:31 AM
To: 'Struts Users Mailing List'
Subject: Check-boxes and formbeans



Hi All,
I have many checkboxes with the same name in my html form. I use struts
framework. When i submit the form, will i be able to access the
checkboxes as an array in the form bean? Or should i have a seperate
field for each checkbox in the formbean?

Regards
Vasudevrao gupta


Confidentiality Notice

The information contained in this electronic message and any attachments to
this message are intended
for the exclusive use of the addressee(s) and may contain confidential or
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or
Mailadmin@wipro.com immediately
and destroy all copies of this message and any attachments.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Check-boxes and formbeans

Posted by Amit Kumar Sharma <am...@sysarris.soft.net>.
I had the same problem....when we do
request.getParameterValues(ARRAY_OF_CHECKBOX) the unchecked checkboxes didnt
appeared in the new array...only the checked ones were there.

-----Original Message-----
From: Jitesh Sinha [mailto:jsinha@cisco.com]
Sent: Thursday, December 18, 2003 10:47 AM
To: Struts Users Mailing List
Subject: RE: Check-boxes and formbeans


you will be able to access fields with same name as an array...

-----Original Message-----
From: vasudevrao gupta [mailto:vasudevrao.gupta@wipro.com]
Sent: Thursday, December 18, 2003 10:31 AM
To: 'Struts Users Mailing List'
Subject: Check-boxes and formbeans



Hi All,
I have many checkboxes with the same name in my html form. I use struts
framework. When i submit the form, will i be able to access the
checkboxes as an array in the form bean? Or should i have a seperate
field for each checkbox in the formbean?

Regards
Vasudevrao gupta


Confidentiality Notice

The information contained in this electronic message and any attachments to
this message are intended
for the exclusive use of the addressee(s) and may contain confidential or
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or
Mailadmin@wipro.com immediately
and destroy all copies of this message and any attachments.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Check-boxes and formbeans

Posted by Jitesh Sinha <js...@cisco.com>.
you will be able to access fields with same name as an array...

-----Original Message-----
From: vasudevrao gupta [mailto:vasudevrao.gupta@wipro.com]
Sent: Thursday, December 18, 2003 10:31 AM
To: 'Struts Users Mailing List'
Subject: Check-boxes and formbeans



Hi All,
I have many checkboxes with the same name in my html form. I use struts
framework. When i submit the form, will i be able to access the
checkboxes as an array in the form bean? Or should i have a seperate
field for each checkbox in the formbean?

Regards
Vasudevrao gupta


Confidentiality Notice

The information contained in this electronic message and any attachments to
this message are intended
for the exclusive use of the addressee(s) and may contain confidential or
privileged information. If
you are not the intended recipient, please notify the sender at Wipro or
Mailadmin@wipro.com immediately
and destroy all copies of this message and any attachments.

---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org