0
votes

I have a form with an inputfield, a label and an ajax button. I want to change the value of the label based on the ajax request AND i want the textfield to remember entered value via browser autocomplete. The basic structure is based on browser native autocomplete for dynamically generated forms (handled with ajax)

I reached both goals and the form works fine, both when submitting by Enter and by Button. I can even change the textfield value and submit again. Only if I submit the Form a second time without changing the textfield value, I get a org.apache.wicket.core.request.mapper.StalePageException. It does not matter whether the first or the second submit happened through Enter or Button. Any combination leads to a stale renderCount as long as the textfield value is not changed. And 'not changed' includes reentering the same value again. That leads to the Exception, too.

I am not quite sure how entering a new value in a textfield changes the way wicket processes the page. Any help welcome, please.

HTML:

    <html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
      <head>
        <wicket:head>
          <title>Suche   </title>
        </wicket:head>
      </head>
      <body>
        <form  target="the_iframe" wicket:id="w_form" id="myform" >
          <input wicket:id="w_input"/> 
          <label wicket:id="w_label">   </label>  
          <input wicket:id="w_button" type="submit"  onclick="myform.submit();"/>
        </form>
        <iframe name="the_iframe" hidden="true">   </iframe> 
      </body>
    </html>

Javacode:

public class TestseitePage extends WebPage {

  private final Form w_form = new Form("w_form");

  @Override
  protected void onInitialize() {
    super.onInitialize();
    final TextField<String> w_input = new TextField<String>("w_input", new Model<String>(""));
    final Model m = new Model<String>("Test");
    final Label w_label = new Label("w_label", m);
    w_label.setOutputMarkupId(true);
    add(w_form);
    w_form.add(w_label);
    w_form.add(w_input);
    final AjaxButton w_button = new AjaxButton("w_button") {
      @Override
      protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
        try {
          Thread.sleep(2000);
        } catch (final InterruptedException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        m.setObject("Button " + new Date().getTime());
        target.add(w_label);
      }
    };
    w_form.add(w_button);
  }
}
1

1 Answers

1
votes

Remove onclick="myform.submit();" from the button's markup. It looks to me that this will trigger non-Ajax submit of the Form and this will lead to full page re-render and thus the change of the Page#renderCount