In onbeforerender you should init the modelobkect not the model.

But in your simple case you dont even need onbrforwrender, instead:
new textfield(..., new propertymodel(this,"model")). Done.

-Igor

On Sunday, May 17, 2009, Ian MacLarty <ian.macla...@gmail.com> wrote:
> Hi,
>
> If I have a TextField whose model object is a Float, then if the user
> enters an invalid value, say "aaa",  the TextField will remember that
> invalid value and display it when the page is re-rendered.  How would
> you go about getting the same behaviour for a custom FormComponent?
>
> Here is my simple custom FormComponent.
>
> public class MyPanel extends FormComponentPanel {
>     TextField field;
>
>     public MyPanel(String id) {
>         super(id);
>         field = new TextField("f", Float.class);
>         add(field);
>     }
>
>    �...@override
>     protected void convertInput() {
>         setConvertedInput(field.getConvertedInput());
>     }
>
>    �...@override
>     protected void onBeforeRender() {
>         field.setModel(getModel());
>         super.onBeforeRender();
>     }
> }
>
> <wicket:panel>
>     <input wicket:id="f" type="text" />
> </wicket:panel>
>
> And here is how I use it:
>
> public class HomePage extends WebPage {
>
>     private static final long serialVersionUID = 1L;
>
>     public HomePage(final PageParameters parameters) {
>         CompoundPropertyModel cpModel = new CompoundPropertyModel(this);
>         Form form = new Form("form", cpModel);
>         form.add(new TextField("field1", Float.class));
>         form.add(new MyPanel("field2"));
>         add(form);
>     }
>
>     private Float field1 = 1.0f;
>     private Float field2 = 2.0f;
>
>     public Float getField1() {
>         return field1;
>     }
>
>     public void setField1(Float value) {
>         field1 = value;
>     }
>
>     public Float getField2() {
>         return field2;
>     }
>
>     public void setField2(Float value) {
>         field2 = value;
>     }
> }
>
> <html>
>     <head>
>         <title>Wicket Quickstart Archetype Homepage</title>
>     </head>
>     <body>
>         <form wicket:id="form">
>             <input wicket:id="field1" type="text" />
>             <div wicket:id="field2" />
>             <input type="submit" value="Submit" />
>         </form>
>     </body>
> </html>
>
> If I run this and enter "aaa" for field1 and "bbb" for field2 and
> submit the form, then when the page is re-rendered field1 still has
> "aaa", but field2 has been reset to "2".  I'm pretty sure the problem
> is to do with the call to setModel in MyPanel#onBeforeRender, but I
> don't know how else to link the FormComponent model with the model of
> the TextField inside the FormComponent.
>
> Any help would be greatly appreciated.  I'm using Wicket 1.3.5.
>
> Cheers,
> Ian.
>
> ---------------------------------------------------------------------
> 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

Reply via email to