Iteanz Interview Questions | Latest Technologies Interview Questions

JSF Interview Questions and Answers

Written by Bharathkumar | Sep 10, 2022 6:45:55 AM

Q1. What is JSF?
Java Server Faces (JSF) technology is a front end framework which makes the creation of user interface components easier by reusing the UI components. JSF is designed based on the Model View Controller pattern (MVC) which segregates the presentation, controller and the business logic.

Q2. What are JSF life cycle phases?
There are six lifecycle phases namely;

Restore view phase
Apply request values phase
Process validations phase
Update model values phase
Invoke application phase
Render response phase

Q3. List  some of the facelets tags?
Some of the important facelets tags are;

  • <ui:component> tag
  • <ui:composition> tag
  • <ui:decorate> tag
  • <ui:define> tag
  • <ui:fragment> tag
  • <ui:include> tag

Q4. What is the significance of @ManagedProperty annotation?
The @ManagedProperty annotation enables us to inject a managed bean into another managed bean.

Q5. What does @ApplicationScoped annotation indicate?
The @ApplicationScoped annotation indicates that the bean is valid as long as the web application is valid.

Q6.  Different types of Page Navigation supported in JSF?
The types of Page navigation supported in JSF are

  • Implicit Navigation
  • Navigation through Managed Bean
  • Navigation through faces-config.xml
  • Forward versus Redirect navigation
  • Conditional Navigation

Q7. What is a Managed Bean?
A managed bean is a java class registered to JSF which makes interaction between the UI and the business logic possible. Managed Beans can be created using @ManagedBean annotation.

Q8. What are the three types of text fields tags provided by JSF?
The three types of text field tags are;

  1. <h:inputText> – This adds the text box next to the label field.
  2. <h:inputSecret> – This type is used for password fields where the entered data is hidden.
  3. <h:inputTextarea> – This type of fields is used while entering large number of characters.

Q9. What are immediate and deferred value expressions?
Immediate expressions are evaluated and results are rendered as soon as the page is displayed initially. The syntax for immediate evaluation is ${}.

Deferred expressions are evaluated during the lifecycle phase whenever it is requested by the user. The syntax for deferred evaluation is #{expression}.

Q10. What is Resource bundling in JSF?
The phenomenon of storing the UI labels, date, status messages and other UI textual elements in a separate properties file instead of hardcoding these in a page is called resource bundling.
We can use h:outputLabel element to pick these values from resource bundle properties file in JSF view pages.

Q11. Explain the required and requiredMessage attribute of the <h:inputText> tag?
Required attribute indicates that the field is mandatory when set to true. The requiredMessage attribute allows users to specify their own message for the ui components when the fields are mandatory. They are used for declarative validations in JSF view pages.

Q12. Explain value expression and method expressions?
Value expressions usually fetch a value or set a value. These expressions can be further categorized into rvalue and lvalue expressions. lvalue expressions can both read and write data whereas rvalue expressions can only read data.
A method expression allows user to invoke a public method of the bean that returns the result necessary for validating the data component and handling events.

Q13. What are the different types of validations in JSF?
There are two types of validations namely;

  1. Declarative Validations: The validations that are fired using JSF standard validators or Bean validators fall under declarative type.
  2. Imperative validation: The standard validation messages would not be sufficient in all the cases and sometimes may require complex validations that are declared by the user overriding the standard validations and these are called Imperative validations.

Q14. What are different types of expressions supported by JSF EL?
JSF Expression Language supports following types of expressions.

  1. Immediate value expressions
  2. Deferred value expressions
  3. Value expression and method expression

Q15. What is an event?
An event is defined as a signal triggered based upon the user actions such as click of button, hyperlink, changing the input value etc. JSF tells the component to invoke the appropriate listener class that process the event generated by the user.

Q16. How can we obtain the generated event?
The generated event can be obtained by calling event.getComponent as
UIComponent ui = new UIComponent(); MyFacesEvent ev1 = new MyFacesEvent(ui); UIComponent sc1 = ev1.getComponent();

Q17. What are the different types of JSF events?
There are three types of JSF events namely

  1. Action Events: Action events are the events that are generated for the ui components like command button or command hyperlink.
  2. Value Change Events: Value change events refers to the UI components textfield, radio button, list box etc. The value change event will get fired as soon as the value is changed in the UI component.
  3. Phase Events: This type of event involves the events to be fired in one of the six phases of JSF lifecycle either during start or towards the end of each phase.

Q18. What is a listener class?
A class which is associated with an event is called a listener class. For example, if the event is a valueChange event then the corresponding listener class ValueChangeListener is associated with it.

Q19. What is the significance of facelets tag?
JSF provides a special set of tags that gives the flexibility to manage common tags/parts in one place for more than one application. These tags allow us to create a common layout that can be used across applications. You can include facelets tags using below code;
<html xmlns=“http://www.w3.org/1999/xhtml” xmlns:ui=“http://java.sun.com/jsf/facelets” >

Q20 . Explain @ViewScoped, @SessionScoped, @CustomScoped and @RequestScoped annotations?
@ViewScoped: annotation indicates that the bean is alive as long as the user interacts with the same JSF view page in the browser.
@SessionScoped: annotation indicates that the bean is valid as long as the HTTP session is alive.
@CustomScoped: annotation indicates that the bean lives as long as the bean’s entry in the custom Map which is created for this scope lives.
@RequestScoped: annotation indicates that the Bean lives as long as the HTTP request-response lives.

