0

I'm having some problems understanding what I'm doing wrong.

What I do:

  • Override getHomePage() in my Application. I return MyStartPage.class.
  • MyStartPage is a subclass of MySubPage.
  • MySubPage is a subclass of MySuperPage.
  • In MySuperPage I add a Panel. This Panel has a TextField and WebMarkupContainer with a AjaxEventBehavior(onclick) that prints the backing modelObject of the textfield.

What happens when I start my server and browse localhost/MyApp:

  • The printed modelObject is null even though the user input is not when I click my WebMarkupContainer.

What happens when I start my server, browse localhost/MyApp, go to another Page in my app and then back to MyStartPage:

  • The printed modelObject matches the user input when I click my WebMarkupContainer.

It also works when I do the following:

  • Override getHomePage() in my Application and return MyLoginPage. MyLoginPage contains MySigninPanel. In MySigninPanel I override onSignInSucceeded() like this:

    @Override
    protected void onSignInSucceeded() {
         setResponsePage(new MyStartPage());
    }
    

Can someone shed some light on what the correct way of getting my TextField to work properly when the user clicks the WebMarkupContainer the first thing they do?

Thanks in advance!

//EDIT :

This only seems to be a problem in Firefox, or at least it's working fine in Chrome IE9 and IE8-mode in IE9.

bumaklion
  • 171
  • 12

2 Answers2

1

Your TextField's model will not be updated with user entered data unless you submit a Form with your click event. Your TextField should be the child of that Form. If it is, then it's content will be sent to the server, converted to the target type, and validated. On success, you'll be able to query the model and view the data entered on your page.

In order to do this, you should use a AjaxFormSubmitBehavior instead of the AjaxEventBehavior you are currently using:

webMarkupContainer.add(new AjaxFormSubmitBehavior(form, "onclick") {

    @Override
    protected void onSubmit(AjaxRequestTarget target) {
        // You can now see what was entered in your TextField
        System.out.println(textField.getModelObject());
    }

    @Override
    protected void onError(AjaxRequestTarget target) {
        // An error occurred and you should provide some kind of feedback
    }
});
Daniel Semmens
  • 461
  • 2
  • 4
  • Thanks for your reply. I'm checking my code and thats actually what I do (I tried with AjaxEventBehavior and adding an AjaxFormComponentUpdatingBehavior(onchange) to the textfield, but that did not work either). With your example, I get why it would start working when I click another link in the system, but then the modelObject of the textField would not change without me doing that after every time I change the input. What I see happening is that after I click another link, it works every time, both with AjaxEventBehavior and AjaxFormSubmitBehavior. Any ideas? – bumaklion Jul 16 '12 at 07:12
0

Well, i have a solution, although I'm not sure why it works. I added

mountPage("invoice/overview", OverviewPage.class);

In my WebApplication, and now it works in FireFox (OverviewPage is referred to as 'MyStartPage' in my initial post).

Here is what the wicket.ajax.baseurl and the typed url in the browser looked like before the change, when it did not work:

baseUrl: wicket/bookmarkable/eyesys.web.invoice.overview.OverviewPage
browser url: wicket/bookmarkable/eyesys.web.invoice.overview.OverviewPage?1

And after the change:

baseUrl: invoice/overview
browser url: invoice/overview?1

bumaklion
  • 171
  • 12