You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by xe0nre <mv...@gmail.com> on 2012/06/17 15:28:28 UTC

Wicket checkbox problem

Hi ,

I have problem getting the value from a check box.
I have something like this:

check = new CheckBox("check", Model.of(Boolean.TRUE));
add(check);
        
AjaxLink link = new AjaxLink("link")
{
    @Override
    public void onClick(AjaxRequestTarget target)
    {
         Boolean x = check.getModelObject();
         System.out.println(x);
    }
};
add(link);

The problem is that the check.getModelObject() returns true even if the
checkbox is unchecked.
I have tried adding check.modelChanged() method. Nothing changed.

Any suggestions ?Thx


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-checkbox-problem-tp4650022.html
Sent from the Users forum 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: Wicket checkbox problem

Posted by xe0nre <mv...@gmail.com>.
Thanks for your reply.I used AjaxCheckBox witch does the job very well.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-checkbox-problem-tp4650022p4650028.html
Sent from the Users forum 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: Wicket checkbox problem

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

The problem is that AjaxLink doesn't send the new value to the server.
You need either AjaxCheckBox or CheckBox with
AjaxFormComponentUpdatingBehavior, or AjaxButton that will submit the
whole form.

On Sun, Jun 17, 2012 at 4:28 PM, xe0nre <mv...@gmail.com> wrote:
> Hi ,
>
> I have problem getting the value from a check box.
> I have something like this:
>
> check = new CheckBox("check", Model.of(Boolean.TRUE));
> add(check);
>
> AjaxLink link = new AjaxLink("link")
> {
>    @Override
>    public void onClick(AjaxRequestTarget target)
>    {
>         Boolean x = check.getModelObject();
>         System.out.println(x);
>    }
> };
> add(link);
>
> The problem is that the check.getModelObject() returns true even if the
> checkbox is unchecked.
> I have tried adding check.modelChanged() method. Nothing changed.
>
> Any suggestions ?Thx
>
>
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Wicket-checkbox-problem-tp4650022.html
> Sent from the Users forum 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
>



-- 
Martin Grigorov
jWeekend
Training, Consulting, Development
http://jWeekend.com

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


Re: Wicket checkbox problem

Posted by Josh Kamau <jo...@gmail.com>.
Try a dynamic model

Boolean value  ;

check = new CheckBox("check", new Model<Boolean>(){

        public void setObject(Boolean object){ value=object}
        public Boolean getObject(){return value}
});

//YOu may want to add an ajax onchange behaviour to the checkbox if you
want to value to be updated immediately you flip the checkbox.

AjaxLink link = new AjaxLink("link")
{
   @Override
   public void onClick(AjaxRequestTarget target)
   {
       System.out.println(value);
   }
};
add(link);

Try something along those lines.

Josh.


> AjaxLink link = new AjaxLink("link")
> {
>    @Override
>    public void onClick(AjaxRequestTarget target)
>    {
>         Boolean x = check.getModelObject();
>         System.out.println(x);
>    }
> };
> add(link);
>
>

> The problem is that the check.getModelObject() returns true even if the
> checkbox is unchecked.
> I have tried adding check.modelChanged() method. Nothing changed.
>
> Any suggestions ?Thx
>
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Wicket-checkbox-problem-tp4650022.html
> Sent from the Users forum 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
>
>