Announcement Announcement Module
Collapse
No announcement yet.
How to use the Validator in booking-faces in other Projects Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use the Validator in booking-faces in other Projects

    Hello Everybody

    I had downloaded the booking-faces example with primefaces. And I wanted to use the error message on the "enterBookingDetails.xhtml", when you not fill out the credit card name, in my web-application.

    First I added the @NotEmpty tag to my model class.

    Code:
       @NotEmpty
        private String username; 
        
        @NotEmpty
        protected String firstName;
        
        @NotEmpty
        protected String lastName;
    Then I created my xhtml for that.
    Code:
    <ui:define name="content">
      
      <h:form id="studentForm">
      	<p:messages />
    
    	<p:fieldset legend="Student #{student.username}">
    	
    		<h:outputLabel for="userName">#{text['user.username']}</h:outputLabel>
    		<h:inputText id="userName" label="User name" value="#{student.username}" />
    		
    		<h:outputLabel for="firstName">#{text['user.firstName']}</h:outputLabel>
    		<h:inputText id="firstName" label="First name" value="#{student.firstName}" />
    		
    		<h:outputLabel for="lastName">#{text['user.lastName']}</h:outputLabel>
    		<h:inputText id="lastName" label="Last name" value="#{student.lastName}" />
    		
    		
    		<p:commandButton id="save" value="#{text['button.save']}" action="save" update="@form" />
    
         	<p:commandButton id="cancel" value="#{text['button.cancel']}" action="cancel" immediate="true" />
    	</p:fieldset>
    </h:form>
    </ui:define>
    When I press the save button with empty fields, the error message comes up but only show:
    Code:
    may not be empty
    may not be empty
    may not be empty
    The Label is missing.
    So can anybody tells me what I do wrong, that the labels does not shown in the message.

    Thanks

    EDIT:
    I use
    spring version: 3.0.5.RELEASE
    webflow version: 2.2.1.RELEASE
    hibernate version: 3.3.2.GA
    primefaces version: 3.0.M1
    Last edited by bhzunami; Jul 13th, 2011, 04:14 AM.

  • #2
    Solved

    Ok I find my failure.
    You have to add
    Code:
     <application>
    	<message-bundle>JsfMessageResources</message-bundle>
        </application>
    to your faces-config.xml.
    And then in the src/main/resources Add a File named JsfMessageResources.properties. And put this in it.
    Code:
    #
    # Overrides default pattern in JSF for Bean Validation messages from "{0}" to "{1} {0}" where
    # the {0} is the Bean Validation constraint message (e.g. "may not be empty") and {1} is the
    # field name or the field label if defined (e.g. "First name").
    #
    javax.faces.validator.BeanValidator.MESSAGE={1} {0}
    Now it shows the label first and then the text. If you have no label defined then it shows the name of the Form and the id.
    Example
    TestForm:id34 my not be empty

    Regards

    Comment

    Working...
    X