Example for FormComponentPanel/best-practice for reusable form-components

2009-05-05 Thread Marc Hauptmann

Hello,

I want to use FormComponentPanels in forms to deal with more complex 
model-objects. I think it should be possible to chain the Model of every 
FormComponentPanel to the Model of the Form. So every FormComponent has 
automatically the right data in its Model when it changes. But somehow I 
am experiencing problems doing that.


Is there any example using the FormComponentPanel-class? Do you have any 
(other) best-practices creating reusable FormComponents?


Any help would be appreciated! :-)

Best regards,
Marc

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



Re: Example for FormComponentPanel/best-practice for reusable form-components

2009-05-05 Thread Igor Vaynberg
show us your code.

-igor

On Tue, May 5, 2009 at 10:04 AM, Marc Hauptmann hauptm...@ecmlabs.de wrote:
 Hello,

 I want to use FormComponentPanels in forms to deal with more complex
 model-objects. I think it should be possible to chain the Model of every
 FormComponentPanel to the Model of the Form. So every FormComponent has
 automatically the right data in its Model when it changes. But somehow I am
 experiencing problems doing that.

 Is there any example using the FormComponentPanel-class? Do you have any
 (other) best-practices creating reusable FormComponents?

 Any help would be appreciated! :-)

 Best regards,
 Marc

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



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



Re: Example for FormComponentPanel/best-practice for reusable form-components

2009-05-05 Thread FlyingMustang


igor.vaynberg wrote:
 
 show us your code.
 

Ok, I have a class 'Person' with an'Address-Property. My Form-object has a
simple Model wrapping a Person-object. The constructor creating the Panel
with the form contains these lines:

form = new FormPerson(form, new ModelPerson());
personFormComponent = new
PersonFormComponentStudent(personFormComponent, form.getModel());
addressFormComponent = new
AddressFormComponentAddress(addressFormComponent, new
PropertyModelAddress(this.form.getModel(), address));

form.add(personFormComponent);
form.add(addressFormComponent);

After creation of this Panel I call form.setModelObject(...). So the model
ist not empty. The PersonFormComponent works well as it only sets some
String-Properties of the Person-Object. But I have trouble with the
AddressFormComponent which looks like this:

public class AddressFormComponentT extends Address extends
FormComponentPanelT {
protected TextFieldString cityField, postcodeField, streetField;
protected IModelT model;

public AddressFormComponent(String id, IModelT model) {
super(id, model);

// Model
this.model = model;

// Straße
streetField = new TextFieldString(streetField, new
PropertyModelString(model, street));
streetField.setRequired(true);
streetField.add(StringValidator.lengthBetween(0, 100));

// PLZ
postcodeField = new TextFieldString(postcodeField, new
ModelString());
postcodeField.setRequired(true);

// Stadt
cityField = new TextFieldString(cityField, new 
ModelString());
cityField.setRequired(true);
cityField.add(StringValidator.lengthBetween(0, 50));

this.add(streetField);
this.add(postcodeField);
this.add(cityField);
}
}

After submitting the whole form (with an AjaxButton) the Address-Property of
my Person-Object ist null. Perhaps I did not use the Models correctly ...?
-- 
View this message in context: 
http://www.nabble.com/Example-for-FormComponentPanel-best-practice-for-reusable-form-components-tp23391811p23393211.html
Sent from the Wicket - User 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: Example for FormComponentPanel/best-practice for reusable form-components

2009-05-05 Thread Igor Vaynberg
a) you are not chaining the postcode and city models, so those values
will never make it into anything
b) so person.address is null? are you sure the person object you are
giving to the form has a non-null address bean? if so i would set a
modification breakpoint on the field and see where it is being set to
null.

-igor

