1) Explain what is JSF or Java Server Faces?
Java Server Faces or JSF : It is a java based web application framework to make the user interface simple for JEE applications. Instead of traditional request-driven MVC framework it uses component based approach.
2) Explain what is the JSF architecture?
JSF is designed on the MVC (Model-View-Controller) framework and this allows for applications to be scaled better. A JSF application is same like other Java technology-based web application, it runs in a JAVA servlet container and it contains
- JavaBeans components as models consisting data and application-based functionality
- Custom tag library for representing validators and event handlers
- Custom tag library for rendering UI components
- UI components signified as stateful objects on the server
- Server-side helper classes
- Event handlers, validators and navigation handlers
- Application configuration resource file for organizing and configuring application resources
3) Explain the life cycle of JSF?
Life cycle of JSF includes
Restore view phase: During this phase binding of components to its event handlers and validators are executed and view is saved in the FacesContext object
Apply request values phase: The motive of this phase is to retrieve its current date for each component
Process validation phase: During this phase, local values saved for the component in the tree are compared to the components validation rules registered
Update model value phase: After verifying, that data is genuine or valid in the previous phase, local values of components can be set to related server side object properties
Invoke application phase: Prior to this phase the component values have been transformed, validated and applied to the bean objects, so that you can avail them to run the application’s business logic
Render response phase: JSP container renders the page back to the user in this phase
4) List out the available implementations of JavaServer faces?
When it comes to JSF there are Reference Implementation (RI) by Sun Microsytems; Apache MyFaces is an open source JavaServer Faces (JSF) implementation and for Oracle there is ADF Faces.
5) Mention what does a typical JSF application consist of?
The typical JSF application consist of
JSF JavaBeans components for managing the application state and its behavior
Event driven development
LogoJSF
6) Explain how JSF is different from conventional JSP?
JSP-
- JSP is a Java based technology used in order to help developers to create dynamic web pages
- JSP must be compiled in JAVA byte-code in respect to function properly
- JSP does not support validator and conversion, ajax etc.
- JSP is not an interface within the view template. However, JSP are compiled within the server
- JSP is not managed or processed by the faces servlet. Instead, JSP are Java Servlets by themselves
JSF-
- JSF is a web application used to simplify development integration of web based user interfaces
- JSF contains multiple core features like managed beans, component system etc. that is based on template, and tag libraries
- JSF supports validator and conversion, ajax etc.Within a view template JSF is an interface
- JSF is processed by Faces Servlet
7) Explain what is rendering of page in JSF?
A JSF page has components which are made with the help of JSF library. The JSF components like h:form, h:inputText, h:commandButton etc. are rendered or translated to HTML output. This process is referred as encoding. Encoding assigns a unique id to a component by the framework and the ids are produced at random.
8) Mention what does JSF-Managed Bean?
Managed bean in JSF act as a Model for UI component, it can be accessed from JSF page. The managed bean consists of the “getter” and “setter” techniques, business logic or even a backing bean.
9) Explain what Ajax is and how JSF is useful for making AJAX call?
Ajax is a method to use HTTPXMLObject of JavaScript to direct data to server and receive data from server simultaneously. Using Ajax, javascript code exchanges data with server, updates parts of webpages without reloading the whole page. For making Ajax call JSF provides full support. It provides f:ajax tag to handle ajax calls.
10) Mention what is the difference between JSF and Struts?
JSF
- JSF is a specification
- JSF action methods can be applied in Java objects
- JSF has event model which reacts on actions, value changes and phase changes in JSF lifecycle
- JSF component tag does not produce HTML-instead they declare a component renderer pair on the server
- By mentioning a navigation rule in the faces configuration file, JSF supports navigation
- JSF uses dependencies injection
- Struts
- Struts is an open source framework
- Struts actions are restricted to struts API only
- There are no such event models in struts
- Struts tag generates HTML directly
- To define navigation struts uses the notation
- There is no dependencies injection in struts
11) Explain how you can call multiple listeners in JSF?
To call multiple listeners in JSF, there is a JSF tag for “value change listeners” and one for “action listeners” that can be availed to link one or more than one listeners to an element. While using the tag syntax, you will be declaring a class that implements a listener interface. For value change listener tag is and for action listeners tag is .
12) What are converter tags in JSF?
JSF has inbuilt convertors to convert or change its UI components data to object used in a managed bean and vice versa. These tags can convert text into date object and can validate the format of the input as well.
13) List out the converter tags used in JSF?
Converter tags used in JSF are
convertNumber: It converts a string into a number of desired format
convertDateTime: It converts a string into a date of desired format
Custom Converter: It creates a custom converter
14) Explain what are facelets JSF tags?
Facelets JSF tags are special tags to create common layout for a web application referred as facelet tags. To manage common parts of a multiple pages at one place, facelets tags are used.
12) What are converter tags in JSF?
JSF has inbuilt convertors
13) List out the converter tags used in JSF?
Converter tags used in JSF are
convertNumber: It converts a string into a number of desired format
convertDateTime: It converts a string into a date of desired format
Custom Converter: It creates a custom converter
14) Explain what are facelets JSF tags?
Facelets JSF tags are special tags to create common layout for a web application referred as facelet tags. To manage common parts of a multiple pages at one place, facelets tags are used.
15) What are the different types of JSF events?
There are three types of JSF events namely
ü Action Events: Action events are the events that are generated for the ui components like command button or command hyperlink.
ü 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.
ü 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.
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.
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"
>
18) What are 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
18) What are the different types of validations in JSF?
There are two types of validations namely;
Declarative Validations: The validations that are fired using JSF standard validators or Bean validators fall under declarative type.
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.
JSF Expression Language supports following types of expressions.
0. Immediate value expressions
1. Deferred value expressions
2. Value expression and method expression
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}.
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.
@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.
@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.
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”.
Declare the managed bean in faces-config.xml file as;
0. <managed-bean>
1. <managed-bean-name>Greetings</managed-bean-name>
2. <managed-bean-class>com.Greetings.Greetings</managed-bean-class>
3. <managed-bean-scope>request</managed-bean-scope>
4. </managed-bean>
24) 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.
· 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
26) 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
· 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.
· 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.
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.
ü 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.
· 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
· 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.
JSF is developed based on the Model View Controller(MVC) pattern. The Model VIew Controller separates the business logic from presentation.
The JSF application contains
· UI components represented as stateful objects on the server
· Server-side helper classes
· Validators, event handlers, and navigation handlers
· Application configuration resource file for configuring application resources
· A custom tag library for representing event handlers and validators
· A custom tag library for rendering UI components
Below image shows the JSF applications architecture diagram.
Yes, any number of faces configuration files can be used but should be declared in the web.xml file as shown below.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
<context-param>
<param-name>javax.faces.CONFIG_FILES</param-name>
<param-value>/WEB-INF/faces-config1.xml,/WEB-INF/faces-config2.xml</param-value>
</context-param>
</web-app>
36) What are the differences between a Backing Bean and Managed Bean?
Backing Beans should be defined in request scope whereas managed bean can be defined in request,session or application scopes.Backing bean is referenced by a form whereas a managed bean is registered with JSF and created automatically when needed.
The h:messages tag shows all the error messages at one place corresponding to UI elements. The “for” attribute can be used to represent the field for which error message has to be displayed.
38) What is the significance of selectOne menu tag in JSF?
The selectOne enables users to select a single value from the list of values. This component can be rendered as a list box, a set of radio buttons or a menu.
The immediate attribute if set to true can force validations, events and conversions processed during request phase of the lifecycle. Command component’s immediate attribute indicates what happens when the component gets activated. If the button’s immediate attribute is set to true and associated text field’s immediate attribute set to false then the event is processed without applying the field’s value to the model. In other words the value entered in the field does not even reach the model when the button is clicked but immediately processed in the above scenario.
ü Binding the component’s value to a bean property or other external data source
ü Binding the component’s instance to a bean property
There are two configuration files namely;
web.xml: This is the general web application configuration file containing the details of deployment. This contains the faces config file responsible for handling the application.
faces-config.xml: allows to configure the application, managed beans, converters, validators, and navigation.
The rules provided by JSF Framework to describe the view to be shown when a button or link is clicked is called a navigation rule.
The convertor tags convert the UI component’s data to object used in a managed bean and vice versa. For example, these tags can convert a text into date object and can validate the format of input as well.
· DataTable can iterate over collection or array of values to display data.
· DataTable provides attributes to modify its data in easy way
46) How to implement internationalization (i18n) in JSF?
Internationalization is a mechanism in which status messages, GUI component labels, currency, date are stored outside the source code in resource bundles and retrieved dynamically rather than hard coding in the program based on the user locale.
The JavaServer Faces component architecture is designed such that the functionality of the components is defined by the component classes, whereas the actualities of the rendering itself can be defined by a separate renderer called as component rendering model.
A render kit defines how component classes map to component tags that are appropriate for a particular client.
A view object is a model object used specifically in the presentation tier but defined outside it. It contains the data that must be displayed in the view layer and the logic to validate user input, handle events, and interact with the business-logic tier.
Bean scope is the mechanism of binding the beans and other objects to be available in the different components of a web application.
· JSF1 does not support the usage of annotations but JSF2 supports annotations that make it far better than JSF1.
· JSF1 Ajax support was limited, however JSF2 support all the ajax features.
· JSF1 does not provide Template concepts whereas JSF2 does.
· JSF1 was first released and API was having a lot of bugs, JSF2 is totally redesigned and can be used as MVC framework in larger applications.
No comments:
Post a Comment