You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Ned Collyer <ne...@gmail.com> on 2008/11/26 09:57:32 UTC

Using CompoundPropertyModel with FormComponentPanel

I'm trying to throw together some components for easily creating accessible
forms.

I'm a fair bit along - just need some assistance with how to structure the
class for use with CompoundPropertyModels.

I want to be able to do the following:

Form form = new Form("form", new CompoundPropertyModel(new User());
form.add(new LabelledTextField("name"))

But I'm having difficulty setting the property model against the textfield
inside my LabelledTextField.

I can retrieve the values just fine, and they are set on the object from the
forms CPM.

I am using a fragment so that markup can be edited in a single place for all
"labelled" form fields.  And different markup providers or variants can be
used if any edge cases occur for any projects.

The form fields can also used as easily as any other form fields in wicket -
this is a different approach from wicketopia - which I've had a good dig
through.

I've gotta be close!


/* the class itself */

private final FormComponentLabel label;
private final Label labelText;
private final TextField<T> editor;
private Fragment componentFragment;

public class LabelledTextField<T> extends FormComponentPanel<T> {

	public LabelledTextField(String id) {
	    super(id);

	    componentFragment = new Fragment(COMPONENT_ID, "textField", this);
	    editor = new TextField<T>("editor", new PropertyModel(this,
String.format("model.%s", id)));
	    label = new FormComponentLabel("label", editor);
	    labelText = new Label("labelText", "TBA");
	    label.add(labelText);

	    componentFragment.add(editor);
	    componentFragment.add(label);

	    add(componentFragment);

	    setRenderBodyOnly(true);
	}

	protected void convertInput() {
	    setConvertedInput(editor.getConvertedInput());
	}

	public String getInput() {
	    return editor.getInput();
	}
}
-- 
View this message in context: http://www.nabble.com/Using-CompoundPropertyModel-with-FormComponentPanel-tp20697019p20697019.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: Using CompoundPropertyModel with FormComponentPanel

Posted by Ned Collyer <ne...@gmail.com>.
I'm not sure how to get the textfield "editor" working on the property "name"
of the user object - I am aware the CPM is trying to look at the id "editor"
which is wrong :).
-- 
View this message in context: http://www.nabble.com/Using-CompoundPropertyModel-with-FormComponentPanel-tp20697019p20698456.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: Using CompoundPropertyModel with FormComponentPanel

Posted by Nino Saturnino Martinez Vazquez Wael <ni...@jayway.dk>.
ahhh, didnt catch that you were doing that..

Ned Collyer wrote:
> I'm going to be sourcing the labelText from a properties file relatve to the
> class of the modelObject (in this case it will be the User - eg,
> user.properties).
>
> If I use the binding, then I need to have scope to the CPM in java world...
> within the LabelledTextField - which is a shame, because it just makes it
> less convenient to use like other regular form components where you do not
> have to pass in the model if the form has CPM (eg, standard TextField) 
>
>
> Nino.Martinez wrote:
>   
>> Hi Ned
>>
>> you can call bind on the compound property model..
>>
>> labelText = new Label("labelText", CPM.bind("propertyname"));
>>
>> You can also do this for your property models btw...
>>
>>     
>
>   

-- 
-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: Using CompoundPropertyModel with FormComponentPanel

Posted by Ned Collyer <ne...@gmail.com>.
I'm going to be sourcing the labelText from a properties file relatve to the
class of the modelObject (in this case it will be the User - eg,
user.properties).

If I use the binding, then I need to have scope to the CPM in java world...
within the LabelledTextField - which is a shame, because it just makes it
less convenient to use like other regular form components where you do not
have to pass in the model if the form has CPM (eg, standard TextField) 


Nino.Martinez wrote:
> 
> Hi Ned
> 
> you can call bind on the compound property model..
> 
> labelText = new Label("labelText", CPM.bind("propertyname"));
> 
> You can also do this for your property models btw...
> 

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

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

you can call bind on the compound property model..

labelText = new Label("labelText", CPM.bind("propertyname"));

You can also do this for your property models btw...

