The JSF specification has its own set of rules specified in navigating the pages in JSF. They are such as which view has to be displayed or redirected based on the clicked button or the link on the previous web or JSF page. A set of navigation rules exist in order to redirect the pages and render the data content on to the web page of the device browser.
Resource Bundling mainly stores the UI date, label, status messages, and UI textual elements separately in the properties file and does not do any hardcoding in the page. It is one of the most convenient methods. Resource bundles are stored in .inproperties file extension because they are key-value pair of strings. This maintenance keeps the messages in a single place.
Managed Bean: It is a basic bean java class of JSF. This java bean is being managed by the JSF framework. It consists of getter and setter methods and business logic. Managed beans generally work for UI component as a model. It can be easily accessed from the JSF page. Backing Bean: It is a subpart of the managed bean. It contains all the properties of UI components in a JSF page.
This bean is used in UI conversion, component validations, and event handling. Almost all the features of UI components binds with a backing bean in JSF page.
The primary purpose of JSF is to make the construction process of the user interface simple. This UI is used for server-based applications, and the components can be reusable in a page. It connects the UI widgets with data sources. It provides the standard UI components and API (Application Programming Interface) majorly for developing components.
The Backing beans in JSF are the Java Beans which are used to implement the UI or front end logic in order to manage the data flow between the business tier and web server tier. Ideally, one backing bean does exist for each JSF page. In JSF 1.2 version, a managed bean should be registered in JSF configuration file facesconfig.xml in order to make it functional. From JSF 2.0 version onwards the same configuration can be avoided and Annotations can be used to apply this configuration.
The Value expression usually fetches a value or a set of values. These expressions can be categorized into rvalue and Ivalue expressions. The Ivalue expressions can read as well as write data whereas on the other hand rvalue expression can only read the data.
The method expression allows the users to involve a public method of the bean which returns the result that is important for validation of the data component and for handling the events.
Yes, it is possible with all popular frameworks. Typically, a JSF, Spring, Hibernate, etc. collaboration application configuration. not complicated, but because of the amount of code required, they will not be given here. See the documentation for the required framework.
Spring uses Inversion of Control (IoC) and Dependency Injection (DI), but JSF does not.
Spring consists of many different modules, such as Spring Data, Security, MVC, and many other perfectly interacting parts. This helps create larger applications at lower cost, while JSF is likely to require more coding for the many necessary functions.
Using DI in the spring allows you to embed POJO classes, while JSF can only work with JEE architecture.
You can opt out of the xml file when using annotations in the code.
JSF 1 need to forget :). Does not support Ajax, annotations, the use of templates and generally quite a curve in terms of stability.
Render kit defines a set of components and classes that are suitable for display to a specific user. For example, <f: view renderKitId = “PRIMEFACES_MOBILE” /> means using the mobile set of components of the Primefaces library.
There are various ways to implement localization in JSF, both by standard methods and using other frameworks (for example, Spring). The main meaning of localization in JSF is the absence of hardcoded component values, text data, etc. in the code. You must set a property and link it using the resource bundle file, which will store the set of values for each language (locale).
The use of the table component in JSF provides ample opportunities to work with collections or arrays and display their contents in a table. It supports iteration, provides data conversion capabilities in the required form, and much more.
You must configure at least two configuration files:
web.xml – the main web application configuration file. Contains deployment details, application configuration, and JSF handlers.
faces-config.xml – provides application settings, managed beans, navigation, converters, validators.
The selectOneMenu component allows you to select one of the list of values. A component may look like a list box, radio buttons, or a menu.
You can display any system errors using the <h: messages> tag , which can refer to a graphical component using the for attribute .
In general, at the moment there is an opinion that these concepts should not be distinguished (for example, spring does this). But if you need to somehow answer differently, then:
1. backing bean should be specified in request scoped . Backing bean is associated with a form.
2. Managed bean can be defined in request , session , application scopes. This type of bean is registered in the context of the JSF application and can be invoked or created at any time and place. Managed beans work with JSF graphics components.
JSF components are displayed on the xhtml page, which includes tag libraries like jsf core, html, facelets tags.
name : specifies the unique name of the class (bean) in JSF. If the name is not specified, the name is the same as the name of the class where the first letter is in lower case.
eager : indicates the creation time of the bean. If true, then a bin will be created at the start of the application, if false, the bin will be created upon the first request to it.
Using @ManagedProperty annotation, the bean can be injected into another bean property by using the bean’s setter method. We need a value attribute containing the bean name that is required to be injected.
Instant expressions are executed and calculated at the stage of rendering the display. Deferred expressions are executed by a direct call. For example, executing a method when clicking a button or getting a property value when building a fragment of a display (for example, when building a table, you need to get data values).
The class that is associated with the event that occurs is called the listener class. You can create such a class by implementing the interfaces PhaseListener , ActionListener or a method with an input parameter (ValueChangeEvent ev) .
The main component for working with tables is <h: dataTable>. Contains extensive display and interaction settings between the view and managed beans.
Tags for action and navigation commands include:
<h: commandButton> – generates an HTML button that confirms the form and thus allows you to start processing the data entered by the user.
<h: commandLink> – generates an HTML hyperlink equivalent to the HTML a
When there is a need to attach multiple listeners, a JSF tag for value change listeners and the action listeners are used to attach more than one listener to the element. When you make use of the tag syntax, you specify the class which implements the listener interface.
Web application archive (war) file of the JSF application contains the following:
>> web.xml – a web application descriptor configuration resource for web applications.
>> Essential classes in a set of JAR (Java Archive) files.
>> Application classes, Java Server Faces pages, other required resources like image files.
>> Resource files for application configuration.
Annotation in JSF helps in the development of clear and clean code. It can be used in packages, classes, constructors, interfaces, fields, methods, parameters, variables, or annotations themselves.
There are mainly three categories of annotation – viz. Markers, Single value annotation, Full annotations.
The validator tags are listed below:
f: validateLength is used to validate string length.
f: validateLongRange is used while validating the numeric value range.
f: validateDoubleRange is used while validating float value range.
f: validateRegex: validation compares given regular expression with JSF 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.
Expressions supported are listed below:
>> Immediate value expression
>> Deferred value expression
>> Value expression
>> Method expression
There are two types of validations in JSF namely, Declarative and Imperative.
>> Declarative validations are invoked using JSF standard validators or Bean validators.
>> Imperative validations are complex user-declared validators that override the standard validation as standard validation messages are not adequate in all cases.
Value expression retrieves a value and sets a value. They are further divided into rvalue expression and lvalue expression. rvalue can only read data, whereas lvalue can read as well write data.
Public method of the bean is invoked by Method expression that returns the result required for validating the data component and event handling.
Various text field tags are as described below:
<h: inputText> inserts text box adjacent to label field.
<h: inputTextArea> is used as a container for entering numerous characters.
<h: inputSecret> is a type of text field that is used for password field so that the entered data is not revealed.
JSF supports the following page navigation types:
>> Conditional navigation
>> Forward versus Redirect navigation
>> Implicit navigation
>> Navigation via managed bean
>> Navigation via Redirect navigation
The advantages are as follows:
>> Fast compile time
>> High-performance rendering
>> Extends its functionality to components and other server-side objects via >> customization
>> Support for code reuse through composite components and templating
>> Compile-time EL validation
Facelets are lightweight page declaration language which uses HTML style templates to build component tree to build Java server faces views.
Some of Facelets feature are listed as below:
>> It uses XHTML for creating web pages.
>> Besides JSF and JSTL tag libraries, it offers Facelets tag libraries.
>> Expression language support, component, and pages templating.
Managed Beans are a Java class that consists of a set of getter/setter methods and properties. It acts as a model to the JSF framework and offers functionalities like,
1. Component data validation
2. Manage the execution of a component event
3. Processing to decide what page application navigates next
4. JSF use managed beans either by configuring them into an XML file or through annotations.
Managed Beans are Java beans that comprise getter and setter methods and have business logic designed in it. It may optionally have a backing bean. They act as a Model for UI components in the MVC framework.
For JSF 1.2, it is required to register them in the JSF configuration file, faces-config.xml, whereas, from JSF 2.0 onwards, annotations are used to register managed beans.
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.
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
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.
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 <f:valueChangeListener> and for action listeners tag is <f:actionListener>.
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.
The typical JSF application consist of
>> JSF JavaBeans components for managing the application state and its behavior
Event driven development
>> Pages that represent MVC style views, pages reference view roots via the JSF component tree
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.
It is a Java framework based on MVC design that has rich API and tag libraries that offer the creation of server-side user interface components for web development.
JSF has a tag library, API, Facelets, and UI components and managed beans to create web applications.
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
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.
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.