JSF <f:validateRequired> Tag

It is used to ensure that the local value is not empty on an EditableValueHolder component.

# Tag Attributes

Attribute Description
binding It is used to bind a ValueExpression that evaluates to an instance of RequiredValidator.
for This attribute is used to refers to the value of one of the exposed attached objects within the composite component inside of which this tag is nested.
id It is a unique component identifier.
class It is used to represent CSS class.

# JSF <f:validateRequired> Tag Example

// index.xhtml


<h:form id="form">
<h:outputLabel for="username">User Name</h:outputLabel>
<h:inputText id="name-id" value="#{user.name}" validatorMessage="User name is required">
<f:validateRequired />
</h:inputText><br/>
<h:commandButton value="OK" action="response.xhtml"></h:commandButton>
</h:form>

// User.java


import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class User{
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}

JSF F valirequired tag 1