You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Fred Toth <ft...@synernet.com> on 2007/07/07 23:11:34 UTC

How do I make a checkbox initially checked?

Hi again,

I'm working on a form where a particular checkbox should be initially
checked when the form first comes up.

None of the options in s:checkbox seem to support this.

I tried to have my backing object initialized with the particular 
Boolean set
to true, but struts doesn't seem to actually create my object (counter 
to the docs),
until submission time.

If I have:

<s:checkbox name="user.sendEmail"/>

The docs say that if user doesn't exist (which is the case on initial 
display of the form),
OGNL will get a null value, and struts will create a user object. This 
doesn't seem
to be happening.

Is there a way to do this using the UI tags?

Thanks,

Fred


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


Re: How do I make a checkbox initially checked?

Posted by Fred Toth <ft...@synernet.com>.
Hi,

Yes, it works fine if I use prepare() and create my own object. However, 
my understanding
from the docs was that struts would create my object for me, based on 
hitting a null pointer.
But that does not seem to be the case.

Also, if I use the value="true" method, then my box is checked always, 
regardless of user input.

Thanks,

Fred

Nuwan Chandrasoma wrote:
> Hi,
>
> If you want the check box to be checked initially you can use the tag 
> like this:
>
> <s:checkbox name="user.sendEmail" value="true"/>
>
> are you calling the prepare method to initialized you backing object?, 
> according to my understanding the backing object will not be created 
> and initiallized if you havent done in the prepare method, the form 
> well be render on the page and when you click the submit buttion. a 
> backing objected will be created and the values entered on the form 
> will be set the object.
>
> Thanks,
>
> Nuwan.
>
>
>
>
> ----- Original Message ----- From: "Fred Toth" <ft...@synernet.com>
> To: "Struts Users Mailing List" <us...@struts.apache.org>
> Sent: Saturday, July 07, 2007 9:11 PM
> Subject: How do I make a checkbox initially checked?
>
>
>> Hi again,
>>
>> I'm working on a form where a particular checkbox should be initially
>> checked when the form first comes up.
>>
>> None of the options in s:checkbox seem to support this.
>>
>> I tried to have my backing object initialized with the particular 
>> Boolean set
>> to true, but struts doesn't seem to actually create my object 
>> (counter to the docs),
>> until submission time.
>>
>> If I have:
>>
>> <s:checkbox name="user.sendEmail"/>
>>
>> The docs say that if user doesn't exist (which is the case on initial 
>> display of the form),
>> OGNL will get a null value, and struts will create a user object. 
>> This doesn't seem
>> to be happening.
>>
>> Is there a way to do this using the UI tags?
>>
>> Thanks,
>>
>> Fred
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>

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


Re: How do I make a checkbox initially checked?

Posted by Nuwan Chandrasoma <my...@gmail.com>.
Hi,

If you want the check box to be checked initially you can use the tag like 
this:

<s:checkbox name="user.sendEmail" value="true"/>

are you calling the prepare method to initialized you backing object?, 
according to my understanding the backing object will not be created and 
initiallized if you havent done in the prepare method, the form well be 
render on the page and when you click the submit buttion. a backing objected 
will be created and the values entered on the form will be set the object.

Thanks,

Nuwan.




----- Original Message ----- 
From: "Fred Toth" <ft...@synernet.com>
To: "Struts Users Mailing List" <us...@struts.apache.org>
Sent: Saturday, July 07, 2007 9:11 PM
Subject: How do I make a checkbox initially checked?


> Hi again,
>
> I'm working on a form where a particular checkbox should be initially
> checked when the form first comes up.
>
> None of the options in s:checkbox seem to support this.
>
> I tried to have my backing object initialized with the particular Boolean 
> set
> to true, but struts doesn't seem to actually create my object (counter to 
> the docs),
> until submission time.
>
> If I have:
>
> <s:checkbox name="user.sendEmail"/>
>
> The docs say that if user doesn't exist (which is the case on initial 
> display of the form),
> OGNL will get a null value, and struts will create a user object. This 
> doesn't seem
> to be happening.
>
> Is there a way to do this using the UI tags?
>
> Thanks,
>
> Fred
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 


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