2 Replies Latest reply on May 22, 2008 5:33 PM by ig rek

    JSF internalization custumized messages validators

    ig rek Newbie

      Hi I m trying to customize the validation message displayed by the validators I ve created for the input fields., in order to make the display in different languages possible.
      Is that possible???



      validator




      
      public class companyNameValidator implements Validator  {
              String validcompanyName = "[a-zA-Z0-9\\s]+";
          public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
              //companyName validator
              String entredcompanyName = (String)value;
       
              Pattern p =Pattern.compile(validcompanyName);
              Matcher m = p.matcher(entredcompanyName);
               if (!m.matches())
               {
                FacesMessage message = new FacesMessage();
                
                message.setDetail("xxxxxxxxxxxxxxxxxx");
                message.setSummary("xxxxxxxxxxxxxxxxx");
                message.setSeverity(FacesMessage.SEVERITY_ERROR);
                throw new ValidatorException(message);
                  
               }
               }        
      




      Display



      ...
       <h:outputText value="#{messages['CompanyName']}"/>
                      
                      <h:inputText label="company" id="Company" required="true" value="#{customer.companyName}">                   
                          <f:validator validatorId="companyNameValidator"/>
                      </h:inputText>   
                      <rich:message for="Company">
                            <f:facet name="passedMarker">
                                   <h:graphicImage  value="#{theme.img}passed.gif" />  
                            </f:facet>
                            <f:facet name="errorMarker">
                                  <h:graphicImage  value="#{theme.img}error.gif" />  
                            </f:facet>
                            
                     </rich:message>  
      ...
      



      Instead of having a XXXXXXXXXXXXXXX message , i want to put something like #{message.validCompanyError}
      and define the message in message.properties.