Ned Collyer wrote:
> I'm trying to throw together some components for easily creating accessible
> forms.
>
> I'm a fair bit along - just need some assistance with how to structure the
> class for use with CompoundPropertyModels.
>
> I want to be able to do the following:
>
> Form form = new Form("form", new CompoundPropertyModel(new User());
> form.add(new LabelledTextField("name"))
>
> But I'm having difficulty setting the property model against the textfield
> inside my LabelledTextField.
>
> I can retrieve the values just fine, and they are set on the object from the
> forms CPM.
>
> I am using a fragment so that markup can be edited in a single place for all
> "labelled" form fields.  And different markup providers or variants can be
> used if any edge cases occur for any projects.
>
> The form fields can also used as easily as any other form fields in wicket -
> this is a different approach from wicketopia - which I've had a good dig
> through.
>
> I've gotta be close!
>
>
> /* the class itself */
>
> private final FormComponentLabel label;
> private final Label labelText;
> private final TextField<T> editor;
> private Fragment componentFragment;
>
> public class LabelledTextField<T> extends FormComponentPanel<T> {
>
> 	public LabelledTextField(String id) {
> 	    super(id);
>
> 	    componentFragment = new Fragment(COMPONENT_ID, "textField", this);
> 	    editor = new TextField<T>("editor", new PropertyModel(this,
> String.format("model.%s", id)));
> 	    label = new FormComponentLabel("label", editor);
> 	    labelText = new Label("labelText", "TBA");
> 	    label.add(labelText);
>
> 	    componentFragment.add(editor);
> 	    componentFragment.add(label);
>
> 	    add(componentFragment);
>
> 	    setRenderBodyOnly(true);
> 	}
>
> 	protected void convertInput() {
> 	    setConvertedInput(editor.getConvertedInput());
> 	}
>
> 	public String getInput() {
> 	    return editor.getInput();
> 	}
> }
>   

-- 
-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: Using CompoundPropertyModel with FormComponentPanel

Posted by Ned Collyer <ne...@gmail.com>.
FYI, you are awesome.

Always obvious what the problem is after its fixed hey ;)


igor.vaynberg wrote:
> 
> then just"model.object" will do :)
> 
> -igor
> 

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

Posted by Igor Vaynberg <ig...@gmail.com>.
then just"model.object" will do :)

-igor

On Wed, Nov 26, 2008 at 2:08 PM, Ned Collyer <ne...@gmail.com> wrote:
>
> Bupbow. - that Yields an exception because the FormComponentPanels model
> object is of type String - not user.
>
> editor = new TextField<T>("editor", new PropertyModel<T>(this,
> String.format("model.object.%s", id)));
>
> org.apache.wicket.WicketRuntimeException: No get method defined for class:
> class java.lang.String expression: name
>
> Rgds
>
> Ned
>
>
>
>
> igor.vaynberg wrote:
>>
>> String.format("model.object.%s", id)));
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Using-CompoundPropertyModel-with-FormComponentPanel-tp20697019p20709911.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
>
>

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


Re: Using CompoundPropertyModel with FormComponentPanel

Posted by Ned Collyer <ne...@gmail.com>.
Bupbow. - that Yields an exception because the FormComponentPanels model
object is of type String - not user.

editor = new TextField<T>("editor", new PropertyModel<T>(this,
String.format("model.object.%s", id)));

org.apache.wicket.WicketRuntimeException: No get method defined for class:
class java.lang.String expression: name

Rgds

Ned




igor.vaynberg wrote:
> 
> String.format("model.object.%s", id)));
> 
> 

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

Posted by Igor Vaynberg <ig...@gmail.com>.
String.format("model.object.%s", id)));

On Wed, Nov 26, 2008 at 12:57 AM, Ned Collyer <ne...@gmail.com> wrote:
>
> I'm trying to throw together some components for easily creating accessible
> forms.
>
> I'm a fair bit along - just need some assistance with how to structure the
> class for use with CompoundPropertyModels.
>
> I want to be able to do the following:
>
> Form form = new Form("form", new CompoundPropertyModel(new User());
> form.add(new LabelledTextField("name"))
>
> But I'm having difficulty setting the property model against the textfield
> inside my LabelledTextField.
>
> I can retrieve the values just fine, and they are set on the object from the
> forms CPM.
>
> I am using a fragment so that markup can be edited in a single place for all
> "labelled" form fields.  And different markup providers or variants can be
> used if any edge cases occur for any projects.
>
> The form fields can also used as easily as any other form fields in wicket -
> this is a different approach from wicketopia - which I've had a good dig
> through.
>
> I've gotta be close!
>
>
> /* the class itself */
>
> private final FormComponentLabel label;
> private final Label labelText;
> private final TextField<T> editor;
> private Fragment componentFragment;
>
> public class LabelledTextField<T> extends FormComponentPanel<T> {
>
>        public LabelledTextField(String id) {
>            super(id);
>
>            componentFragment = new Fragment(COMPONENT_ID, "textField", this);
>            editor = new TextField<T>("editor", new PropertyModel(this,
> String.format("model.%s", id)));
>            label = new FormComponentLabel("label", editor);
>            labelText = new Label("labelText", "TBA");
>            label.add(labelText);
>
>            componentFragment.add(editor);
>            componentFragment.add(label);
>
>            add(componentFragment);
>
>            setRenderBodyOnly(true);
>        }
>
>        protected void convertInput() {
>            setConvertedInput(editor.getConvertedInput());
>        }
>
>        public String getInput() {
>            return editor.getInput();
>        }
> }
> --
> View this message in context: http://www.nabble.com/Using-CompoundPropertyModel-with-FormComponentPanel-tp20697019p20697019.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
>
>

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