Q21. Mention some of the attributes of <h:form> tag?
The important h:form tag attributes are;

  • id: This is the unique identifier used to identify a component.
  • title: A title for an element of the form used as tooltip.
  • onclick: invokes the javascript function to be called when a button is clicked next to an element.
  • onsubmit: invokes javascript function to be called on click of form by a submit button.
  • onreset: Javascript to be invoked on the reset of the elements in a form.
  • ondblclick: Javascript code to be executed when the mouse is double clicked over a field in a form.
  • onmouseup: Javascript code to be executed when the mouse button is released over a component.
  • onmousedown: Javascript code to be executed when the mouse pointer is clicked down over this element.
  • binding: value of the expression linked to a property in a backing bean.
  • target: Name of the frame where the resource retrieved is to be displayed.
  • accept: the contents list that the form can handle.
  • acceptCharSet: defines the list of character encoding that the form will accept.
  • style: The CSS style definitions that can be applied for the form
  • prependId: flag that indicates whether id should be prepended to the form
  • dir: Overrides default text functionality for this component.

Q22. What are the command component tags used for action and navigation?
The command component tags for performing action and navigation are

  1. <h:commandButton> tag – The h:commandButton tag renders a button to submit a form thereby paving a way for processing the data entered by the user.
  2. <h:commandLink> tag – The commandLink provides an hyperlink equivalent to anchor tag in HTML that acts like a submit button and can be associated with the backing beans or action class for event handling.

Q23. What are Data Bound table components?
The components that are responsible for displaying the relational data in a tabular format are called data bound table components. The <h:dataTable> tag is used for displaying the data components. The <h:column> tag iterates over each record in the data source displayed in rows.
Some of the attributes of the h:dataTable tag are;

  • bgcolor: background color for the table that is displayed.
  • border: width in pixel to be drawn around the table.
  • cellpadding: Space between border of each cell and its contents.
  • cellspacing: Space between left side of the table and leftmost column and also amount of space between the cells.
  • columnClasses: List of css styles separated by comma to be applied to the columns of this table.
  • bodyrows: List of row indices separated by comma to be applied for the “tbody” element should be started.

Q24. Mention some of the validator tags used in JSF?f:validateLength: Validates length of a string

  • f:validateLongRange: Validates range of numeric value
  • f:validateDoubleRange: Validates range of float value
  • f:validateRegex: Validate JSF component with a given regular expression

Q25. What are the benefits of using JSF Framework?
Some of the benefits of using JSF framework are;

  • Clean separation between presentation and business logic.
  • Manages UI state across multiple server requests.
  • Implementation of custom components.
  • Easier flow of data between the components.
  • JSF specs that helps custom implementations such as PrimeFaces

Q26. Explain different ways of declaring a managed bean in JSF?

  1. Use @ManagedBean annotation in the java class indicating that the class is a managed bean as;
    @ManagedBean(name=“Greetings”, eager=“true”)If the name attribute is not specified the name is defaulted to the class name as java naming standards. For example class Car will be named “car” and CarDetails will be named “carDetails”.
  2. Declare the managed bean in faces-config.xml file as;
    <managed-bean> <managed-bean-name>Greetings</managed-bean-name> <managed-bean-class>com.Greetings.Greetings</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean>

Q27. What is the significance of name and eager attributes in managed bean?
name: The name attribute indicates the managed bean with the name specified. If the name is not specified then the bean name is same as the class name.
eager: If eager is set to “true” then managed bean is created before it is requested for the first time and if set to false the bean is created when it is requested.

Q28. What is a backing bean?
A JavaServer Faces application includes one or more backing beans, each of which is a type of managed bean that can be associated with the components used in a particular page.

Q29. List the benefits of Expression Language?

  • Arithmetic, logical, relational operations can be used in expression language.
  • Automatic type conversion.
  • Shows missing values as empty strings instead of NullPointerException.
  • Provides easy access to predefined objects such as request.

Q30. What are different implementations of JSF API?

  • ADF Faces: Oracle’s implementation for the JSF standard.
  • Reference Implementation (RI): by Sun Microsystems.
  • Apache MyFaces: open source JavaServer Faces (JSF) implementation.
  • Primefaces: JSF components with Ajax framework.

Q31. Mention some of the functions that the backing bean method performs?

  • Validating a component’s data
  • Handling an event fired by a component
  • Performs processing to determine the next page to which the application must navigate

Q32. What are standard JSF tag libraries?

  • JSF Core Tags library
  • JSF HTML tags library

Use below namespace configurations to use them in JSF xhtml pages.

<html xmlns=“http://www.w3.org/1999/xhtml” xmlns:h=“http://java.sun.com/jsf/html” xmlns:ui=“http://java.sun.com/jsf/facelets” xmlns:c=“http://java.sun.com/jsf/core”>
The html tags can now be used as with the h prefix as <h:head>,<h:form> etc and core tags with c prefix as <c:validateBean>,<c:validator> etc.

Q33. What are different JSF Converter tags?

  • f:convertNumber: tag is used to convert a string value to a number of required format.
  • f:convertDateTime: tag is used to convert a string value to a date of required format.
  • CustomConverter: allows user to define their own convertor in JSF.

Q34. How different components are rendered in JSF page?
JSF components are rendered in the xhtml pages by the tag libraries included, such as JSF core, html and facelets tag libraries.