Field Validation - Screen doesn't display the error message

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Field Validation - Screen doesn't display the error message

Shinky Narula
Hi,

I am trying to perform field vaildation in spring webflow. My Bean name is "BookDetailBean" and view-state is 'booking'. So, i have my Validator defined as follows:


    @Component(value="bookDetailBeanValidator")
    public class BookDetailBeanValidator {

     public void validateBooking(ValidationContext context) {
      System.out.println("void validateBooking(ValidationContext context)");
      MessageContext messages = context.getMessageContext();
      messages.addMessage(new MessageBuilder().error().source("identityNumber").defaultText("Invalid Inputs").build());
     }
    }

flow.xml


    <view-state id="booking" view="/booking" model="bookDetailBean">
     <binder>
       <binding property="identityNumber"/>
     </binder>
     <transition on="nextpage" to="determineNextPage" />
    </view-state>
    <action-state id="determineNextPage">
    <evaluate expression="...."/>
    <transition on="booking" to="booking"/>
    <transition on="xxx" to="xxx"/>
    </action-state>

I am adding Error Message for field 'identityNumber' in my validate Method. Using Thymeleaf2.0 for my view part.

booking.html


    <div id="row">
      <div id="left" th:utext="#{bookDetailBean.IdNum}"></div>
      <div id="right"><input type="text" th:field="*{identityNumber}"/></div>
    </div>
    <ul th:if="${#fields.hasErrors('identityNumber')}"> 
       <li th:each="err : ${#fields.errors('identityNumber')}" th:text="${err}">Input is incorrect</li>
    </ul>

##Jars used: Spring3.1.2 , spring-webflow2.3 , Thymeleaf2.0

My validate method gets called up but the error message doesn't get displayed on screen. Do i need to make any additional settings or something?
Reply | Threaded
Open this post in threaded view
|

Re: Field Validation - Screen doesn't display the error message

Shinky Narula
Resolved. I am accessing the context this way in my html:

<ul> 
      <li th:each="err : ${flowRequestContext.messageContext.getMessagesBySource('phone')}" th:text="${err.text}">Input is incorrect</li>
</ul>

Also, the correct signature of validate method is:

public void validateRegistrationDetails(Booking booking,ValidationContext context) {
         MessageContext messages = context.getMessageContext();
       //validation rules
              messages.addMessage(new MessageBuilder().error().source("phone").defaultText("Invalid Inputs").build());

}
Reply | Threaded
Open this post in threaded view
|

Re: Field Validation - Screen doesn't display the error message

blandger
I'm use web-flow and I'm getting the same result for field.error.
I also wanted to show validation error for 'formBean' object using JSR-303 approach in HTML.

I tried you code snipped for getting and showing error, but can't get error highlighted.
Tomorrow I'll try it more.