You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Andrei Razin <ru...@hotmail.com> on 2010/10/20 19:00:33 UTC

Re: setEnabled based on Model

Sorry for the Type:

I meant:
My problem is: "setEnabled" does not take iModel as argumet. 
I'd like to do something like setEnabled(new PropertyModel(doc, "canDelete")
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/setEnabled-based-on-Model-tp3004230p3004245.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: setEnabled based on Model

Posted by Andrei Razin <ru...@hotmail.com>.
Thanks a lot!!!!
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/setEnabled-based-on-Model-tp3004230p3004356.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: setEnabled based on Model

Posted by Andrei Razin <ru...@hotmail.com>.
Jeremy. 

Thanks a lot.

It is nice to have a hand when you need it.

Appreciate, 
Andrei.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/setEnabled-based-on-Model-tp3004230p3004897.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: setEnabled based on Model

Posted by James Carman <ja...@carmanconsulting.com>.
Make sure you detach the model in case nobody else is doing it.

On Wed, Oct 20, 2010 at 9:01 PM, Jeremy Thomerson
<je...@wickettraining.com> wrote:
> On Wed, Oct 20, 2010 at 7:57 PM, Andrei Razin <ru...@hotmail.com> wrote:
>
>>
>> Sorry, I didn't clarify the reason for Reflection.
>>
>> I created the generic LinkDataColumn, and the link inside does not know
>> about the tipe of class passed into.
>> The page (or form) supplied the Model for the column and the Name like the
>> "isEditEnabled" property.
>> So, inside the LinkColumn i cannot get the property directly and it will be
>> much nicer to use PropertyModel.
>>
>> Regards,
>> Andrei.
>> --
>> View this message in context:
>> http://apache-wicket.1842946.n4.nabble.com/setEnabled-based-on-Model-tp3004230p3004867.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
>>
>>
> So, just override isVisible and setVisible to take the IModel<Boolean>
>
> class LinkDataColumn extends Foo {
>
> private IModel<Boolean> visibility;
>
> isVisible() {
> // do null check
> return visibility.getModelObject();
> }
>
> setVisible(IModel<Boolean> vis) {
> visibility = vis;
> }
> }
>
> Done and done.
>
> --
> Jeremy Thomerson
> http://wickettraining.com
> *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
>

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


Re: setEnabled based on Model

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Wed, Oct 20, 2010 at 7:57 PM, Andrei Razin <ru...@hotmail.com> wrote:

>
> Sorry, I didn't clarify the reason for Reflection.
>
> I created the generic LinkDataColumn, and the link inside does not know
> about the tipe of class passed into.
> The page (or form) supplied the Model for the column and the Name like the
> "isEditEnabled" property.
> So, inside the LinkColumn i cannot get the property directly and it will be
> much nicer to use PropertyModel.
>
> Regards,
> Andrei.
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/setEnabled-based-on-Model-tp3004230p3004867.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
>
>
So, just override isVisible and setVisible to take the IModel<Boolean>

class LinkDataColumn extends Foo {

private IModel<Boolean> visibility;

isVisible() {
// do null check
return visibility.getModelObject();
}

setVisible(IModel<Boolean> vis) {
visibility = vis;
}
}

Done and done.

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*

Re: setEnabled based on Model

Posted by Andrei Razin <ru...@hotmail.com>.
Sorry, I didn't clarify the reason for Reflection.

I created the generic LinkDataColumn, and the link inside does not know
about the tipe of class passed into.
The page (or form) supplied the Model for the column and the Name like the
"isEditEnabled" property.
So, inside the LinkColumn i cannot get the property directly and it will be
much nicer to use PropertyModel.

Regards, 
Andrei.
-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/setEnabled-based-on-Model-tp3004230p3004867.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: setEnabled based on Model

Posted by Andrei Razin <ru...@hotmail.com>.
Thanks a lot for the advice.
I just implemented it - works.
I am still on version 1.4.7, so, couldn't use onConfigure.
anyway, here is the code:

@Override
public boolean isEnabled(){

............
	Object obj = model.getObject();
	return Boolean.parseBoolean(BeanUtils.getProperty(obj,
enabledPropertyName));
.............

}


I had to use reflections (Apache commons BeanUtils).
I am Happy with this, but may be, for the future the setters may take the
PropertyModel as an argument. It will be more consistent and nicer (or I may
be wrong).

So, it may be something like:

element.setEnabled(new PropertyModel(iModel, "enabled"));


-- 
View this message in context: http://apache-wicket.1842946.n4.nabble.com/setEnabled-based-on-Model-tp3004230p3004864.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: setEnabled based on Model

Posted by Igor Vaynberg <ig...@gmail.com>.
or better yet, override onconfigure() and call setvisible/enabled from there

-igor

On Wed, Oct 20, 2010 at 10:04 AM, Jeremy Thomerson
<je...@wickettraining.com> wrote:
> On Wed, Oct 20, 2010 at 12:00 PM, Andrei Razin <ru...@hotmail.com>wrote:
>
>>
>> Sorry for the Type:
>>
>> I meant:
>> My problem is: "setEnabled" does not take iModel as argumet.
>> I'd like to do something like setEnabled(new PropertyModel(doc,
>> "canDelete")
>>
>
> override isVisible instead:
>
> @Override
> public boolean isVisible() {
>  return getModelObject().canDelete();
> }
>
> remember that if you reference doc directly in your isVisible method, it
> will be serialized, so it's better to give the component a
> loadabledetachablemodel and reference it through the model object as shown
> (depending on what doc is - I'm assuming you won't want it serialized, but
> you may not care depending on where this is).
>
> --
> Jeremy Thomerson
> http://wickettraining.com
> *Need a CMS for Wicket?  Use Brix! http://brixcms.org*
>

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


Re: setEnabled based on Model

Posted by Jeremy Thomerson <je...@wickettraining.com>.
On Wed, Oct 20, 2010 at 12:00 PM, Andrei Razin <ru...@hotmail.com>wrote:

>
> Sorry for the Type:
>
> I meant:
> My problem is: "setEnabled" does not take iModel as argumet.
> I'd like to do something like setEnabled(new PropertyModel(doc,
> "canDelete")
>

override isVisible instead:

@Override
public boolean isVisible() {
  return getModelObject().canDelete();
}

remember that if you reference doc directly in your isVisible method, it
will be serialized, so it's better to give the component a
loadabledetachablemodel and reference it through the model object as shown
(depending on what doc is - I'm assuming you won't want it serialized, but
you may not care depending on where this is).

-- 
Jeremy Thomerson
http://wickettraining.com
*Need a CMS for Wicket?  Use Brix! http://brixcms.org*