ui: component
defines the created component and adds to the component tree.ui: composition
defines page composition, uses templates optionally, and ignores content outside.ui: debug
defines debug component created and adds to the component tree.ui: decorate
is similar to component tag, consider content outside this tag.ui: define
is used to define content inserted into the page by a template.ui: fragment
is similar to component and decorates tag. It considers content outside this tag.ui: include
reuses and encapsulates multiple page content.ui: insert
as name inserts contents into a template.ui: param
pass parameters to the included file.ui: repeat
an alternative for loop tags, like c: forEach
or c: dataTable
.ui: remove
is used to remove content from a page.<h:inputText>
: This adds the text box next to the label field.<h:inputSecret>
: This type is used for password fields where the entered data is hidden.<h:inputTextarea>
: This type of fields is used while entering large number of characters.@ManagedProperty
annotation allows you to inject one managed bin into another.@ManagedProperty(value = “#{beanName}”)
private BeanName beanName;
@ApplicationScoped
annotation indicates that the managed bean will be available throughout the lifetime of the application. 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.h:inputText
: Creates HTML text box of text typeh:inputSecret
: HTML text box of password typeh:inputTextarea
: HTML textarea input fieldh:inputHidden
: HTML input of type hiddenh:selectBooleanCheckbox
: For single HTML check boxh:selectManyCheckbox
: For group of HTML check boxesh:selectOneRadio
: For single HTML radio buttonh:selectOneListBox
: For HTML single list box<h: inputText>
tag is used to render an input field on the web page.<h: form>
tag to declare input field that allows the user to input data.<h:outputText>
is used to render a plain text. styleClass
", "style
", "dir
" or "lang
" attributes are present, render a "span
" element. styleClass
" attribute is present, render its value as the value of the "class
" attribute. <h:form>
tag represents an input form. <h:commandButton>
tag creates a submit button and used to submit an application form. <h:inputTextarea>
tag renders an HTML "textarea
" element. a
" anchor element that acts as a form submit button when clicked. So, you can create an anchor tag by using this tag. <h:commandLink>
tag must include a nested h:outputText tag, which represents the text that the user clicks to generate the event. It's also required to be placed inside a <h:form>
tag. <h:inputSecret value="#{user.password}" maxlength="15" size="14"
required="true" requiredMessage="Password is required"></h:inputSecret>​
input
" element of type hidden. It does not appear on the web page, so you can pass hidden information while submitting the form.<h:inputHidden value="#{user.id}" id="userId" class="userId-class"></h:inputHidden>
<h:inputFile id="file-id" value="#{user.fileName}" required="true"
requiredMessage="Please upload a file" alt="upload file"></h:inputFile>
img
" tag. This tag is used to render an image on the web page.<h:graphicImage id="image-id" name="user-image" url="#{user.fileLocation()}"
height="50px" width="100px" alt="Image"></h:graphicImage>
<h:message>
<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 anchor tag. It can be associated with a managed bean or an Action class for handling events.<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="https://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://xmlns.jcp.org/xml/ns/javaee
https://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>
@ViewScoped
: means that a managed bean exists over the lifetime of the JSF
view (while the page is being shown).@SessionScoped
: The bean will be available throughout the HTTP
session.@CustomScoped
: the bin will live for as long as it is in the Map, which is created to control the lifetime of the beans.@RequestScoped
: The bean exists for the life of the request-response (HTTP
request-response).
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.JSF
validators to shoot out the built in error messages to the users.h:message
tag is used to display all the error messages related to the UI
components.h:message
has the following attributesid
attribute is the unique identifier for a ui component.style
displays the style information like color,font etcfor
attribute describes the component name applicable for the form.error.xhtml
as error.xhtml
<h:message for="cname" style="color: red"></h:message>
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.rendered attribute indicates
whether a component should be rendered or not in the view page. Rendered attribute can use arithmetic operators and literals with rvalue expression but not lvalue expressions.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.Login-Logout
available for ready integration whereas in JSF we have to write the login feature manually.Java EE architecture
.PostConstructApplicationEvent
, PreDestroyApplicationEvent
, PreRenderViewEvent
.public String logout() {
FacesContext fc = FacesContext.getCurrentInstance();
HttpSession session = (HttpSession) fc.getExternalContext().getSession(false);
session.invalidate();
return "loginPage";
}
META-INF/resources
directory within a web application : META-INF/resources/resource-identifier
. You can use this file structure to package resources in a JAR file bundled in the web application.