Hello Team,
I am working on Simple Spring Web flow 2.3.1 application.. In my application I wanted to show the submitted form validated errror messages from a configured resource bundle.. But the error messages are coming from default JSR 303 validations...
JSP Page Code:
messages.properties file placed class pathCode:<form:form commandName="authenticatedUser" method="POST"> <form:errors path="*" cssClass="errorblock" element="div" /> User Name:<form:input path="userName" /> <form:errors path="userName" cssClass="error" /> Password:<form:password path="passWord" /> <form:errors path="passWord" cssClass="error" /> <input type="submit" name="_eventId_verifyLogin" value="Login" /> </form:form>
Messages bean configuration:Code:NotEmpty.authenticatedUser.userName = User Name should not be empty NotNull.authenticatedUser.userName = User Name should be not be null Pattern.authenticatedUser.userName = User Name should be Alpha Characters only Size.authenticatedUser.userName = User Name should be minimum 2 characters NotEmpty.authenticatedUser.passWord = Password should not be empty NotNull.authenticatedUser.passWord = Password should be not be null Size.authenticatedUser.passWord = Password should be minimum 6 characters Pattern.authenticatedUser.passWord = Password should not contain spaces
Bean class:Code:<bean class="org.springframework.context.support.ResourceBundleMessageSource" id="messageSource"> <property name="basename" value="messages" /> </bean>
Flow configurationCode:public class AuthenticatedUser implements Serializable{ /** * Stores the userName */ @NotEmpty @NotNull @Pattern(regexp = "[a-z-A-Z]*") @Size(min=1) private String userName =null; @NotEmpty @NotNull @Size(min=4) @Pattern(regexp = "[a-z-A-Z-0-9]*") private String passWord = null; //get and set methods are included }
Flow Registry configurationCode:<flow...> <var name="authenticatedUser" class="com....AuthenticatedUser" /> <view-state id="login" model="authenticatedUser"> <transition on="verifyLogin" to="confirmLogin" validate="true" bind="true" > </transition> </view-state> <action-state id="confirmLogin"> <evaluate expression="authenticationService.authenticateUser(authenticatedUser)" /> <transition on="success" to="balances" /> <transition on="error" to="login" /> <transition on-exception="com......AuthenticationFailedException" to="login" /> </action-state> ..... </flow>
Code:<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> <property name="flowRegistry" ref="flowRegistry" /> <property name="order" value="0" /> </bean> <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> <property name="flowExecutor" ref="flowExecutor" /> </bean> <flow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="classpath:/flows/"> <flow:flow-location-pattern value="**/*.xml"/> </flow:flow-registry> <flow:flow-executor id="flowExecutor" flow-registry="flowRegistry" > <!-- <flow:flow-execution-attributes> <flow:redirect-in-same-state value="false"/> </flow:flow-execution-attributes> --> </flow:flow-executor> <flow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" development="true" validator="validator"/> <bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator"> <property name="viewResolvers" ref="viewResolver" /> </bean> <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"> <property name="ValidationMessageSource" ref="messageSource"/> </bean> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"> <value>/views/</value> </property> <property name="suffix"> <value>.jsp</value> </property> </bean>
I am getting the default messages but not the configured messages in resource bundle... Please let me know if any one knows the answer for this issue...
Thanks in Advance


Reply With Quote
