Hi! I don't see the problem, setDefaultModelObject also clears input via internalOnModelChanged:
public final Component setDefaultModelObject(final Object object) { final IModel<Object> model = (IModel<Object>)getDefaultModel(); // Check whether anything can be set at all if (model == null) { throw new IllegalStateException( "Attempt to set model object on null model of component: " + getPageRelativePath()); } // Check authorization if (!isActionAuthorized(ENABLE)) { throw new UnauthorizedActionException(this, ENABLE); } // Check whether this will result in an actual change if (!getModelComparator().compare(this, object)) { modelChanging(); model.setObject(object); modelChanged(); } return this; } public final void modelChanged() { // Call user code internalOnModelChanged(); onModelChanged(); } protected void internalOnModelChanged() { // If the model for this form component changed, we should make it // valid again because there can't be any invalid input for it anymore. valid(); } public final void valid() { clearInput(); onValid(); } ** Martin 2010/2/23 Pedro Santos <pedros...@gmail.com>: > Hi Martin, call get or set defaultModel is not the solution, consider this > another test case: > > The new link implementation: > > AjaxLink link = new AjaxLink("reload") > { > �...@override > public void onClick(AjaxRequestTarget target) > { > textField.setDefaultModelObject(new Integer(30)); > target.addComponent(textField); > } > }; > > new test script: > > 1- click on the reload link, then you has as expected the text field markup > presenting the new value on model > 2 - type something wrong on the text field, like some non numeric characters > 3 - submit the form. At this moment, you has your forms components on the > server with the raw input > 3 - press reload link, to update the markup of the component > 4 - you has now an text field markup presenting the wrong user typed value, > and the original one on the component model > > For this case modelChanged or clearInput method solves the problem of render > the form component with his actual model value. > > It brings me an question, does store the raw input on server worth? > pro: user can go back to his form, and has all his input back > cons: he already get his input back on the render parse, and the browser can > remember just using html meta tags that require cache > > > On Tue, Feb 23, 2010 at 9:06 AM, Martin Makundi < > martin.maku...@koodaripalvelut.com> wrote: > >> Yes.. don't use referenceToModel. Instead call >> >> textField.getDefaultModelObject(); >> >> ** >> Martin >> >> 2010/2/23 Pedro Santos <pedros...@gmail.com>: >> > Hi Martin, consider this form: >> > >> > java code: >> > Form form = new Form("form"); >> > add(form); >> > final TextField<Integer> textField = new TextField("tf", new >> > Model()); >> > textField.setType(Integer.class); >> > textField.setOutputMarkupId(true); >> > form.add(textField); >> > AjaxLink link = new AjaxLink("reload") { >> > public void onClick(AjaxRequestTarget target) { >> > IModel referenceToModel = textField.getDefaultModel(); >> > referenceToModel.setObject(new Integer(30)); >> > target.addComponent(textField); >> > }}; >> > form.add(link); >> > form.add(new FeedbackPanel("fp")); >> > >> > markup code: >> > >> > <form wicket:id="form" > >> > <input wicket:id="tf" type="text" /> >> > <a wicket:id="reload">reload</a> >> > <input type="submit" /> >> > <div wicket:id="fp" ></div> >> > </form> >> > >> > In the browser: >> > 1 - you type something wrong on the text field, like some non numeric >> > characters >> > 2 - submit the form. At this moment, you has your forms components on the >> > server with the raw input >> > 3 - press reload link, to change the value on the text field model >> > 4 - you has now an text field presenting the wrong user typed value, and >> the >> > new one on the component model on server. >> > >> > >> > On Mon, Feb 22, 2010 at 5:55 PM, Martin Makundi < >> > martin.maku...@koodaripalvelut.com> wrote: >> > >> >> Hi! >> >> >> >> What's the difference whether it's thrown away or not if the next step >> >> is re-submit with new values? >> >> >> >> ** >> >> Martin >> >> >> >> 2010/2/22 Pedro Santos <pedros...@gmail.com>: >> >> > IMO the form processing can be: >> >> > >> >> >> >> >> >> 1. validate >> >> >> 2. detect error >> >> >> 3. keep rawinput >> >> >> 4. re-render error components with red border AND rawinput >> >> >> >> >> > >> >> > 4.1. throw away the raw input in some detach method >> >> > >> >> > 5. user retry form submit >> >> >> >> >> > >> >> > 6. all form components get they raw input again since they get >> rendered >> >> > before some detach method clear they raw input, no need to maintain >> those >> >> > values on the server >> >> > >> >> > >> >> > >> >> > >> >> > -- >> >> > Pedro Henrique Oliveira dos Santos >> >> > >> >> >> > >> > >> > >> > -- >> > Pedro Henrique Oliveira dos Santos >> > >> > > > > -- > Pedro Henrique Oliveira dos Santos >