• Post Reply Bookmark Topic Watch Topic
  • New Topic

What is the best way to trigger an action from an input field?

 
Henrik Larne
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application where the user is supposed to enter his username on one page and press a link "next" to get to the next page. To enhance the user experience I want to allow him to simply press enter in the input field to go to the next page. The site navigation is setup in a faces config file.

The problem is that the input field does not handle actions that trigger page navigation, but only ValueChangeListeners and they do not trigger navigation. The way I solved it was to register a valueChangeListener on the inputText field and then let the value change method lookup the link command object and create and queue an action event on that command. Code:



This does not seem like the most convient method to solve the problem. Does anybody have a better solution?
 
Efrat Bar-Nahum
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you use a simple command button of type submit?
When pressing the button you'll get to the bounded method in the bean, and before that the set method for your input field will be called.
An action must be bound to a method with no parameters and return a String to the navigation handler.
This way you can save the user and navigate to the next page.

Efrat
 
Henrik Larne
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The page design I use does not allow the use of a command button. It looks much better with a command link.

It would be neat if the value change method could return a String the same way the action methods can and if the returned String were not null it would trigger the navigation logic.
 
Efrat Bar-Nahum
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if you can't use a command button you have only 3 other options for using a method binding expression:
validator, actionListener & valueChangeListener.

Efrat
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!