I am having issues with getting a validator to work. I appreciate any help in identifying the issue.
I am using an MVC + Web Flow configuration.
Here is web.xml
Here is my spring configuration:Code:<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>project123</display-name> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> <servlet> <servlet-name>mvcwebflowDispatcher</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/config/*servlet.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>mvcwebflowDispatcher</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>/WEB-INF/jsp/redirect.jsp</welcome-file> </welcome-file-list> <servlet> <description></description> <display-name>TestServlet</display-name> <servlet-name>TestServlet</servlet-name> <servlet-class>com.website.project123.servlet.TestServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>TestServlet</servlet-name> <url-pattern>/TestServlet</url-pattern> </servlet-mapping> </web-app>
My action beans are defined in this separate spring configuration:Code:<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xmlns:webflow="http://www.springframework.org/schema/webflow-config" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd"> <context:component-scan base-package="com.website" /> <mvc:annotation-driven/> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <!--##############################################################################################################################--> <!--##############################################################################################################################--> <!--##############################################################################################################################--> <!-- WEBFLOW CONFIGURATIONS --> <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry"> <webflow:flow-execution-repository max-executions="5" max-execution-snapshots="30" /> </webflow:flow-executor> <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/pageFlows"> <webflow:flow-location-pattern value="/**/*-flow.xml"/> </webflow:flow-registry> <webflow:flow-builder-services id="flowBuilderServices" /> <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> <property name="flowExecutor" ref="flowExecutor" /> </bean> <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> <property name="flowRegistry" ref="flowRegistry"/> <property name="order" value="-1"/> </bean> <!--##############################################################################################################################--> <!--##############################################################################################################################--> <!--##############################################################################################################################--> </beans>
And my validation bean is in it's own separate spring configuration too:Code:<?xml version="1.0" encoding="windows-1252" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:webflow="http://www.springframework.org/schema/webflow-config" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd"> <bean id="entity1SearchAction" class="com.website.flow.action.Entity1SearchAction" /> <bean id="entity2SearchAction" class="com.website.flow.action.Entity2SearchAction" /> <bean id="registrationAction" class="com.website.flow.action.RegistrationAction" /> </beans>
Here is my validator class:Code:<?xml version="1.0" encoding="windows-1252" ?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:webflow="http://www.springframework.org/schema/webflow-config" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd"> <bean id="registrationValidator" class="com.website.flow.validator.RegistrationModelValidator" /> </beans>
>>> POST WAS TOO LONG >> REPLYING WITH REMAINING CODE....Code:package com.website.flow.validator; import java.util.regex.Pattern; import com.website.config.Resources; import com.website.flow.model.RegistrationModel; import org.springframework.validation.Errors; import org.springframework.validation.Validator; import com.website.libraries.logging.LogManager; import com.website.libraries.util.WebUtil; public class RegistrationModelValidator implements Validator { public static final String SOURCE_NAME = "RegistrationModelValidator"; public static final String REGEX_FIELDNUMBER = "[0-9]{9}"; @Override public boolean supports(Class<?> clazz) { return RegistrationModel.class.isAssignableFrom(clazz); } @Override public void validate(Object obj, Errors errors) { LogManager.debug(Resources.LOG_DIRECTORY, SOURCE_NAME, "Entering RegistrationModelValidator.validate()..."); RegistrationModel model = (RegistrationModel) obj; if (model.isReadyToRegister()) { // the user has verified the fieldNumber is not in the system and can now submit a registration application } else { // the user is attempting to begin registration and needs to verify the fieldNumber is not in the system if (WebUtil.isEmptyString(model.getName())) { errors.reject("error.name-required", "name is required"); } if (WebUtil.isEmptyString(model.getfieldNumber())) { errors.reject("error.fieldNumber-required", "fieldNumber is required"); } else if (!Pattern.matches(REGEX_FIELDNUMBER, model.getfieldNumber())) { errors.reject("error.fieldNumber-invalid-format", "fieldNumber must be numbers only and 9 digits in length"); } } LogManager.debug(Resources.LOG_DIRECTORY, SOURCE_NAME, "Exiting RegistrationModelValidator.validate()..."); } }


Reply With Quote