You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by "V. Jenks" <za...@gmail.com> on 2007/10/03 18:51:15 UTC
CheckBox is misbehaving...
NOTE: I'm stuck at Wicket 1.2.4 and cannot upgrade yet.
I've got a very simple form with an input class that looks like this:
****************************
public class PaymentInfoInput implements Serializable
{
private Boolean optedForNewsletter;
.....................................
public Boolean isOptedForNewsletter()
{
return this.optedForNewsletter;
}
public void setOptedForNewsletter(Boolean optedForNewsletter)
{
this.optedForNewsletter = optedForNewsletter;
}
}
****************************
When the page loads I load a boolean value into my CheckBox from an entity,
like so:
****************************
//model for checkbox value
IModel checkedModel = new Model(customer.isOptedForNewsletter());
//newsletter opt-in checkbox
form.add(new CheckBox("optedForNewsletter", checkedModel));
****************************
...I've walked through this portion in the debugger, it loads the correct
value.
Now, when I submit the form, regardless of whether or not the CheckBox is
checked, the value is null:
****************************
//create form
final Form form = new Form("paymentInfoForm", new
CompoundPropertyModel(new PaymentInfoInput()));
...........................................
//submit button
form.add(new Button("completeOrderButton")
{
public void onSubmit()
{
try
{
//get form input
PaymentInfoInput input = (PaymentInfoInput)form.getModelObject();
Boolean opted =
input.isOptedForNewsletter(); //WHY IS THIS NULL?
}
catch (Exception exp)
{
LogProxy.saveEntry(exp);
}
}
});
...in the HTML:
<input type="checkbox" wicket:id="optedForNewsletter" value="true" />
****************************
...what's up with that? I must be missing something painfully simple.
Thanks!
--
View this message in context: http://www.nabble.com/CheckBox-is-misbehaving...-tf4563018.html#a13022997
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: CheckBox is misbehaving...
Posted by "V. Jenks" <za...@gmail.com>.
Ah ha, that makes sense...I understand now. I reorganized the code so I
could pre-load the input class first and it works.
Thanks much!
igor.vaynberg wrote:
>
> you are not tying your checkbox's model to the form's model object so it
> saves into its own model..
>
> as you can see here:
> IModel checkedModel = new Model(customer.isOptedForNewsletter());
> form.add(new CheckBox("optedForNewsletter", checkedModel));
> you are giving it its own model...
>
> so in your onsubmit you have to call checkbox.getmodelobject() to retrieve
> the value, or give it a model that is properly tied to the form's model
> object via a propertymodel or something else
>
> -igor
>
>
> On 10/3/07, V. Jenks <za...@gmail.com> wrote:
>>
>>
>> NOTE: I'm stuck at Wicket 1.2.4 and cannot upgrade yet.
>>
>> I've got a very simple form with an input class that looks like this:
>>
>> ****************************
>> public class PaymentInfoInput implements Serializable
>> {
>> private Boolean optedForNewsletter;
>>
>> .....................................
>>
>> public Boolean isOptedForNewsletter()
>> {
>> return this.optedForNewsletter;
>> }
>>
>> public void setOptedForNewsletter(Boolean optedForNewsletter)
>> {
>> this.optedForNewsletter = optedForNewsletter;
>> }
>> }
>> ****************************
>>
>> When the page loads I load a boolean value into my CheckBox from an
>> entity,
>> like so:
>>
>> ****************************
>> //model for checkbox value
>> IModel checkedModel = new Model(
>> customer.isOptedForNewsletter());
>>
>> //newsletter opt-in checkbox
>> form.add(new CheckBox("optedForNewsletter",
>> checkedModel));
>> ****************************
>>
>> ...I've walked through this portion in the debugger, it loads the correct
>> value.
>>
>> Now, when I submit the form, regardless of whether or not the CheckBox is
>> checked, the value is null:
>>
>> ****************************
>> //create form
>> final Form form = new Form("paymentInfoForm", new
>> CompoundPropertyModel(new PaymentInfoInput()));
>>
>> ...........................................
>>
>> //submit button
>> form.add(new Button("completeOrderButton")
>> {
>> public void onSubmit()
>> {
>> try
>> {
>> //get form input
>> PaymentInfoInput input =
>> (PaymentInfoInput)form.getModelObject();
>> Boolean opted =
>> input.isOptedForNewsletter(); //WHY IS THIS NULL?
>> }
>> catch (Exception exp)
>> {
>> LogProxy.saveEntry(exp);
>> }
>> }
>> });
>>
>> ...in the HTML:
>>
>> <input type="checkbox" wicket:id="optedForNewsletter" value="true" />
>> ****************************
>>
>> ...what's up with that? I must be missing something painfully simple.
>>
>> Thanks!
>> --
>> View this message in context:
>> http://www.nabble.com/CheckBox-is-misbehaving...-tf4563018.html#a13022997
>> Sent from the Wicket - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>
>
--
View this message in context: http://www.nabble.com/CheckBox-is-misbehaving...-tf4563018.html#a13025669
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: CheckBox is misbehaving...
Posted by Igor Vaynberg <ig...@gmail.com>.
you are not tying your checkbox's model to the form's model object so it
saves into its own model..
as you can see here:
IModel checkedModel = new Model(customer.isOptedForNewsletter());
form.add(new CheckBox("optedForNewsletter", checkedModel));
you are giving it its own model...
so in your onsubmit you have to call checkbox.getmodelobject() to retrieve
the value, or give it a model that is properly tied to the form's model
object via a propertymodel or something else
-igor
On 10/3/07, V. Jenks <za...@gmail.com> wrote:
>
>
> NOTE: I'm stuck at Wicket 1.2.4 and cannot upgrade yet.
>
> I've got a very simple form with an input class that looks like this:
>
> ****************************
> public class PaymentInfoInput implements Serializable
> {
> private Boolean optedForNewsletter;
>
> .....................................
>
> public Boolean isOptedForNewsletter()
> {
> return this.optedForNewsletter;
> }
>
> public void setOptedForNewsletter(Boolean optedForNewsletter)
> {
> this.optedForNewsletter = optedForNewsletter;
> }
> }
> ****************************
>
> When the page loads I load a boolean value into my CheckBox from an
> entity,
> like so:
>
> ****************************
> //model for checkbox value
> IModel checkedModel = new Model(
> customer.isOptedForNewsletter());
>
> //newsletter opt-in checkbox
> form.add(new CheckBox("optedForNewsletter",
> checkedModel));
> ****************************
>
> ...I've walked through this portion in the debugger, it loads the correct
> value.
>
> Now, when I submit the form, regardless of whether or not the CheckBox is
> checked, the value is null:
>
> ****************************
> //create form
> final Form form = new Form("paymentInfoForm", new
> CompoundPropertyModel(new PaymentInfoInput()));
>
> ...........................................
>
> //submit button
> form.add(new Button("completeOrderButton")
> {
> public void onSubmit()
> {
> try
> {
> //get form input
> PaymentInfoInput input =
> (PaymentInfoInput)form.getModelObject();
> Boolean opted =
> input.isOptedForNewsletter(); //WHY IS THIS NULL?
> }
> catch (Exception exp)
> {
> LogProxy.saveEntry(exp);
> }
> }
> });
>
> ...in the HTML:
>
> <input type="checkbox" wicket:id="optedForNewsletter" value="true" />
> ****************************
>
> ...what's up with that? I must be missing something painfully simple.
>
> Thanks!
> --
> View this message in context:
> http://www.nabble.com/CheckBox-is-misbehaving...-tf4563018.html#a13022997
> Sent from the Wicket - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>
Re: CheckBox is misbehaving...
Posted by "V. Jenks" <za...@gmail.com>.
I apologize if this is a dumb question but can anyone offer any advice? A
work-around would be fine, if necessary. I'm unable to figure this thing
out. It's the last issue before I can put my app into production today.
Thanks!
V. Jenks wrote:
>
> NOTE: I'm stuck at Wicket 1.2.4 and cannot upgrade yet.
>
> I've got a very simple form with an input class that looks like this:
>
> ****************************
> public class PaymentInfoInput implements Serializable
> {
> private Boolean optedForNewsletter;
>
> .....................................
>
> public Boolean isOptedForNewsletter()
> {
> return this.optedForNewsletter;
> }
>
> public void setOptedForNewsletter(Boolean optedForNewsletter)
> {
> this.optedForNewsletter = optedForNewsletter;
> }
> }
> ****************************
>
> When the page loads I load a boolean value into my CheckBox from an
> entity, like so:
>
> ****************************
> //model for checkbox value
> IModel checkedModel = new Model(customer.isOptedForNewsletter());
>
> //newsletter opt-in checkbox
> form.add(new CheckBox("optedForNewsletter", checkedModel));
> ****************************
>
> ...I've walked through this portion in the debugger, it loads the correct
> value.
>
> Now, when I submit the form, regardless of whether or not the CheckBox is
> checked, the value is null:
>
> ****************************
> //create form
> final Form form = new Form("paymentInfoForm", new
> CompoundPropertyModel(new PaymentInfoInput()));
>
> ...........................................
>
> //submit button
> form.add(new Button("completeOrderButton")
> {
> public void onSubmit()
> {
> try
> {
> //get form input
> PaymentInfoInput input = (PaymentInfoInput)form.getModelObject();
> Boolean opted =
> input.isOptedForNewsletter(); //WHY IS THIS NULL?
> }
> catch (Exception exp)
> {
> LogProxy.saveEntry(exp);
> }
> }
> });
>
> ...in the HTML:
>
> <input type="checkbox" wicket:id="optedForNewsletter" value="true" />
> ****************************
>
> ...what's up with that? I must be missing something painfully simple.
>
> Thanks!
>
--
View this message in context: http://www.nabble.com/CheckBox-is-misbehaving...-tf4563018.html#a13025097
Sent from the Wicket - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org