Announcement Announcement Module
Collapse
No announcement yet.
Unable to see the form validation error messages from resource bundle JSR 303 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • 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:
    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>
    messages.properties file placed class path

    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
    Messages bean configuration:
    Code:
    <bean class="org.springframework.context.support.ResourceBundleMessageSource"
    		id="messageSource">
    		<property name="basename" value="messages" />
    	</bean>
    Bean class:

    Code:
    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 configuration
    Code:
    <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>
    Flow Registry configuration

    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

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

    Code:
    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.

    Thanks,
    Raghunath

    Comment


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

      Comment

      Working...
      X