You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Craig L <cl...@spinnphr.com> on 2014/07/01 20:21:28 UTC

How to Generate a Stateful page off an AutoCompleteTextField onchange/onsubmit event

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-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to Generate a Stateful page off an AutoCompleteTextField onchange/onsubmit event

Posted by Craig L <cl...@spinnphr.com>.
Hello Martin,
Thank you for the swift reply.

I added the call at the beginning of my constructor but that doesn't seem
to make any difference in the application. When the page loads the
url still shows the
?wicket:bookmarkablePage=:com.ourstuff.PatientSelectionPage. That url
remains throughout the AutoCompleteTextField selection process that
triggers a Form onSubmit and a AutoComplete component onSubmit event.

setStatelessHint(*false*);

System.*out*.println("is page stateless: " + isPageStateless());

Console shows:   11:56:33,898 INFO [STDOUT] is page stateless: false

As I mentioned in my original description, once the AutoComplete field is
populated with a name, if I place the cursor in the AutoCompleteTextField
and then hit the Enter key only the Form component's onSubmit is triggered
(as I would expect) and the page is versioned.  This is the behavior I
would LIKE to get from the AutoCompleteTextField selection.

For my better understanding, why are the two Form onSubmits different and
because they do seem different, can I force the
AutoComplete/onchange/onsubmit event to behave like the Field level Enter
key event and force a versioning of the page?

I have another page that uses a PageableListView that behaves the same way
(no page version created). I would like to version each navigatable page
so when a user clicks a link from say page 4 of the PLV I would like them
to return to page 4 on a Back button press.

Thank you,

Craig

ps. I will see what I can do regarding duplicating the issue in 6.16 but
upgrading our current environment is not an immediate option.




On Wed, Jul 2, 2014 at 2:06 AM, Martin Grigorov-4 [via Apache Wicket] <
ml-node+s1842946n4666417h95@n4.nabble.com> wrote:

> Hi,
>
> If there is an Ajax component in the page then it should be stateful.
> AutoCompleteTextField is an Ajax component and it should be enough.
> But it seems there is some problem ...
> If you are able to reproduce it with Wicket Quickstart 6.16.0 then please
> attach the application to a ticket in JIRA !
>
> The solution: call page.setStatelessHint(false) to mark the page as
> stateful explicitly.
>
> Martin Grigorov
> Wicket Training and Consulting
> https://twitter.com/mtgrigorov
>
>
> On Tue, Jul 1, 2014 at 9:21 PM, Craig L <[hidden email]
> <http://user/SendEmail.jtp?type=node&node=4666417&i=0>> wrote:
>
> > 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: [hidden email]
> <http://user/SendEmail.jtp?type=node&node=4666417&i=1>
> > For additional commands, e-mail: [hidden email]
> <http://user/SendEmail.jtp?type=node&node=4666417&i=2>
> >
> >
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://apache-wicket.1842946.n4.nabble.com/How-to-Generate-a-Stateful-page-off-an-AutoCompleteTextField-onchange-onsubmit-event-tp4666414p4666417.html
>  To unsubscribe from How to Generate a Stateful page off an
> AutoCompleteTextField onchange/onsubmit event, click here
> <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=4666414&code=Y2xhaWRsYXdAc3Bpbm5waHIuY29tfDQ2NjY0MTR8OTkzNDE0MjE4>
> .
> NAML
> <http://apache-wicket.1842946.n4.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>


--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/How-to-Generate-a-Stateful-page-off-an-AutoCompleteTextField-onchange-onsubmit-event-tp4666414p4666425.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: How to Generate a Stateful page off an AutoCompleteTextField onchange/onsubmit event

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

If there is an Ajax component in the page then it should be stateful.
AutoCompleteTextField is an Ajax component and it should be enough.
But it seems there is some problem ...
If you are able to reproduce it with Wicket Quickstart 6.16.0 then please
attach the application to a ticket in JIRA !

The solution: call page.setStatelessHint(false) to mark the page as
stateful explicitly.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov


On Tue, Jul 1, 2014 at 9:21 PM, Craig L <cl...@spinnphr.com> wrote:

> 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-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>