You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Anna Simbirtsev <as...@gmail.com> on 2010/08/23 21:18:27 UTC

Using AjaxCheckBox

Hi,

I am trying to use AjaxCheckBox to update another checkbox model object when
this checkbox is clicked.

CheckBox b = new CheckBox("basicCreate",
                new Model<Boolean>());

AjaxCheckBox a = new AjaxCheckBox("create",
                new Model<Boolean>()) {

            private static final long serialVersionUID =
288634742710645609L;

            protected void onUpdate(AjaxRequestTarget target)
            {
                if (getModelObject()) {
                    b.setModelObject(true);
                    b.setOutputMarkupId(true);

                    target.addComponent(b);
                }
            }
        };

So when checkbox a is checked, I want checkbox b to be checked as well.
But nothing happens. Am I doing something wrong?

Thanks,
Anna

Re: Using AjaxCheckBox

Posted by Sven Meier <sv...@meiers.net>.
Yes, you did call it before #addComponent():

     b.setOutputMarkupId(true);
     target.addComponent(b);

But Wicket doesn't keep track of *when* you called the method, i.e. 
before or after the Ajax request.
IIRC there should be an error message in the Ajax debug window.

Regards

Sven


On 08/23/2010 09:30 PM, Anna Simbirtsev wrote:
> Thanks, this fixed a problem. But I thought, it would give me an error
> message, if I am trying to update a component that does not have
> setOutputMarkupId(true) ?
>
> On Mon, Aug 23, 2010 at 3:26 PM, Sven Meier<sv...@meiers.net>  wrote:
>
>    
>> Hi,
>>
>> calling b.setOutputMarkupId(true) during Ajax request is too late. The HTML
>> tag will not have a markup id, so nothing will be updated.
>>
>> Call this method immediately after constructing the checkbox.
>>
>> Regards
>>
>> Sven
>>
>>
>>
>> On 08/23/2010 09:18 PM, Anna Simbirtsev wrote:
>>
>>      
>>> Hi,
>>>
>>> I am trying to use AjaxCheckBox to update another checkbox model object
>>> when
>>> this checkbox is clicked.
>>>
>>> CheckBox b = new CheckBox("basicCreate",
>>>                  new Model<Boolean>());
>>>
>>> AjaxCheckBox a = new AjaxCheckBox("create",
>>>                  new Model<Boolean>()) {
>>>
>>>              private static final long serialVersionUID =
>>> 288634742710645609L;
>>>
>>>              protected void onUpdate(AjaxRequestTarget target)
>>>              {
>>>                  if (getModelObject()) {
>>>                      b.setModelObject(true);
>>>                      b.setOutputMarkupId(true);
>>>
>>>                      target.addComponent(b);
>>>                  }
>>>              }
>>>          };
>>>
>>> So when checkbox a is checked, I want checkbox b to be checked as well.
>>> But nothing happens. Am I doing something wrong?
>>>
>>> Thanks,
>>> Anna
>>>
>>>
>>>
>>>        
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>>      
>
>    


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Using AjaxCheckBox

Posted by Anna Simbirtsev <as...@gmail.com>.
Thanks, this fixed a problem. But I thought, it would give me an error
message, if I am trying to update a component that does not have
setOutputMarkupId(true) ?

On Mon, Aug 23, 2010 at 3:26 PM, Sven Meier <sv...@meiers.net> wrote:

> Hi,
>
> calling b.setOutputMarkupId(true) during Ajax request is too late. The HTML
> tag will not have a markup id, so nothing will be updated.
>
> Call this method immediately after constructing the checkbox.
>
> Regards
>
> Sven
>
>
>
> On 08/23/2010 09:18 PM, Anna Simbirtsev wrote:
>
>> Hi,
>>
>> I am trying to use AjaxCheckBox to update another checkbox model object
>> when
>> this checkbox is clicked.
>>
>> CheckBox b = new CheckBox("basicCreate",
>>                 new Model<Boolean>());
>>
>> AjaxCheckBox a = new AjaxCheckBox("create",
>>                 new Model<Boolean>()) {
>>
>>             private static final long serialVersionUID =
>> 288634742710645609L;
>>
>>             protected void onUpdate(AjaxRequestTarget target)
>>             {
>>                 if (getModelObject()) {
>>                     b.setModelObject(true);
>>                     b.setOutputMarkupId(true);
>>
>>                     target.addComponent(b);
>>                 }
>>             }
>>         };
>>
>> So when checkbox a is checked, I want checkbox b to be checked as well.
>> But nothing happens. Am I doing something wrong?
>>
>> Thanks,
>> Anna
>>
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>


-- 
Anna Simbirtsev
(416) 729-7331

Re: Using AjaxCheckBox

Posted by Sven Meier <sv...@meiers.net>.
Hi,

calling b.setOutputMarkupId(true) during Ajax request is too late. The 
HTML tag will not have a markup id, so nothing will be updated.

Call this method immediately after constructing the checkbox.

Regards

Sven


On 08/23/2010 09:18 PM, Anna Simbirtsev wrote:
> Hi,
>
> I am trying to use AjaxCheckBox to update another checkbox model object when
> this checkbox is clicked.
>
> CheckBox b = new CheckBox("basicCreate",
>                  new Model<Boolean>());
>
> AjaxCheckBox a = new AjaxCheckBox("create",
>                  new Model<Boolean>()) {
>
>              private static final long serialVersionUID =
> 288634742710645609L;
>
>              protected void onUpdate(AjaxRequestTarget target)
>              {
>                  if (getModelObject()) {
>                      b.setModelObject(true);
>                      b.setOutputMarkupId(true);
>
>                      target.addComponent(b);
>                  }
>              }
>          };
>
> So when checkbox a is checked, I want checkbox b to be checked as well.
> But nothing happens. Am I doing something wrong?
>
> Thanks,
> Anna
>
>    


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org