Events in JSF Life Cycle, Value Change Events


Events in JSF Life Cycle
  • Web applications often need to respond to user events, such as selecting items from a menu or clicking a button. 
  • Exa. you might want to respond to the selection of a country in an address form by changing the locale and reloading the current page to better accommodate your users.
  • Typically, you register event handlers with components.
  • JSF supports four kinds of events:
    • Value change events
      • fired by editable value holders—such as h:inputText, h:selectOneRadio, and h:selectManyMenu
    • Action events
      • fired by action sources—for example, h:commandButton and h:commandLink
    • Phase events
      • fired by the JSF life cycle
    • System events (since JSF 2.0)
  • NOTE: Keep in mind that all JSF events are executed on the server. 
  • Event listeners can affect the JSF life cycle in one of three ways:
    • Let the life cycle proceed normally.
    • Call the renderResponse method of the FacesContext class to skip the rest of the life cycle up to Render Response.
    • Call the responseComplete method of the FacesContext class to skip the rest of the life cycle entirely.
Value Change Events
  • Components in a web application often depend on each other. 
  • Exa. the value of the “State” prompt depends on the “Country” menu’s value.
  • Two Ways
    • 1. Method binding – In input component, specified a bean’s method directly in the “valueChangeListener” attribute.
      • In JSF
      • In JAVA
    • 2. ValueChangeListener interface – In input component, add a “f:valueChangeListener” tag inside, and specified an implementation class of ValueChangeListener interface.
      • In JSF
      • In JAVA
Action Events:
  • Action events are fired by buttons and links.
  • When you activate a button or link, the surrounding form is submitted and the JSF implementation subsequently fires action events.
  • action listeners vs. actions:
    • actions are designed for business logic and participate in navigation handling,
    • action listeners typically perform user interface logic and do not participate in navigation handling.
  • Two Ways
    • 1. Method binding 
      • In JSF
    • 2. ActionListener interface – 
      • In JSF

Thanks a lot for query or your valuable suggestions related to the topic.

Previous Post Next Post

Contact Form