Wicket newbie so standard up front apologies. We are running our intranet on Wicket 1.4.18. I have searched the forums but I mostly see requests to generate stateless pages. I need to do the opposite. I need to generate a stateful page off an AutoCompleteTextField onchange/onsubmit event.
Setup: I have an AutoCompleteTextField as the only component inside a form, no buttons or submit links. The AutoComplete field holds a list of strings of people's names and email addresses. Beneath the form in the html markup is a WebMarkupContainer which holds a ListView. The ListView is fed by a simple property model of Person objects which is empty on initial rendering. When a person is selected in the AutoComplete field then the ListView is updated to display one row with person-dependent links to other pages. I know the ListView is over kill for displaying only one row but the code was brought forward from a previous app so why re-invent the wheel. What is working: When a user types in chars and eventually selects a name from the AutoComplete they hit Enter and the name populates the field. I have an AjaxFormSubmitBehavior on the AutoComplete field where I trap the onSubmit, manipulate the selected user string and populate the simple property model with a Person object from our system. I then trigger a target.addComponent on the WebMarkupContainer to force the ListView to be rendered with the new Person object from the model and life is all good. I get the display results I am looking for...except The Problem: When the page is first rendered it is stateless (url just shows wicket:bookmarkablePage=:com.ourstuff.PersonSelectionPage). Even after the user types in chars to do the AutoComplete process, hits Enter to select the name from the AutoComplete listing, and the ajax process updates the ListView display with the resulting links for that person the page is still stateless. At that point If the user selects a link from the ListView and then tries to return to the page with a browser Back button they are returned to a blank AutoComplete field with no ListView data (since there is no stateful page to return to.) I do see that both the Form and AutoCompleteTextField component's onSubmit events are called when the user hits enter to select the name from the listing. What I don't understand: After selecting a person from the AutoComplete listing if I place the cursor in the AutoComplete field again and hit Enter, then the Form's onSubmit event is called again but this time the page is returned to the server, gets versioned with a wicket:interface=:2:1:::, and I am able to click the ListView links and return to the person populated page with the Back button. Not sure why the Form's onSubmit event behaves differently unless the AutoComplete's onSubmit is overridding it? The Question: So, how can I force a page to get 'versioned' on an AutoCompleteTextField onchange/onsubmit event without asking the user to click an additional button or link? I have attached the code for the relevant objects Form<Void> form = new Form<Void>("form") { @Override public void onSubmit() { System.out.println("form submit"); } }; final AutoCompleteTextField<String> field = new AutoCompleteTextField<String>("ac", new Model<String>("")) { private static final long serialVersionUID = 1L; @Override protected Iterator<String> getChoices(String input) { if (Strings.isEmpty(input)) { List<String> emptyList = Collections.emptyList(); return emptyList.iterator(); } List<String> choices = new ArrayList<String>(20); for (final Persons person : customers) { String fullname = person.getFullName() + " (" + person.getEmail() + ")"; if (fullname.toLowerCase().contains(input.toLowerCase())) { choices.add(fullname); if (choices.size() == 15) { break; } } } return choices.iterator(); } }; form.add(field); field.add(new AjaxFormSubmitBehavior(form, "onchange") { private static final long serialVersionUID = 1L; @Override protected void onSubmit(AjaxRequestTarget target) { // get the person record for the autocomplete user and update the chart System.out.println("ajax submit"); String fullfieldentry = field.getModelObject(); String email = parseEmailFromEntry(fullfieldentry); if (!email.equals("")) { SessionFactory factory = siteDaoFactory.getSessionFactory(); HibernateUtility.openSession(factory); try { // set the model with the Person object setLoneUser(personDao.findPersonsByEmailWithInit(email)); // wicket won't allow us to target the PageableListView repeater // so we need to target the wmc holding the repeater. target.addComponent(datacontainer); } catch (Exception e) { e.printStackTrace(); }finally { HibernateUtility.close(factory); } } } @Override protected void onError(AjaxRequestTarget target) { } }); -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-Generate-a-Stateful-page-off-an-AutoCompleteTextField-onchange-onsubmit-event-tp4666414.html Sent from the Users forum mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org