Announcement Announcement Module
Collapse
No announcement yet.
Spring maanged bean JSF 2 how to do annotation validation Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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() {
    		System.out.println(cabinClassTO.toString());
    
    
    
    		FacesContext.getCurrentInstance().addMessage(null,
    				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 {
    
    		@NotNull
    		@Size(min=3, max=10, message="Error goes here")
    		private String name;
    		
    		@NotNull
    		@Size(min=3, max=10)
    		private String category;
    		
    		@AssertTrue
    		private boolean discontinued;
    
    		
    		
    		public String getName() {
    			return name;
    		}
    
    		public void setName(String name) {
    			this.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;
    		}
    
    		@Override
    		public String toString() {
    			return "CabinClassTO [name=" + name + ", category=" + category
    					+ ", discontinued=" + discontinued + "]";
    		}
    
    
    @Override
    	public boolean supports(Class<?> arg0) {
    		// TODO Auto-generated method stub
    		return false;
    	}
    
    	@Override
    	public void validate(Object arg0, Errors arg1) {
    		System.out.println("Spring validation");
    		
    	}
    
    
    
    @Override
    	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="http://www.w3.org/1999/xhtml"
    	xmlns:ui="http://java.sun.com/jsf/facelets"
    	xmlns:h="http://java.sun.com/jsf/html"
    	xmlns:f="http://java.sun.com/jsf/core"
    	xmlns:a4j="http://richfaces.org/a4j"
    	xmlns:rich="http://richfaces.org/rich"
    	xmlns:cat360="http://java.sun.com/jsf/composite/components">
    
    	<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="#{cabinClassSearchBean.cabinClassTO.name}" validatorMessage="Bad Class Name">
    
    		<f:validateLength minimum="3" maximum="8" required="true"/>
                        <rich:validator />
    					
    		</h:inputText>
    		
    		<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:select>
    		<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 />
    		</h:selectBooleanCheckbox>
    
    		<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>
    				</a4j:commandLink>
    			</h:panelGroup>
    			<h:outputText value=""/>
    		</h:panelGrid>
    		</rich:panel>
    	</h:form>	
    		
    </ui:composition>
Working...
X