When a field is submitted and there is a validation error, it doesn't update the model and the field will redisplay with the invalid input. This way the user can see what they typed and can fix the problem. With your populate link, you are updating the model, but wicket won't look at the model because the field is redisplaying the invalid input (in your case an empty field).

If you want to update the underlying model value and ignore the previous failed validation you will need to clear the input. You could use Form.clearInput() to clear all invalid fields or testInput.clearInput() perhaps.

Neil Curzon wrote:
Thanks for the reply.

It doesn't sound like this is exactly what I want, though. I do need my
required field to be validated, always. I just don't understand why
validation works when the link that fills in the Integer behind the property
model is clicked first, but the same link populating and updating the field
stops working after a validation error.

On Fri, Sep 4, 2009 at 6:11 PM, Pedro Santos <pedros...@gmail.com> wrote:

Take a look at:

http://wicket.apache.org/docs/wicket-1.3.2/wicket/apidocs/org/apache/wicket/markup/html/form/Button.html#setDefaultFormProcessing(boolean)<http://wicket.apache.org/docs/wicket-1.3.2/wicket/apidocs/org/apache/wicket/markup/html/form/Button.html#setDefaultFormProcessing%28boolean%29>

On Fri, Sep 4, 2009 at 7:01 PM, Neil Curzon <neil.cur...@gmail.com> wrote:

Hi all,

I'm having a weird problem that causes an input to refuse to update with
an
AjaxLink click method when there's been a validation error. One field in
the
form has a property model pointing to an Integer value. It's set to
required, and there are other links that set the Integer value.

What I see is that when I first click a link that populates the Integer
under the required field, everything works fine. But when I click submit
first, the populate links stop working. The handlers are still invoked,
but
the HTML that comes back in the Ajax Debug shows an input with value=""
(even though the getModelObject() for that TextField returns the proper
value in debugging statements). This results in the input always being
showed empty. If I do things in the proper order, I see the correct value
populate in the text field as expected. It's not just a display issue,
either. The form refuses to submit successfully at all if there was a
validation error first (and you don't manually enter anything into the
field).

Below is a simple application that reproduces the issue I'm seeing. I'm
using wicket 1.3.7 but I've tried 1.4.1 with the same result. Any help
would
be greatly appreciated.

Thanks
Neil



public class HomePage extends WebPage {

   public HomePage() {
       add(new TestForm("testForm"));
   }

   class TestForm extends Form {

       private Integer value;
       private FeedbackPanel feedbackPanel;
       private TextField testInput;

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

           add(feedbackPanel = new FeedbackPanel("feedbackPanel"));
           feedbackPanel.setOutputMarkupId(true);

           add(testInput = new TextField("testInput", new
PropertyModel(this, "value")));
           testInput.setRequired(true);
           testInput.setOutputMarkupId(true);

           add(new AjaxButton("submitButton"){
               @Override
               protected void onError(AjaxRequestTarget target, Form
form)
{
                   target.addComponent(feedbackPanel);
               }

               protected void onSubmit(AjaxRequestTarget target, Form
form)
{
                   info("It worked!");
                   target.addComponent(feedbackPanel);
               }
           });

           add(new AjaxLink("chooseOneLink"){
               public void onClick(AjaxRequestTarget target) {
                   value = 1;
                   target.addComponent(testInput);
                   target.addComponent(feedbackPanel);
               }
           });
       }
   }
}

<html>
   <body>
       <form wicket:id="testForm">
           <div wicket:id="feedbackPanel"/>
           <input wicket:id="testInput"/>
           <a wicket:id="chooseOneLink">Choose 1</a>
           <button wicket:id="submitButton">Submit</button>
       </form>
   </body>
</html>



--
Jason Lea


Reply via email to