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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to