Announcement Announcement Module
No announcement yet.
Spring maanged bean JSF 2 how to do annotation validation Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring maanged bean JSF 2 how to do annotation validation

    I am using richfaces 4 JSF with spring integeration

    When i click on save button "saveCabinClass" method gets call and display error messages and client side validation also working.

    But bean level annotation and implemented interfaces validation not working at all, as you can see i implemented both interfaces to check if any one getting call but none of them getting call !!

    When i press enter on any field form don't get submit only when i click upon save button method gets call. and incase if it input value is null client side validation not getting call as well.

    I am so confuse whats going on around with spring jsf richfaces combination

    please help following is my code

    HTML Code:
    @Component(value = "cabinClassSearchBean")
    @Scope(value = "request")
    public class CabinClassSearchBean implements Serializable, javax.faces.validator.Validator, org.springframework.validation.Validator{
    public void saveCabinClass() {
    				new FacesMessage(FacesMessage.SEVERITY_INFO, "Succesfully changed!", "Succesfully changed!"));
    		FacesContext.getCurrentInstance().addMessage("create_cabin_class_detail_form:cabin_name", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error in name", "Error in name deatil"));
    		FacesContext.getCurrentInstance().addMessage("create_cabin_class_detail_form:cabin_class_discontinue", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error in name", "Error in name deatil"));
    		FacesContext.getCurrentInstance().addMessage("create_cabin_class_detail_form:cabin_class_category", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error in name", "Error in name deatil"));
    public class CabinClassTO {
    		@Size(min=3, max=10, message="Error goes here")
    		private String name;
    		@Size(min=3, max=10)
    		private String category;
    		private boolean discontinued;
    		public String getName() {
    			return name;
    		public void setName(String name) { = name;
    		public String getCategory() {
    			return category;
    		public void setCategory(String category) {
    			this.category = category;
    		public boolean isDiscontinued() {
    			return discontinued;
    		public void setDiscontinued(boolean discontinued) {
    			this.discontinued = discontinued;
    		public String toString() {
    			return "CabinClassTO [name=" + name + ", category=" + category
    					+ ", discontinued=" + discontinued + "]";
    	public boolean supports(Class<?> arg0) {
    		// TODO Auto-generated method stub
    		return false;
    	public void validate(Object arg0, Errors arg1) {
    		System.out.println("Spring validation");
    	public void validate(FacesContext ctx, UIComponent toValidate, Object value)
    			throws ValidatorException {
    		System.out.println("JSF Faces validation");

    Following is my xhtml code to display validation

    HTML Code:
    <ui:composition xmlns=""
    	<h:form id="create_cabin_class_detail_form" method="POST">
    		<rich:panel styleClass="myTableUtility">
                    <rich:messages globalOnly="true"/>
    		<h:panelGrid border="0" cellspacing="5" columns="4"  cellpadding="5" styleClass="myTableUtility">
    		<h:outputText value="Name" />
    		<h:outputText value=":" styleClass="colon-cell" /> 
    		<h:inputText id="cabin_name" value="#{}" validatorMessage="Bad Class Name">
    		<f:validateLength minimum="3" maximum="8" required="true"/>
                        <rich:validator />
    		<rich:message for="cabin_name" ajaxRendered="true"/>
    		<h:outputText value="Category" styleClass="myTableUtility"/>
    		<h:outputText value=":" styleClass="colon-cell" />
    		<rich:select id="cabin_class_category" value="#{cabinClassSearchBean.cabinClassTO.category}">
    		<f:selectItem itemLabel="category-1" itemValue="cat-1"/>
    		<f:selectItem itemLabel="category-2" itemValue="cat-2"/>
    		<f:selectItem itemLabel="category-3" itemValue="cat-3"/>
    		 <rich:validator />
    		<rich:message for="cabin_class_category" ajaxRendered="true"/> 
    		<h:outputLabel value="Discontinued?" styleClass="label-cell" />
    		<h:outputText value=":" styleClass="colon-cell" />
    		<h:selectBooleanCheckbox value="#{cabinClassSearchBean.cabinClassTO.discontinued}" id="cabin_class_discontinue">
    		<rich:validator />
    		<rich:message for="cabin_class_discontinue" ajaxRendered="true"/>
    		<h:outputText value=""/>
    		<h:outputText value=""/>
    		<h:panelGroup border="1" style="text-align:right;">
    				<a4j:commandLink styleClass="button" action="#{cabinClassSearchBean.saveCabinClass}">
    					<span> Save </span>
    			<h:outputText value=""/>