On Tue, May 5, 2009 at 11:22 AM, FlyingMustang hauptm...@ecmlabs.de wrote:


 igor.vaynberg wrote:

 show us your code.


 Ok, I have a class 'Person' with an'Address-Property. My Form-object has a
 simple Model wrapping a Person-object. The constructor creating the Panel
 with the form contains these lines:

 form = new FormPerson(form, new ModelPerson());
 personFormComponent = new
 PersonFormComponentStudent(personFormComponent, form.getModel());
 addressFormComponent = new
 AddressFormComponentAddress(addressFormComponent, new
 PropertyModelAddress(this.form.getModel(), address));

 form.add(personFormComponent);
 form.add(addressFormComponent);

 After creation of this Panel I call form.setModelObject(...). So the model
 ist not empty. The PersonFormComponent works well as it only sets some
 String-Properties of the Person-Object. But I have trouble with the
 AddressFormComponent which looks like this:

 public class AddressFormComponentT extends Address extends
 FormComponentPanelT {
        protected TextFieldString cityField, postcodeField, streetField;
        protected IModelT model;

        public AddressFormComponent(String id, IModelT model) {
                super(id, model);

                // Model
                this.model = model;

                // Straße
                streetField = new TextFieldString(streetField, new
 PropertyModelString(model, street));
                streetField.setRequired(true);
                streetField.add(StringValidator.lengthBetween(0, 100));

                // PLZ
                postcodeField = new TextFieldString(postcodeField, new
 ModelString());
                postcodeField.setRequired(true);

                // Stadt
                cityField = new TextFieldString(cityField, new 
 ModelString());
                cityField.setRequired(true);
                cityField.add(StringValidator.lengthBetween(0, 50));

                this.add(streetField);
                this.add(postcodeField);
                this.add(cityField);
        }
 }

 After submitting the whole form (with an AjaxButton) the Address-Property of
 my Person-Object ist null. Perhaps I did not use the Models correctly ...?
 --
 View this message in context: 
 http://www.nabble.com/Example-for-FormComponentPanel-best-practice-for-reusable-form-components-tp23391811p23393211.html
 Sent from the Wicket - User 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



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



Re: Example for FormComponentPanel/best-practice for reusable form-components

2009-05-05 Thread John Krasnay
AddressFormComponent should extend Panel, not FormComponentPanel.
FormComponentPanel is used for special cases where you have several
FormComponents that work together to edit a model value, such as a date
editor that has dropdowns for month and day.

On a FormComponentPanel, you have to implement convertValue() to gather
the input from your subcomponents, synthesize them into a single value,
and call setConvertedValue(). Since you never call setConvertedValue(),
your panel pushes null back into your address model.

jk

On Tue, May 05, 2009 at 11:22:44AM -0700, FlyingMustang wrote:
 
 
 igor.vaynberg wrote:
  
  show us your code.
  
 
 Ok, I have a class 'Person' with an'Address-Property. My Form-object has a
 simple Model wrapping a Person-object. The constructor creating the Panel
 with the form contains these lines:
 
 form = new FormPerson(form, new ModelPerson());
 personFormComponent = new
 PersonFormComponentStudent(personFormComponent, form.getModel());
 addressFormComponent = new
 AddressFormComponentAddress(addressFormComponent, new
 PropertyModelAddress(this.form.getModel(), address));
 
 form.add(personFormComponent);
 form.add(addressFormComponent);
 
 After creation of this Panel I call form.setModelObject(...). So the model
 ist not empty. The PersonFormComponent works well as it only sets some
 String-Properties of the Person-Object. But I have trouble with the
 AddressFormComponent which looks like this:
 
 public class AddressFormComponentT extends Address extends
 FormComponentPanelT {
   protected TextFieldString cityField, postcodeField, streetField;
   protected IModelT model;
 
   public AddressFormComponent(String id, IModelT model) {
   super(id, model);
 
   // Model
   this.model = model;
 
   // Straße
   streetField = new TextFieldString(streetField, new
 PropertyModelString(model, street));
   streetField.setRequired(true);
   streetField.add(StringValidator.lengthBetween(0, 100));
 
   // PLZ
   postcodeField = new TextFieldString(postcodeField, new
 ModelString());
   postcodeField.setRequired(true);
 
   // Stadt
   cityField = new TextFieldString(cityField, new 
 ModelString());
   cityField.setRequired(true);
   cityField.add(StringValidator.lengthBetween(0, 50));
 
   this.add(streetField);
   this.add(postcodeField);
   this.add(cityField);
   }
 }
 
 After submitting the whole form (with an AjaxButton) the Address-Property of
 my Person-Object ist null. Perhaps I did not use the Models correctly ...?
 -- 
 View this message in context: 
 http://www.nabble.com/Example-for-FormComponentPanel-best-practice-for-reusable-form-components-tp23391811p23393211.html
 Sent from the Wicket - User 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
 

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



