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-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: setEnabled based on Model
On Wed, Oct 20, 2010 at 12:00 PM, Andrei Razin rukusv...@hotmail.comwrote: 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*
Re: setEnabled based on Model
or better yet, override onconfigure() and call setvisible/enabled from there -igor On Wed, Oct 20, 2010 at 10:04 AM, Jeremy Thomerson jer...@wickettraining.com wrote: On Wed, Oct 20, 2010 at 12:00 PM, Andrei Razin rukusv...@hotmail.comwrote: 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-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: setEnabled based on Model
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-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: setEnabled based on Model
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-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: setEnabled based on Model
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-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: setEnabled based on Model
On Wed, Oct 20, 2010 at 7:57 PM, Andrei Razin rukusv...@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-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org So, just override isVisible and setVisible to take the IModelBoolean class LinkDataColumn extends Foo { private IModelBoolean visibility; isVisible() { // do null check return visibility.getModelObject(); } setVisible(IModelBoolean 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
Make sure you detach the model in case nobody else is doing it. On Wed, Oct 20, 2010 at 9:01 PM, Jeremy Thomerson jer...@wickettraining.com wrote: On Wed, Oct 20, 2010 at 7:57 PM, Andrei Razin rukusv...@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-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org So, just override isVisible and setVisible to take the IModelBoolean class LinkDataColumn extends Foo { private IModelBoolean visibility; isVisible() { // do null check return visibility.getModelObject(); } setVisible(IModelBoolean 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-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: setEnabled based on Model
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-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org