You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by jensiator <je...@megasol.se> on 2008/10/17 10:18:54 UTC

Wizard with CompoundPropertyModel

Hi everyone
Time for a new question. This time its about the wizard component. I have
already done a couple of wizards and they work well. I have looked at the
example in wicket and of course I have changed it a little bit. I dont want
the steps do be static private classes so in my solution I send in the Model
that contains the BackingBean in the constructor of the wizardSteps. And it
works. Put in one case I Noticed that all the WizardSteps uses the same
backingbean, so I started to think about using a compoundpropertymodel that
I set to the Wizard in its constuctor. Something like this:
public MywizardConstuctor(String id){
   super(id);
   CompoundPropertyModel<BackingBean> formModel = new
CompoundPropertyModel<BackingBean>(new BackingBean());
    setDefaultModel(formModel);
    WizardModel wizardmodel = new WizardModel();
    wizardmodel.add(new WizardStep1());
    wizardmodel.add(new WizardStep2());
    init(wizardmodel);
}
Okey, in the WizardSteps constuctors I want to bind some TextFields to the
right property. Like this:
public WizardStep1(){
   TextField firstnameTF = new TextField<String>("firstName");
}
and it works well. BUT, this binding forces me to use the same markupid as
the backingbean property. Could be dangerous when different developers work
on the code. Someone might fail to notice this. I personly like when use the
propertmodel parameter in the TextField because it realy shows what your
doing. 
TextField firstnameTF = new TextField<String>("firstName",new
PropertyModel<String>(getDefaultModel(), "nestedobj.firstname"));
But I cant make it work! The former TextField code works, but the one with
getDeafultModel() doesnt. The defaultModel is null. I tryid to
findParent(Wizard.class).getDefaultModel() but it failes, probably because
the Step has not been added to the WizardModel yet.
Can anyone explain to me why 'new TextField<String>("firstName")' works?
Jens Alenius


-- 
View this message in context: http://www.nabble.com/Wizard-with-CompoundPropertyModel-tp20029043p20029043.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: Wizard with CompoundPropertyModel

Posted by jensiator <je...@megasol.se>.
Hi Mattias
I have a solution where I sending the a ordenary Model into the WizardStep
constuctors and it work well. 
I thought that the CompoundPropertyModel should nest itself down the
children so you didn't have to send it "down the chain". 
I think that in your case, you could change the CompoundPropertyModel to a
Model and it work to.
Jens Alenius
-- 
View this message in context: http://www.nabble.com/Wizard-with-CompoundPropertyModel-tp20029043p20032204.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: Wizard with CompoundPropertyModel

Posted by Matthias Keller <ma...@ergon.ch>.
Hi

jensiator wrote:
> Put in one case I Noticed that all the WizardSteps uses the same
> backingbean, so I started to think about using a compoundpropertymodel that
> I set to the Wizard in its constuctor. Something like this:
> public MywizardConstuctor(String id){
>    super(id);
>    CompoundPropertyModel<BackingBean> formModel = new
> CompoundPropertyModel<BackingBean>(new BackingBean());
>     setDefaultModel(formModel);
>     WizardModel wizardmodel = new WizardModel();
>     wizardmodel.add(new WizardStep1());
>     wizardmodel.add(new WizardStep2());
>     init(wizardmodel);
> }
> TextField firstnameTF = new TextField<String>("firstName",new
> PropertyModel<String>(getDefaultModel(), "nestedobj.firstname"));
> But I cant make it work! The former TextField code works, but the one with
> getDeafultModel() doesnt. The defaultModel is null. I tryid to
> findParent(Wizard.class).getDefaultModel() but it failes, probably because
> the Step has not been added to the WizardModel yet.
> Can anyone explain to me why 'new TextField<String>("firstName")' works?
> Jens Aleniu
Looks like you're using 1.4, but I can explain you how I'm doing it in 1.3:

In the wizard:
IModel model = new CompoundPropertyModel(this);
setModel(model);  // i dont have a  setDefaultModel() - Maybe that's the 
difference?
WizardModel wizardModel = new WizardModel();
wizardModel.add(new MyStep(model));

Like that I already have the model in my step (MyStep)

