Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
Hey Ninjas!!
While working on a piece of code, the most encountered error is a validation error. Then how to check whether the string we enter is in the specified range or not. For this, in JSF, there is the f:validateLength tag which verifies whether the string is the specific given range or not.
So let's begin our journey to explore more about this topic.
First, let's have a look at what JSF is.
JSF
The Java standard technology for creating component-based, event-oriented web interfaces is called JavaServer Faces (JSF). JSF permits server-side data and functionality access, just like JavaServer Pages (JSP). JSF is an XML document representing formal components in a logical tree, unlike JSP, which is just an HTML page with server-side capabilities. JSF components are supported by Java objects, separate from HTML, and possess all of Java's features, including the ability to access distant APIs and databases
Now let's have a look at the JSF f: validateLength
JSF f: validateLength
f:validateLength tag is used to verify the length of a string value inside a specific range.
Syntax
<f:validateLength minimum="a" maximum="b" />
Tag Attribute Used
1. Minimum: It specifies the component's minimum length.
2.Maximum: It is used to specify the component's maximum length.
Sample Code
Data.java
package com. coding.ninjas;
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
@ManagedBean(name = "Data", eager = true)
@SessionScoped
public class UserData implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
index.xhtml
<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml"
xmlns:h = "http://java.sun.com/jsf/html"
xmlns:f = "http://java.sun.com/jsf/core">
<h:head>
<title>localhost:8080l</title>
</h:head>
<h:body>
<h2>h:validateLength Example</h2>
<h:form>
<h:inputText id = "nameInput" value = "#{Data.name}"
label = "name" >
<f:validateLength minimum = "5" maximum = "9" />
</h:inputText>
<h:commandButton value = "submit" action = "result"/>
<h:message for = "nameInput" style = "color:red" />
</h:form>
</h:body>
</html>
HTML tags function similarly to keywords in that they specify how a web browser will format and present text. A web browser can distinguish between HTML material and plain content with the use of tags.
What are controllers in JSF Application?
"FacesServlet" is the central controller for the JSF application.
What is servlet?
A Java programming language class known as a servlet is used to increase the functionality of servers that host applications that are accessed via the request-response programming model.
What are APIs?
API stands for Application Programming Interface , is a software bridge that enables communication between two applications.
What is XHTML?
EXtensible HyperText Markup Language (XHTML).To make HTML more adaptable and extendable so that it could interact with other data types, XHTML was created (such as XML).
Conclusion
Finally, you've concluded this article.
Congratulations!! You learned about JSF - f: validateLengthin this blog. You studied the tag and how it helps in validating the string length, attribute used, and a sample program.
After reading these interview questions, are you eager to read more articles on the subject of JSF? Don't worry; Coding Ninjas will take care of everything. Check out the awesome content on the Coding Ninjas Website