Logo F2FInterview

JSF Interview Questions

Q   |   QA

We can have any number of config files. Just need to register in web.xml.
Assume that we want to use faces-config(1,2,and 3),to register more than one faces configuration file in JSF,just declare in the web.xml file

<context-param>
  <param-name>javax.faces.CONFIG_FILES</param-name>
  <param-value>
   /WEB-INF/faces-config1.xml,
   /WEB-INF/faces-config2.xml,
   /WEB-INF/faces-config3.xml
  </param-value>
</context-param>

Restore View : A request comes through the FacesServlet controller. The controller examines the request and extracts the view ID, which is determined by the name of the JSP page.

Apply request values: The purpose of the apply request values phase is for each component to retrieve its current state. The components must first be retrieved or created from the FacesContext object, followed by their values.

Process validations: In this phase, each component will have its values validated against the application’s validation rules. Update model values: In this phase JSF updates the actual values of the server-side model ,by updating the properties of your backing beans.

Invoke application: In this phase the JSF controller invokes the application to handle Form submissions.

Render response: In this phase JSF displays the view with all of its components in their current state.

The below diagram explains this better.

Life Cycle phases of JSF

JSF is an event driven framework.

Action Events: bound to UI Command objects like a Command Button or a Hyper-link. Whenever a user presses a Command Button or clicks a hyperlink these Events get generated.

Value Change Events: bound to UI Components like Text Field, Check-Box, List and Radio Buttons. The Value Change Event is fired as soon as the value that is displayed in the view is modified.

Phase Events: As you saw earlier in the JSF overview blog, the request processing life-cycle in JSF includes six phases and any JSF implementation will fire Phase events during the start and end of each phase. If we want to capture the Phase Events, then can define a Phase Listener. These are handy for debugging as well.

  • The main set back is having the business logic or data access logic in the getter methods.
  • Having too many rich components from third-party libraries like Richfaces, ICEFaces, etc could adversely impact performance due to bloated HTML pages.
  • Having too many backing beans in session scope could lead to memory and performance issues
  • Not coding in a thread-safe manner.
  • Not carefully designing the GUI and the relevant interactions

Action handlers and event listeners provide an event driven mechanism. Every time a user does something like clicking a button, selecting an item from a drop down, or submitting a form, an event occurs. Event notification is then sent via HTTP to the server and handled by the FacesServlet. Events can invoke custom business logic or initiate page navigation.

JSF provides two types of methods for handling events; listeners and action handlers, both of these may be defined within a managed bean. A listener takes an FacesEvent as a parameter and a void return type, while an action handler takes no parameters and returns a String.

In order to link this F2FInterview's page as Reference on your website or Blog, click on below text area and pres (CTRL-C) to copy the code in clipboard or right click then copy the following lines after that paste into your website or Blog.

Get Reference Link To This Page: (copy below code by (CTRL-C) and paste into your website or Blog)
HTML Rendering of above code: