How to implement the encoding and decoding data ?
ANS: JSF provide the two way implement of these
direct implementation
delegated implementation
direct implement the component itself implement encoding and decoding
delegated implementation the component delegate to the renderer that does the encoding and decoding .this is not render specific.
JSF component consist of the two thinks
1-Component
2-Renderer
1-Component class used to define state and behavior of a UI component .
2-Renderer define how the component will be read form the request and how it will be displayed usually though HTML .
Wednesday, October 13, 2010
The jsf component model :
The jsf component model :
It have some type of properties and events just like the swing .jsf also have the containers that contains components and that also are components that can be contained by other containers .
component functionality typically combination of two part
1-decoding
2-encoding
Decoding is the process of converting incoming request parameters to the values of the components and encoding is the process in which convert the current value of components into corresponding markup language that is html.
component functionality typically combination of two part
1-decoding
2-encoding
Decoding is the process of converting incoming request parameters to the values of the components and encoding is the process in which convert the current value of components into corresponding markup language that is html.
Jsf Validation
Jsf Validation:
In jsf the validation is divided in to four part
1-built in validation components
2-application-level validation
3-custom validation components(this is achieve using the Validate interface )
4-validation method in backing beans (inline)
1-Build in validation also called Standard validation
1-DoubleRangeValidator
1)value should be numeric
2)range should be between minimum and maximum values
Example:
<h:inputText id="user3" >
<f:validateDoubleRange minimum="2" maximum="100"></f:validateDoubleRange>
<h:message for="user3"></h:message>
</h:inputText>
Error Message:Validation Error: Specified attribute is not between the expected values of 2 and 100.
2-LongRangeValidator:
1)valve(Local Value) must be numeric and belong to range of long
2)must be in range specified by minimum and maximum values
Example:
<h:inputText id="user2" >
<f:validateLongRange minimum="2" maximum="100"></f:validateLongRange>
<h:message for="user2"></h:message>
</h:inputText>
Error Message: Validation Error: Specified attribute is not between the expected values of 2 and 100.
3-LenghtValidator:
1)type must be in range specified by minimum and maximum value
Example:
<h:inputText value="#{userName.userclassvalue}" id="user1" >
<f:validateLength maximum="4" minimum="2"> </f:validateLength>
<h:message for="user1"></h:message>
</h:inputText>
ErrorMessage:Validation Error: Value is less than allowable minimum of '2'
It also validate the type of data you insert .
DoubleRangeValidator is require the Numeric value
LongRangeValidator is require the numeric but should be between the long rang
LenghtValidator :this apply to check the length of string type
Application level validation :Application level validation Is business level validation .validation shift from form level to the bean level (backing bean level ).if you want to check the credit card limit then on command button you need to add the action method ,and in this action method you check the value of the filed one the basic of the business requirement .
Example : in this example ,first I just create a method in my backing bean class and in this bean I am going to perform the validation logic . I just check the value of the input field. if it is null then show the errors message on the same pages .
Method code :
public String actionsubmit(){
FacesContext faces=FacesContext.getCurrentInstance();
Application app= faces.getApplication();
String inputvalue=(String) app.createValueBinding("#{ForValidation.name}").getValue(faces);
FacesMessage message=new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setSummary("the field is blank which should not be");
message.setDetail("the field is blank which should not be");
if(a.equals("")){
faces.addMessage("val:field", message );
return somepage;
}
return otherpage;
}
Jsp code :
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
doctype-system="http://www.w3.org/TR/html4/loose.dtd"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>untitled4</title>
</head>
<body>
<h:form id="val">
<h:inputText value="#{ForValidation.name}" id="field">
</h:inputText>
<h:messages></h:messages>
<h:commandButton value="submit" action="#{ForValidation.actionsubmit}" ></h:commandButton>
</h:form>
</body>
</html>
</f:view>
</jsp:root>
Pros and cons of application level validation
Pros –
1-very easy to used
2-no need to be specified any tag on jsp pages
3-also no need to separate class for writing the code .
Cons –
1-called after the custom validation
2-not suitable for large application
In jsf the validation is divided in to four part
1-built in validation components
2-application-level validation
3-custom validation components(this is achieve using the Validate interface )
4-validation method in backing beans (inline)
1-Build in validation also called Standard validation
1-DoubleRangeValidator
1)value should be numeric
2)range should be between minimum and maximum values
Example:
<h:inputText id="user3" >
<f:validateDoubleRange minimum="2" maximum="100"></f:validateDoubleRange>
<h:message for="user3"></h:message>
</h:inputText>
Error Message:Validation Error: Specified attribute is not between the expected values of 2 and 100.
2-LongRangeValidator:
1)valve(Local Value) must be numeric and belong to range of long
2)must be in range specified by minimum and maximum values
Example:
<h:inputText id="user2" >
<f:validateLongRange minimum="2" maximum="100"></f:validateLongRange>
<h:message for="user2"></h:message>
</h:inputText>
Error Message: Validation Error: Specified attribute is not between the expected values of 2 and 100.
3-LenghtValidator:
1)type must be in range specified by minimum and maximum value
Example:
<h:inputText value="#{userName.userclassvalue}" id="user1" >
<f:validateLength maximum="4" minimum="2"> </f:validateLength>
<h:message for="user1"></h:message>
</h:inputText>
ErrorMessage:Validation Error: Value is less than allowable minimum of '2'
It also validate the type of data you insert .
DoubleRangeValidator is require the Numeric value
LongRangeValidator is require the numeric but should be between the long rang
LenghtValidator :this apply to check the length of string type
Application level validation :Application level validation Is business level validation .validation shift from form level to the bean level (backing bean level ).if you want to check the credit card limit then on command button you need to add the action method ,and in this action method you check the value of the filed one the basic of the business requirement .
Example : in this example ,first I just create a method in my backing bean class and in this bean I am going to perform the validation logic . I just check the value of the input field. if it is null then show the errors message on the same pages .
Method code :
public String actionsubmit(){
FacesContext faces=FacesContext.getCurrentInstance();
Application app= faces.getApplication();
String inputvalue=(String) app.createValueBinding("#{ForValidation.name}").getValue(faces);
FacesMessage message=new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setSummary("the field is blank which should not be");
message.setDetail("the field is blank which should not be");
if(a.equals("")){
faces.addMessage("val:field", message );
return somepage;
}
return otherpage;
}
Jsp code :
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">
<jsp:output omit-xml-declaration="true" doctype-root-element="HTML"
doctype-system="http://www.w3.org/TR/html4/loose.dtd"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN"/>
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>untitled4</title>
</head>
<body>
<h:form id="val">
<h:inputText value="#{ForValidation.name}" id="field">
</h:inputText>
<h:messages></h:messages>
<h:commandButton value="submit" action="#{ForValidation.actionsubmit}" ></h:commandButton>
</h:form>
</body>
</html>
</f:view>
</jsp:root>
Pros and cons of application level validation
Pros –
1-very easy to used
2-no need to be specified any tag on jsp pages
3-also no need to separate class for writing the code .
Cons –
1-called after the custom validation
2-not suitable for large application
Subscribe to:
Posts (Atom)