You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Kai Mütz <km...@googlemail.com> on 2008/06/04 11:40:48 UTC

Problem: Check within a ListView

Hi,

I have a ListView nested in a CheckGroup which works actually fine. In some
cases I have to disable (or make invisible) a certain Check within the
Checkgroup. e.g.

CheckGroup roleGroup = new CheckGroup("roles");
add(roleGroup);
roleGroup.add(new CheckGroupSelector("selector"));
ListView roleList = new ListView("role-list", new DetachableRolesModel()) {
	@Override
	protected void populateItem(final ListItem item) {
		Check check = new Check("check", item.getModel());
		item.add(check);
		item.add(new Label("role",
			new PropertyModel(item.getModel(), "value")));
		if (condition) {
			check.setEnabled(false);
		}
	}
};
roleList.setReuseItems(true);
roleGroup.add(roleList);

The problem is that the disabled item is removed from my model while
submitting the form although the disabled checkbox is checked. A disabled
and checked checkbox should not yield to the same result as a enabled and
unchecked checkbox. If I modify it to check.setEnabled(true); everything
works fine. Same with setVisibiliy().

What am I doing wrong?

Kai



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


Re: Problem: Check within a ListView

Posted by Timo Rantalaiho <Ti...@ri.fi>.
On Sat, 21 Jun 2008, Kai Mütz wrote:
> I have no idea how to implement such a model. Do you have any hint? I am not
> sure where/when exactly the IModel.getObject() method is called and where
> the missing values can be inserted.

Something like this, I'm not sure if I got your requirements 
right but maybe this will get you started:

    protected void populateItem(final ListItem item) {                      
        Check check = new Check("check", new Model() {
	    @Override
	    public void setObject(Object object) {
	        if (!isEnabled()) {
		    return;
		}
	        Boolean enableRole = (Boolean) object;
		if (enableRole) {
		    user().addRole(getRoleOf(item));
		}
		user().removeRole(getRoleOf(item));
	    }

	    @Override 
	    public Object getObject() {
	        return user().hasRole(getRoleOf(item));
	    }
	});              

getObject() of the Check is called at least when the Check 
is rendered, to be able to tick it or not as needed. If you 
are really interested, you can always put Thread.dumpStack() 
in getObject() to see when it is called and by whom.

Best wishes,
Timo

-- 
Timo Rantalaiho           
Reaktor Innovations Oy    <URL: http://www.ri.fi/ >

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


Re: Problem: Check within a ListView

Posted by Kai Mütz <km...@googlemail.com>.
I have no idea how to implement such a model. Do you have any hint? I am not
sure where/when exactly the IModel.getObject() method is called and where
the missing values can be inserted.

Regards, Kai

2008/6/5 Igor Vaynberg <ig...@gmail.com>:

> right, so like that its not going to work. you need a model in between
> that can buffer values and insert missing checked by disabled values.
>
> -igor
>
> On Thu, Jun 5, 2008 at 4:36 AM, Kai Mütz <km...@googlemail.com> wrote:
> > Igor Vaynberg <ma...@gmail.com> wrote:
> >> it is possible, just depends on how you set up your models. it is not
> >> possible by directly reading the collection of checkgroup, but you
> >> can come up with a different way.
> >>
> >
> > The checkgroup is part of a form based on a CompoundPropertyModel
> wrapping a
> > User object which has a "roles" property (List). Nothing special.
> >
> > Kai
> >
> >
> > ---------------------------------------------------------------------
> > 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: Problem: Check within a ListView

Posted by Igor Vaynberg <ig...@gmail.com>.
right, so like that its not going to work. you need a model in between
that can buffer values and insert missing checked by disabled values.

-igor

On Thu, Jun 5, 2008 at 4:36 AM, Kai Mütz <km...@googlemail.com> wrote:
> Igor Vaynberg <ma...@gmail.com> wrote:
>> it is possible, just depends on how you set up your models. it is not
>> possible by directly reading the collection of checkgroup, but you
>> can come up with a different way.
>>
>
> The checkgroup is part of a form based on a CompoundPropertyModel wrapping a
> User object which has a "roles" property (List). Nothing special.
>
> Kai
>
>
> ---------------------------------------------------------------------
> 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: Problem: Check within a ListView

Posted by Kai Mütz <km...@googlemail.com>.
Igor Vaynberg <ma...@gmail.com> wrote:
> it is possible, just depends on how you set up your models. it is not
> possible by directly reading the collection of checkgroup, but you
> can come up with a different way.
>

The checkgroup is part of a form based on a CompoundPropertyModel wrapping a
User object which has a "roles" property (List). Nothing special.

Kai


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


Re: Problem: Check within a ListView

Posted by Igor Vaynberg <ig...@gmail.com>.
it is possible, just depends on how you set up your models. it is not
possible by directly reading the collection of checkgroup, but you can
come up with a different way.

-igor

On Wed, Jun 4, 2008 at 8:29 AM, Kai Mütz <km...@googlemail.com> wrote:
> Igor Vaynberg <ma...@gmail.com> wrote:
>> you are not doing anything wrong, that is how things are meant to
>> work.
>>
>
> So, isn't it possible to add a disabled checkbox to a listview without
> removing the item from the corresponding collection?
>
> Kai
>
>
> ---------------------------------------------------------------------
> 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: Problem: Check within a ListView

Posted by Kai Mütz <km...@googlemail.com>.
Igor Vaynberg <ma...@gmail.com> wrote:
> you are not doing anything wrong, that is how things are meant to
> work.
>

So, isn't it possible to add a disabled checkbox to a listview without
removing the item from the corresponding collection?

Kai


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


Re: Problem: Check within a ListView

Posted by Igor Vaynberg <ig...@gmail.com>.
you are not doing anything wrong, that is how things are meant to work.

-igor

On Wed, Jun 4, 2008 at 2:40 AM, Kai Mütz <km...@googlemail.com> wrote:
> Hi,
>
> I have a ListView nested in a CheckGroup which works actually fine. In some
> cases I have to disable (or make invisible) a certain Check within the
> Checkgroup. e.g.
>
> CheckGroup roleGroup = new CheckGroup("roles");
> add(roleGroup);
> roleGroup.add(new CheckGroupSelector("selector"));
> ListView roleList = new ListView("role-list", new DetachableRolesModel()) {
>        @Override
>        protected void populateItem(final ListItem item) {
>                Check check = new Check("check", item.getModel());
>                item.add(check);
>                item.add(new Label("role",
>                        new PropertyModel(item.getModel(), "value")));
>                if (condition) {
>                        check.setEnabled(false);
>                }
>        }
> };
> roleList.setReuseItems(true);
> roleGroup.add(roleList);
>
> The problem is that the disabled item is removed from my model while
> submitting the form although the disabled checkbox is checked. A disabled
> and checked checkbox should not yield to the same result as a enabled and
> unchecked checkbox. If I modify it to check.setEnabled(true); everything
> works fine. Same with setVisibiliy().
>
> What am I doing wrong?
>
> Kai
>
>
>
> ---------------------------------------------------------------------
> 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