Validation Issue with RF3.30
tuxbox May 2, 2009 11:14 AMHi!
First of all, I want to say how much I like RichFaces, it's really an awesome component collection and I really do like to work with them.
However, today I expierience some issues when I use some input validation features, mainly I do not get any responses by the validation components, regardless if I'm using standard validators like f:validateLength or my custom ValidationClass. I know, that the validation method is called as the Tomcat output confirms that.
here's my jsp file:
<%@ page language="java" contentType="text/html; charset=US-ASCII" pageEncoding="US-ASCII"%> <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <%@ taglib uri="http://richfaces.org/rich" prefix="rich" %> <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %> <f:view> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"> <title>Tippspiel - Register</title> </head> <body> <a4j:form> <rich:panel header="Registration Form"> <h:panelGrid columns="3"> <h:outputLabel for="inUsername" value="Username*"/> <h:inputText id="inUsername" value="#{userRegistration.username}" required="true"> <f:validator validatorId="UsernameValidator"/> <a4j:support event="onkeyup" eventsQueue="usernameQueue" requestDelay="500" reRender="inUsernameMsg"/> </h:inputText> <h:message for="inUsername" id="inUsernameMsg" /> <h:outputLabel for="inFirstname" value="Firstname*"/> <h:inputText id="inFirstname" value="#{userRegistration.firstname}" required="true"> <f:validateLength minimum="2" maximum="32"/> <a4j:support event="onblur" reRender="inFirstnameMsg"/> </h:inputText> <h:message for="inFirstname" id="inFirstnameMsg"/> <h:outputLabel for="inLastname" value="Lastname*"/> <h:inputText id="inLastname" value="#{userRegistration.lastname}" required="true"> <f:validateLength minimum="2" maximum="32"/> <a4j:support event="onblur" reRender="inLastnameMsg" /> </h:inputText> <h:message for="inLastname" id="inLastnameMsg"/> <h:outputLabel for="inEmail" value="E-Mail*"/> <h:inputText id="inEmail" value="#{userRegistration.email}" required="true"> <f:validator validatorId="eMailValidator"/> <a4j:support event="onblur" reRender="inEmailMsg"/> </h:inputText> <h:message for="inEmail" id="inEmailMsg"/> <h:outputLabel for="inPassword" value="Password*"/> <h:inputSecret id="inPassword" value="#{userRegistration.password}" required="true"/> <h:message for="inPassword"/> <h:outputLabel for="inPasswordConfirm" value="Password (confirm)*"/> <h:inputSecret id="inPasswordConfirm" value="#{userRegistration.passwordConfirm}" required="true"/> <h:message for="inPasswordConfirm"/> </h:panelGrid> <a4j:commandButton action="submit" value="Register"></a4j:commandButton> </rich:panel> </a4j:form> </body> </html> </f:view>
and here's my custom validation method:
public void validate( FacesContext context, UIComponent component, Object value ) throws ValidatorException { String username = (String)value; System.out.println("Checking Username `"+username+"`"); this.db = new MySQL("testuser","testpassword","192.168.5.254"); this.db.connect(); this.db.selectDatabase("db_name"); PreparedStatement stmt = this.db.createPreparedStatement(SQL_CHECK_USERNAME); try { stmt.setString(1, username); stmt.execute(); ResultSet rs = stmt.getResultSet(); rs.next(); if( rs.getString("amount").equals("1")) { FacesMessage fm = new FacesMessage(); fm.setSeverity(FacesMessage.SEVERITY_ERROR); fm.setDetail("Username already exsists!"); fm.setSummary("Username exsists!"); System.out.println(fm.getDetail()); throw new ValidatorException(fm); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
since the validation method is called properly, I don't paste my faces-config.xml.
Thank you for your help! Any help is very appreciated!
cu
tuxbox