You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Johan Haleby <jo...@gmail.com> on 2010/09/06 13:38:57 UTC

Replace components with AjaxCheckbox

I'm trying to replace a component when clicking on an AjaxCheckbox. The code
looks something like this:

AjaxCheckBox checkbox = new AjaxCheckBox("checkBox", new
PropertyModel<Boolean>(this, "isChecked")) {
	private static final long serialVersionUID = 4298312627418158465L;

	@Override
	protected void onUpdate(AjaxRequestTarget target) {
		final Component component;
		if (isChecked) {
			System.out.println("is checked");
			component = new Label("component", "is checked");
		} else {
			System.out.println("is NOT checked");
			component = originalComponent;
		}
		form.replace(component);
		target.addComponent(form);
	}

	@Override
	protected boolean wantOnSelectionChangedNotifications() {
		return true;
	}
};

It works fine the first time I click on the check box, i.e. "is checked" is
printed to the console and the label "is checked" is shown on the web pagfe.
But when I click on the checkbox again (to uncheck it) "originalComponent"
is never shown but "is NOT checked" is printed in the console. What am I
doing wrong? 

/Johan
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Replace-components-with-AjaxCheckbox-tp2528243p2528243.html
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: Replace components with AjaxCheckbox

Posted by Igor Vaynberg <ig...@gmail.com>.
component = new Label("component", "is checked");
orginalComponent=component

-igor

On Mon, Sep 6, 2010 at 4:38 AM, Johan Haleby <jo...@gmail.com> wrote:
>
> I'm trying to replace a component when clicking on an AjaxCheckbox. The code
> looks something like this:
>
> AjaxCheckBox checkbox = new AjaxCheckBox("checkBox", new
> PropertyModel<Boolean>(this, "isChecked")) {
>        private static final long serialVersionUID = 4298312627418158465L;
>
>        @Override
>        protected void onUpdate(AjaxRequestTarget target) {
>                final Component component;
>                if (isChecked) {
>                        System.out.println("is checked");
>                        component = new Label("component", "is checked");
>                } else {
>                        System.out.println("is NOT checked");
>                        component = originalComponent;
>                }
>                form.replace(component);
>                target.addComponent(form);
>        }
>
>        @Override
>        protected boolean wantOnSelectionChangedNotifications() {
>                return true;
>        }
> };
>
> It works fine the first time I click on the check box, i.e. "is checked" is
> printed to the console and the label "is checked" is shown on the web pagfe.
> But when I click on the checkbox again (to uncheck it) "originalComponent"
> is never shown but "is NOT checked" is printed in the console. What am I
> doing wrong?
>
> /Johan
> --
> View this message in context: http://apache-wicket.1842946.n4.nabble.com/Replace-components-with-AjaxCheckbox-tp2528243p2528243.html
> 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
>
>

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


Re: Replace components with AjaxCheckbox

Posted by Alexander Morozov <al...@gmail.com>.
Check this:
                if (isChecked) { 
                        System.out.println("is checked"); 
                        component = new Label("component", "is checked"); 
                        /* output markup ID */
                        component.setOutputMarkupId(true);
                } else { 
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Replace-components-with-AjaxCheckbox-tp2528243p2528388.html
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