You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by akoo <og...@yahoo.com> on 2009/12/04 19:31:18 UTC

checkbox : unchecked elements not in list

I have following form 

<s:form action="updateAccount">
<s:iterator value="accounts">
<s:property name="account"/>
<s:checkbox name="accountStatus" value=={active}/>

.....
</s:iterator>
</s:form>




In my action class I have following

public UpdateAccount account
{
	List accountStatus;//list to hold all the checkbox values
	List accounts; //list to hold all the accounts values

	// getter setters

	public String execute()
	{
		//iterate through the list of accounts/
		//set account status value  to that list accountStatus
	}

}

Ideally I would want the accountStatus list to contains a list of "true" or
"false" strings, however accountStatus list only seems to contains only the
checked
elements...
-- 
View this message in context: http://old.nabble.com/checkbox-%3A-unchecked-elements-not-in-list-tp26636367p26636367.html
Sent from the Struts - User mailing list archive at Nabble.com.


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


RE: checkbox : unchecked elements not in list

Posted by Colin NG <co...@hotmail.com>.
The use "accounts" in s:iterator is wrong. It probably works if you can create something like "new int [7]".
 
> Date: Fri, 4 Dec 2009 12:50:36 -0600
> Subject: Re: checkbox : unchecked elements not in list
> From: elephantium@gmail.com
> To: user@struts.apache.org
> 
> Unchecked checkboxes in html forms don't submit a value. If you want true
> vs. false submitted back to the Java action, you'll need to use radio
> buttons.
> 
> -Brian
> 
> On Fri, Dec 4, 2009 at 12:31 PM, akoo <og...@yahoo.com> wrote:
> 
> >
> > I have following form
> >
> > <s:form action="updateAccount">
> > <s:iterator value="accounts">
> > <s:property name="account"/>
> > <s:checkbox name="accountStatus" value=={active}/>
> >
> > .....
> > </s:iterator>
> > </s:form>
> >
> >
> >
> >
> > In my action class I have following
> >
> > public UpdateAccount account
> > {
> > List accountStatus;//list to hold all the checkbox values
> > List accounts; //list to hold all the accounts values
> >
> > // getter setters
> >
> > public String execute()
> > {
> > //iterate through the list of accounts/
> > //set account status value to that list accountStatus
> > }
> >
> > }
> >
> > Ideally I would want the accountStatus list to contains a list of "true" or
> > "false" strings, however accountStatus list only seems to contains only the
> > checked
> > elements...
> > --
> > View this message in context:
> > http://old.nabble.com/checkbox-%3A-unchecked-elements-not-in-list-tp26636367p26636367.html
> > Sent from the Struts - User mailing list archive at Nabble.com.
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
 		 	   		  
_________________________________________________________________
Windows Live: Make it easier for your friends to see what you’re up to on Facebook.
http://go.microsoft.com/?linkid=9691816

Re: checkbox : unchecked elements not in list

Posted by Brian Thompson <el...@gmail.com>.
Unchecked checkboxes in html forms don't submit a value.  If you want true
vs. false submitted back to the Java action, you'll need to use radio
buttons.

-Brian

On Fri, Dec 4, 2009 at 12:31 PM, akoo <og...@yahoo.com> wrote:

>
> I have following form
>
> <s:form action="updateAccount">
> <s:iterator value="accounts">
> <s:property name="account"/>
> <s:checkbox name="accountStatus" value=={active}/>
>
> .....
> </s:iterator>
> </s:form>
>
>
>
>
> In my action class I have following
>
> public UpdateAccount account
> {
>        List accountStatus;//list to hold all the checkbox values
>        List accounts; //list to hold all the accounts values
>
>        // getter setters
>
>        public String execute()
>        {
>                //iterate through the list of accounts/
>                //set account status value  to that list accountStatus
>        }
>
> }
>
> Ideally I would want the accountStatus list to contains a list of "true" or
> "false" strings, however accountStatus list only seems to contains only the
> checked
> elements...
> --
> View this message in context:
> http://old.nabble.com/checkbox-%3A-unchecked-elements-not-in-list-tp26636367p26636367.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

RE: checkbox : unchecked elements not in list

Posted by Neil Aggarwal <ne...@JAMMConsulting.com>.
> Ideally I would want the accountStatus list to contains a 
> list of "true" or
> "false" strings, however accountStatus list only seems to 
> contains only the
> checked
> elements...

It looks like you are processing the submitted params
yourself.  If that is the case, the browser only gives 
you values for the checked boxes.  That is an http limitation, 
not struts.  If you want to do it that way, you will have
to check for the non-presence of unchecked boxes.

Struts will handle the checkboxes correctly if you let it handle 
the form submission.  On my form bean, I have boolean values 
for each of the checkboxes and set the checkbox to use
the field name: <s:checkbox name="myName"> 
When the user submits the form, everything
works as expected.  

Can you do that in your app instead of processing the 
request params yourself?

	Neil

--
Neil Aggarwal, (281)846-8957, http://UnmeteredVPS.net
Host your struts app on a CentOS VPS for only $25/month!
Unmetered bandwidth = no overage charges, 7 day free trial


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