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

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

    Hi,

    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:

    Code:
    <var name="hotelValidator" class="xxxx.HotelValidator"/>
    
    <view-state id="overview" view="main.xhtml" redirect="true">
    		<on-entry>
    			<set name="viewScope.hotels" value="hotelsPage.dataModel" />
    		</on-entry>
    		
    		<transition on="insert" to="newHotel"/>
    		<transition on="select" to="hotelDetails">
    			<set name="flowScope.hotel" value="hotels.selected" />
    		</transition>
    		<transition on="delete" to="overview">
    			<evaluate expression="hotelsService.delete(hotels.selected.id)" />
    		</transition>
    		
    		<transition on="exit" to="finish"/>
    	</view-state>
    
            <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="hotelsService.save(hotel)" />
    		</transition>
    	</view-state>
    The messages are shown in the overviews view but not in the details view itself:


    Code:
    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) {
    
    		log.info("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?

    Thanks,
    Soheil
Working...
X