Announcement Announcement Module
No announcement yet.
Unable to see the form validation error messages from resource bundle JSR 303 Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to see the form validation error messages from resource bundle JSR 303

    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:
    <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> file placed class path

    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
    Messages bean configuration:
    <bean class=""
    		<property name="basename" value="messages" />
    Bean class:

    public class AuthenticatedUser implements Serializable{
    	 * Stores the userName
    	@Pattern(regexp = "[a-z-A-Z]*")
    	private String userName =null;
    	@Pattern(regexp = "[a-z-A-Z-0-9]*")
    	private String passWord = null;
                  //get and set methods are included
    Flow configuration
    	<var name="authenticatedUser" class="com....AuthenticatedUser" />
    	<view-state id="login" model="authenticatedUser">
    		<transition on="verifyLogin" to="confirmLogin" validate="true"
    			bind="true" >
    	<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" />
    Flow Registry configuration

    	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    		<property name="flowRegistry" ref="flowRegistry" />
    		<property name="order" value="0" />
    	<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
    		<property name="flowExecutor" ref="flowExecutor" />
    	<flow:flow-registry id="flowRegistry"
    		flow-builder-services="flowBuilderServices" base-path="classpath:/flows/">
    				<flow:flow-location-pattern  value="**/*.xml"/>
    	<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-builder-services id="flowBuilderServices"
    		view-factory-creator="mvcViewFactoryCreator" development="true" validator="validator"/>
    	<bean id="mvcViewFactoryCreator"
    		<property name="viewResolvers" ref="viewResolver" />
    	<bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    		<property name="ValidationMessageSource" ref="messageSource"/>
    	<bean id="viewResolver"
    		<property name="prefix">
    		<property name="suffix">

    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

  • #2
    After changing the like below then I am able to see the configured error messages..

    authenticatedUser.userName.NotEmpty =
    UserName should not be empty
    authenticatedUser.userName.NotNull =
    UserName shouldnot be null
    authenticatedUser.userName.Pattern =
    UserName should be AlphaCharacters only
    authenticatedUser.userName.Size =
    UserName should be minimum 2 characters
    authenticatedUser.passWord.NotEmpty =
    Password should not be empty
    authenticatedUser.passWord.NotNull =
    Password should not be null
    authenticatedUser.passWord.Size =
    Password should be minimum 6 characters
    authenticatedUser.passWord.Pattern = Password should not contain spaces
    Previously I have used the NotEmpty.authenticatedUser.userName but after changing this to authenticatedUser.userName.NotEmpty then we are able to see the configured error messages in resource bundle... I am not sure what the difference between Spring MVC and Webflow.. but with Webflow I am able to see the error messages with the above change.



    • #3
      Do you know why this worked by now ?