There I'm doing:
setModel(model);  // again, I dont have a setDefaultModel()
add(new TextField("my.id", new PropertyModel(getModel(), "propertyName"));

In your example, you're not passing the model to the steps - that's why 
it cannot be there.

The above example works for me in Wicket 1.3.x, so I think it shouldn't 
be that different in your case.

Matt

-- 
matthias.keller@ergon.ch  +41 44 268 83 98
Ergon Informatik AG, Kleinstrasse 15, CH-8008 Zürich
http://www.ergon.ch
______________________________________________________________
e r g o n    smart people - smart software



Re: Wizard with CompoundPropertyModel

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
Just saw what you were actually talking about...

And yes it's because it's not bound yet.

You could make the compound propertymodel available to every inner class 
step? And call bind instead?

Nino Saturnino Martinez Vazquez Wael wrote:
>
>
>
> Short mail:
>
>
>        public EventDetailsStep() {
>
>            setTitleModel(new ResourceModel("eventdetails.title"));
>            setSummaryModel(new 
> StringResourceModel("eventdetails.summary",
>                    this, new Model<Event>(event)));
>
>            add(new RequiredTextField<String>("name").setLabel(new 
> Model<String>("Eventname")));
>            add(new TextArea<String>("description").setRequired(true));
>            add(new DateField("date").setRequired(true));
>            add(new 
> TextField<String>("location.name").setRequired(true).setLabel(new 
> Model<String>("address")));
> --------------------------------------------^^^^^^^^^^^^^^^
> Nested property.
>
>    public NewEventWizard(String id) {
>        super(id);
>        // create a blank event
>        event = new Event();
>
>        setDefaultModel(new CompoundPropertyModel<Event>(event));
>        WizardModel model = new WizardModel();
>
> This is working for me...
>
>
>
> jensiator wrote:
>> Hi everyone
>> Time for a new question. This time its about the wizard component. I 
>> have
>> already done a couple of wizards and they work well. I have looked at 
>> the
>> example in wicket and of course I have changed it a little bit. I 
>> dont want
>> the steps do be static private classes so in my solution I send in 
>> the Model
>> that contains the BackingBean in the constructor of the wizardSteps. 
>> And it
>> works. Put in one case I Noticed that all the WizardSteps uses the same
>> backingbean, so I started to think about using a 
>> compoundpropertymodel that
>> I set to the Wizard in its constuctor. Something like this:
>> public MywizardConstuctor(String id){
>>    super(id);
>>    CompoundPropertyModel<BackingBean> formModel = new
>> CompoundPropertyModel<BackingBean>(new BackingBean());
>>     setDefaultModel(formModel);
>>     WizardModel wizardmodel = new WizardModel();
>>     wizardmodel.add(new WizardStep1());
>>     wizardmodel.add(new WizardStep2());
>>     init(wizardmodel);
>> }
>> Okey, in the WizardSteps constuctors I want to bind some TextFields 
>> to the
>> right property. Like this:
>> public WizardStep1(){
>>    TextField firstnameTF = new TextField<String>("firstName");
>> }
>> and it works well. BUT, this binding forces me to use the same 
>> markupid as
>> the backingbean property. Could be dangerous when different 
>> developers work
>> on the code. Someone might fail to notice this. I personly like when 
>> use the
>> propertmodel parameter in the TextField because it realy shows what your
>> doing. TextField firstnameTF = new TextField<String>("firstName",new
>> PropertyModel<String>(getDefaultModel(), "nestedobj.firstname"));
>> But I cant make it work! The former TextField code works, but the one 
>> with
>> getDeafultModel() doesnt. The defaultModel is null. I tryid to
>> findParent(Wizard.class).getDefaultModel() but it failes, probably 
>> because
>> the Step has not been added to the WizardModel yet.
>> Can anyone explain to me why 'new TextField<String>("firstName")' works?
>> Jens Alenius
>>
>>
>>   
>

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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


Re: Wizard with CompoundPropertyModel

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.


Short mail:


        public EventDetailsStep() {

            setTitleModel(new ResourceModel("eventdetails.title"));
            setSummaryModel(new StringResourceModel("eventdetails.summary",
                    this, new Model<Event>(event)));

            add(new RequiredTextField<String>("name").setLabel(new 
Model<String>("Eventname")));
            add(new TextArea<String>("description").setRequired(true));
            add(new DateField("date").setRequired(true));
            add(new 
TextField<String>("location.name").setRequired(true).setLabel(new 
Model<String>("address")));
--------------------------------------------^^^^^^^^^^^^^^^
Nested property.

    public NewEventWizard(String id) {
        super(id);
        // create a blank event
        event = new Event();

        setDefaultModel(new CompoundPropertyModel<Event>(event));
        WizardModel model = new WizardModel();

This is working for me...



jensiator wrote:
> Hi everyone
> Time for a new question. This time its about the wizard component. I have
> already done a couple of wizards and they work well. I have looked at the
> example in wicket and of course I have changed it a little bit. I dont want
> the steps do be static private classes so in my solution I send in the Model
> that contains the BackingBean in the constructor of the wizardSteps. And it
> works. Put in one case I Noticed that all the WizardSteps uses the same
> backingbean, so I started to think about using a compoundpropertymodel that
> I set to the Wizard in its constuctor. Something like this:
> public MywizardConstuctor(String id){
>    super(id);
>    CompoundPropertyModel<BackingBean> formModel = new
> CompoundPropertyModel<BackingBean>(new BackingBean());
>     setDefaultModel(formModel);
>     WizardModel wizardmodel = new WizardModel();
>     wizardmodel.add(new WizardStep1());
>     wizardmodel.add(new WizardStep2());
>     init(wizardmodel);
> }
> Okey, in the WizardSteps constuctors I want to bind some TextFields to the
> right property. Like this:
> public WizardStep1(){
>    TextField firstnameTF = new TextField<String>("firstName");
> }
> and it works well. BUT, this binding forces me to use the same markupid as
> the backingbean property. Could be dangerous when different developers work
> on the code. Someone might fail to notice this. I personly like when use the
> propertmodel parameter in the TextField because it realy shows what your
> doing. 
> TextField firstnameTF = new TextField<String>("firstName",new
> PropertyModel<String>(getDefaultModel(), "nestedobj.firstname"));
> But I cant make it work! The former TextField code works, but the one with
> getDeafultModel() doesnt. The defaultModel is null. I tryid to
> findParent(Wizard.class).getDefaultModel() but it failes, probably because
> the Step has not been added to the WizardModel yet.
> Can anyone explain to me why 'new TextField<String>("firstName")' works?
> Jens Alenius
>
>
>   

-- 
-Wicket for love

Nino Martinez Wael
Java Specialist @ Jayway DK
http://www.jayway.dk
+45 2936 7684


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