Announcement Announcement Module
No announcement yet.
Validation error messages not shown in the view when the field values are wrong! Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation error messages not shown in the view when the field values are wrong!


    I tried to add a validator for one of my view and it seems that it works .
    When I add a message and redirect it
    to another view the message is shown in that view but when I want that it show me the messages
    (In fact error messages) in the same view it doesn't show any message:

    <var name="hotelValidator" class="xxxx.HotelValidator"/>
    <view-state id="overview" view="main.xhtml" redirect="true">
    			<set name="" value="hotelsPage.dataModel" />
    		<transition on="insert" to="newHotel"/>
    		<transition on="select" to="hotelDetails">
    			<set name="flowScope.hotel" value="hotels.selected" />
    		<transition on="delete" to="overview">
    			<evaluate expression="hotelsService.delete(" />
    		<transition on="exit" to="finish"/>
            <view-state id="newHotel" view="details.xhtml" >
    		<var name="hotel" class="xxx.domain.Hotel"/>
    		<transition on="cancel" to="overview" validate="false"/>
    		<transition on="save" to="overview">
    			<evaluate expression="hotelValidator.validate(hotel, messageContext)" />
    			<evaluate expression="" />
    The messages are shown in the overviews view but not in the details view itself:

    public class HotelValidator implements Serializable {
        protected final Log log = LogFactory.getLog(getClass());
    	private static final long serialVersionUID = -2102823196606697250L;
    	public boolean validate(Hotel hotel, MessageContext messages) {
 "this log message are displayed and all things works well");
    		if (hotel.getName() == null || hotel.getName().trim().length() == 0) {
    			messages.addMessage(new MessageBuilder().error().source("name").
                                 defaultText("Name should be specified!").build());
                            //if it return false the flow return back to the origin view 
                            // (details) and error messages won't be shown.
                            //but even if I return true here the above error message will be shown in the overview page!
    			return false;
    		messages.addMessage(new MessageBuilder().error().source("name").
                                  defaultText("New Hotel is saved successfully!").build());
    		//In this case the messages are shown in the "overview" page.
    		return true;
    Can anyone tell me how I should fix this problem?