I'm trying to default a DDC (DropDownChoice) using the model I am passing
in. The page is getting passed in a LoadableDetachableModel which is of
Type Player. The list to back the DDC is a List<Player>.
LoadableDetachableModel playersModel = new LoadableDetachableModel()
{
protected Object load()
{
return playerManager.getPlayersInLeague(getActiveLeague());
}
};
And here is the DDC.
final DropDownChoice downChoice = new DropDownChoice("name", new Model(),
playersModel, new ChoiceRenderer("username", "id"));
add(downChoice);
downChoice.add(new AjaxFormComponentUpdatingBehavior("onChange")
{
@Override
protected void onUpdate(AjaxRequestTarget target) {
setResponsePage(new ViewPicksPage(downChoice.getModel()));
}
});
The above code works but does not obviously does not default the DDC. I
want the default to be the playerModel that is being passed in to the page.
If I pass the playerModel into the DDC (instead of the new Model()) I get an
error saying that I can't set a model on a LDM (loadabledetachablemodel).
What is the correct way to default the DDC? I've read that I shouldn't use
a LDM for backing as it is loadable, but then what model should I use? Keep
in mind that I am trying to keep the memory footprint low and do not want to
serialize objects unless I have to.
Tim
Hi Tim, I think what happens is that the playerModel is an instance of
AbstractReadOnlyModel. So DDC can not set the choice on it. As you need to
avoid the player serialization on playerModel, I suggest you create an
custom model ( and forgot any AbstractReadOnlyModel class or subclass usage
for your component default model ), that you can set and get an Player type.
But internally, it only keep the id value to serialization process. In that
way, you will can find the Player on deserialization process. I saw an
example of this type of model on "Wicket in Action" book.
class CustomPlayerModel extends Model{
private id;
public getObject(){
dao.getPlayer(id);
}
public setObject(player){
this.id = player.getId();
}
}
final DropDownChoice downChoice = new DropDownChoice("name", new
CustomPlayerModel(Player), playersModel, new ChoiceRenderer("username",
"id"));
On Mon, Sep 21, 2009 at 10:24 AM, tdelesio <td...@gmail.com> wrote:
>
>
> tdelesio wrote:
> >
> >
> > final DropDownChoice downChoice = new DropDownChoice("name", new
> > CompoundPropertyModel(playerModel), playersModel, new
> > ChoiceRenderer("username", "id"));
> >
> > This would work fine w/o serialization except that the compound expects a
> > setter with the name of the component from the object that comes from the
> > backing LDM (playerModel) so it would error. I essentially want it to
> not
> > use a setter, instead just store the value itself as the object.
> >
> >
>
> BTW...this is the error that is generated when you try and use new
> CompoundPropertyModel(playerModel) for the backing of the DDC.
>
> java.lang.UnsupportedOperationException: Model class
> ViewPicksPage$1 does not support setObject(Object)
> at
>
> org.apache.wicket.model.AbstractReadOnlyModel.setObject(AbstractReadOnlyModel.java:55)
> at
> org.apache.wicket.Component.setDefaultModelObject(Component.java:3052)
>
> Tim
> --
> View this message in context:
> http://www.nabble.com/Defaulting-a-DropDownChoice-tp25508933p25530325.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
>
>
tdelesio wrote:
>
>
> final DropDownChoice downChoice = new DropDownChoice("name", new
> CompoundPropertyModel(playerModel), playersModel, new
> ChoiceRenderer("username", "id"));
>
> This would work fine w/o serialization except that the compound expects a
> setter with the name of the component from the object that comes from the
> backing LDM (playerModel) so it would error. I essentially want it to not
> use a setter, instead just store the value itself as the object.
>
>
BTW...this is the error that is generated when you try and use new
CompoundPropertyModel(playerModel) for the backing of the DDC.
java.lang.UnsupportedOperationException: Model class
ViewPicksPage$1 does not support setObject(Object)
at
org.apache.wicket.model.AbstractReadOnlyModel.setObject(AbstractReadOnlyModel.java:55)
at org.apache.wicket.Component.setDefaultModelObject(Component.java:3052)
Tim
--
View this message in context: http://www.nabble.com/Defaulting-a-DropDownChoice-tp25508933p25530325.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
Thanks for the response. How do I bind the playerModel to the DDC? If I did
the below extract the object out of the playerModel it would probably work.
Player player = (Player)playerModel.getObject();
final DropDownChoice downChoice = new DropDownChoice("name", new
Model(Player), playersModel, new ChoiceRenderer("username", "id"));
If I did this though, the player object would get serialized and I want to
avoid that. If I use:
final DropDownChoice downChoice = new DropDownChoice("name", new
CompoundPropertyModel(playerModel), playersModel, new
ChoiceRenderer("username", "id"));
This would work fine w/o serialization except that the compound expects a
setter with the name of the component from the object that comes from the
backing LDM (playerModel) so it would error. I essentially want it to not
use a setter, instead just store the value itself as the object.
Tim
Pedro Santos-6 wrote:
>
> The DDC uses the model choises internaly, if you want manage this model,
> use
> it on other places, why don't you keep an refecence to by yourself?
>
> setResponsePage(new ViewPicksPage(playersModel));
>
> on DDC default model will have only the selected item, provided by choices
> options you passed
>
> On Fri, Sep 18, 2009 at 10:45 AM, Tim Delesio <td...@gmail.com> wrote:
>
>> I'm trying to default a DDC (DropDownChoice) using the model I am passing
>> in. The page is getting passed in a LoadableDetachableModel which is of
>> Type Player. The list to back the DDC is a List<Player>.
>>
>> LoadableDetachableModel playersModel = new LoadableDetachableModel()
>> {
>> protected Object load()
>> {
>> return
>> playerManager.getPlayersInLeague(getActiveLeague());
>> }
>> };
>>
>> And here is the DDC.
>>
>> final DropDownChoice downChoice = new DropDownChoice("name", new
>> Model(),
>> playersModel, new ChoiceRenderer("username", "id"));
>> add(downChoice);
>>
>> downChoice.add(new AjaxFormComponentUpdatingBehavior("onChange")
>> {
>>
>> @Override
>> protected void onUpdate(AjaxRequestTarget target) {
>> setResponsePage(new ViewPicksPage(downChoice.getModel()));
>> }
>>
>> });
>>
>> The above code works but does not obviously does not default the DDC. I
>> want the default to be the playerModel that is being passed in to the
>> page.
>> If I pass the playerModel into the DDC (instead of the new Model()) I get
>> an
>> error saying that I can't set a model on a LDM (loadabledetachablemodel).
>> What is the correct way to default the DDC? I've read that I shouldn't
>> use
>> a LDM for backing as it is loadable, but then what model should I use?
>> Keep
>> in mind that I am trying to keep the memory footprint low and do not want
>> to
>> serialize objects unless I have to.
>>
>> Tim
>>
>
>
--
View this message in context: http://www.nabble.com/Defaulting-a-DropDownChoice-tp25508933p25513112.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
The DDC uses the model choises internaly, if you want manage this model, use
it on other places, why don't you keep an refecence to by yourself?
setResponsePage(new ViewPicksPage(playersModel));
on DDC default model will have only the selected item, provided by choices
options you passed
On Fri, Sep 18, 2009 at 10:45 AM, Tim Delesio <td...@gmail.com> wrote:
> I'm trying to default a DDC (DropDownChoice) using the model I am passing
> in. The page is getting passed in a LoadableDetachableModel which is of
> Type Player. The list to back the DDC is a List<Player>.
>
> LoadableDetachableModel playersModel = new LoadableDetachableModel()
> {
> protected Object load()
> {
> return playerManager.getPlayersInLeague(getActiveLeague());
> }
> };
>
> And here is the DDC.
>
> final DropDownChoice downChoice = new DropDownChoice("name", new Model(),
> playersModel, new ChoiceRenderer("username", "id"));
> add(downChoice);
>
> downChoice.add(new AjaxFormComponentUpdatingBehavior("onChange")
> {
>
> @Override
> protected void onUpdate(AjaxRequestTarget target) {
> setResponsePage(new ViewPicksPage(downChoice.getModel()));
> }
>
> });
>
> The above code works but does not obviously does not default the DDC. I
> want the default to be the playerModel that is being passed in to the page.
> If I pass the playerModel into the DDC (instead of the new Model()) I get
> an
> error saying that I can't set a model on a LDM (loadabledetachablemodel).
> What is the correct way to default the DDC? I've read that I shouldn't use
> a LDM for backing as it is loadable, but then what model should I use?
> Keep
> in mind that I am trying to keep the memory footprint low and do not want
> to
> serialize objects unless I have to.
>
> Tim
>