JSF Interview Questions
Explain the different types of JSF events?
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.
Can you explain some of the setback of JSF?
- 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
Explain the way by which the events handled in JSF? What is the difference between these event handling mechanisms?
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.
Explain about viewstate in JSF?
In JSF, there is a viewstate associated with each page, which is passed back and forth with each submits. The reason for the viewtate is that the HTTP is a stateless protocol. The state of the components across requests need to be maintained. The viewstate can change in between requests as new controls like UIInput can be added or modified.
Explain some of the differences between struts and JSF?
The main advantages of JSF over Struts are :
Eliminated the need for a Form Bean
Eliminated the need for a DTO Class
Allows the use of the same POJO on all Tiers because of the Backing Bean
As Struts is a web application framework, it has a more sophisticated controller architecture than does JavaServer Faces technology. It is more sophisticated partly because the application developer can access the controller by creating an Action object that can integrate with the controller, whereas JavaServer Faces technology does not allow access to the controller. In addition, the Struts controller can do things like access control on each Action based on user roles. This functionality is not provided by JavaServer Faces technology.
Explain the way by which we can declare the page navigation (navigation rules) in faces-config.xml file ?
Navigation rules tells JSF implementation which page to send back to the browser after a form has been submitted. We can declare the page navigation as follows:
This declaration states that the login action navigates to /welcome.jsp, if it occurred inside /index.jsp.
What happens if no navigation rule matches a given action?
If no navigation rule matches a given action, then the current page is again displayed.