mobileNavlogo
headerlogo

Event Handler Event handling in JSF

Blog Author

Tekslate

Published Date

17th September, 2018

Ratings

Views

183

  • Share this blog :

4 types of event handler  Event handling

  1. Action
  2. Action Listener
  3. Value change listener
  4. Phase listener

  Action

  • This attribute will be used for only the GUI Components like<h:command button> and<h:command link>
  • This attribute will rise action event automatically when we click on button or hyperlink and it will take a method name in the respective managed bean to execute in order to perform the respective action.
  • It we want to use this attribute in JSF applications to perform event handling, we have to use the following rules while preparing action method In managed bean component
  1. a) Method name must be same as the method which we have specified in method expression along with action attribute
  2. b) Managed bean method must not have any parameters
  3. c) Managed bean method must have string return type and it must return a string value.
  • This listener will use navigation system to identify the target page.
  • This listener may forward request to either same page from where the request is coming or any diff. page which we configured in faces-config.xml file

  Action Listener

  • This attribute will rise action event, it will send a request to faces servlet and it will make faces servlet to perform the respective action and forward request back to the same page from where faces servlet is getting request
  • It we want to use action listener attribute in JSF application n s then the respective managed bean method must have the following co mentions.
  1. Managed bean method name must be matched with the method name which we specified in method expression along with action listener attribute
  2. managed bean method must have ”action event” type as parameter
  3. Managed bean method must have ”void” return type & it must not return any value
  • This Listener will not use navigation system, because it will forward request to the same page from where the request is coming.
  • It will be applicable for the GUI Components like

<h:command button> and<h:command link>   Screenshot_22   <h:command Link value =”address details” action Listener =”#<empBean.displayAddressDetails}>”/>   Value change listener

  • This Listener will rise change event, it will send a request to faces servlet and it will make faces servlet to execute the respective managed bean method and forward request to the same JSP page from where the request is coming
  • If you want to use this listener in JSF applications then we have to use the following co mentions while preparing managed bean method.

  a)Method name must be matched with the method name specified along with Method expression as attribute values to ”value change listener”. b)managed bean method must have ”change event ”as parameter c)Managed bean method must  have ”void” return type & it must not return any value

  • This Listener will not use navigation system
  • This Listener will be applicable for the GUI Components like

<h:select many check box>     <h:select one menu> <h:select boolean check box>                   <h:select many menu> <h:select one radio> <h:select many list box> <h:select one list box>   Screenshot_23   Phase Listener In JSF based web appl n it we send a request from client to server then faces servlet will process the request by following request processing life cycle. àIn JSF request processing life cycle includes the phases like restore view, apply Request values, process validations update model values, invoke application  and render response 2In JSF based we apps the main purpose of phase listener is to read each & every phase in JSP request process in life cycle and gives notification before and after the at each and every phase 2If we want to use phase listener in JSF based web appl n we have to follow below steps   Step Prepare phase listener implementation class To prepare phase listener class we have to take on user defined class which must implement class to javax.faces event. Phase listener and implement all the methods of phase listener interface. àJavax. Faces. Event. Phase listener interface has the following methods

  1. Public void before phase(phase event pe)
  2. Public void after phase(phase event pe)
  • Public phaseId get phase ID()

2Where before phase() will be executed just before starting each and every phase 2Where after phase() will be executed just after completing each and every phase 2Where get phase Id() will return current  phase Id value. Eg: Public class myphaseListener implements phase listener   Step-2 - Configure phase listener implementation class in faces- config.xml The main intention to configure phase listener implementation class in faces- config.xml file is  to give an interaction to faces servlet which class is having implementation for phase listener interface, in order to execute at each and every phase 2To configure phase listener implementation class in faces- config.xml file, we have to use the following lode <faces-config> <life cycle> <phase- listener>fully qualified listeners</phase- listener> </life cycle> </life config> [for example application on event handling refer hand out provide on 21st nov 2013] Screenshot_24    

About Author
Authorlogo
Name

TekSlate

Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills .

Related Blogs

Write For Us