Re: Example for FormComponentPanel/best-practice for reusable form-components

2009-05-05 Thread FlyingMustang


John Krasnay wrote:
 
 AddressFormComponent should extend Panel, not FormComponentPanel.
 

Thank you for yout help! Now AddressFormComponent extends from Panel and
fixed the wrong chainigs. I also asserted that the address is NOT null right
before I submit the form in my test-case. But after submission I still get
the following Exception:
 
org.apache.wicket.WicketRuntimeException: Attempted to set property value on
a null object. Property expression: street Value: Straße
at
org.apache.wicket.util.lang.PropertyResolver.setValue(PropertyResolver.java:125)
at
org.apache.wicket.model.AbstractPropertyModel.setObject(AbstractPropertyModel.java:169)
at 
org.apache.wicket.Component.setDefaultModelObject(Component.java:3021)
at
org.apache.wicket.markup.html.form.FormComponent.updateModel(FormComponent.java:1141)
at
org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:223)
at
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:488)
at
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:467)
at
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:467)
at
org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrder(FormComponent.java:439)
at
org.apache.wicket.markup.html.form.Form.internalUpdateFormComponentModels(Form.java:1970)
at
org.apache.wicket.markup.html.form.Form.updateFormComponentModels(Form.java:1938)
at org.apache.wicket.markup.html.form.Form.process(Form.java:960)
at org.apache.wicket.markup.html.form.Form.process(Form.java:908)
at 
org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:876)
-- 
View this message in context: 
http://www.nabble.com/Example-for-FormComponentPanel-best-practice-for-reusable-form-components-tp23391811p23395642.html
Sent from the Wicket - User 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: Example for FormComponentPanel/best-practice for reusable form-components

2009-05-05 Thread Igor Vaynberg
create a quickstart and attach it to a jira issue

-igor

On Tue, May 5, 2009 at 1:47 PM, FlyingMustang hauptm...@ecmlabs.de wrote:


 John Krasnay wrote:

 AddressFormComponent should extend Panel, not FormComponentPanel.


 Thank you for yout help! Now AddressFormComponent extends from Panel and
 fixed the wrong chainigs. I also asserted that the address is NOT null right
 before I submit the form in my test-case. But after submission I still get
 the following Exception:

 org.apache.wicket.WicketRuntimeException: Attempted to set property value on
 a null object. Property expression: street Value: Straße
        at
 org.apache.wicket.util.lang.PropertyResolver.setValue(PropertyResolver.java:125)
        at
 org.apache.wicket.model.AbstractPropertyModel.setObject(AbstractPropertyModel.java:169)
        at 
 org.apache.wicket.Component.setDefaultModelObject(Component.java:3021)
        at
 org.apache.wicket.markup.html.form.FormComponent.updateModel(FormComponent.java:1141)
        at
 org.apache.wicket.markup.html.form.Form$FormModelUpdateVisitor.component(Form.java:223)
        at
 org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:488)
        at
 org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:467)
        at
 org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrderHelper(FormComponent.java:467)
        at
 org.apache.wicket.markup.html.form.FormComponent.visitComponentsPostOrder(FormComponent.java:439)
        at
 org.apache.wicket.markup.html.form.Form.internalUpdateFormComponentModels(Form.java:1970)
        at
 org.apache.wicket.markup.html.form.Form.updateFormComponentModels(Form.java:1938)
        at org.apache.wicket.markup.html.form.Form.process(Form.java:960)
        at org.apache.wicket.markup.html.form.Form.process(Form.java:908)
        at 
 org.apache.wicket.markup.html.form.Form.onFormSubmitted(Form.java:876)
 --
 View this message in context: 
 http://www.nabble.com/Example-for-FormComponentPanel-best-practice-for-reusable-form-components-tp23391811p23395642.html
 Sent from the Wicket - User 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



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