Note that there are some explanatory texts on larger screens.

plurals
  1. POh:messages validation not working when project is online
    primarykey
    data
    text
    <p>I am creating web application using JSF 2.0 where I am doing validation for full name.</p> <pre><code>&lt;h:inputText value="#{PersonalInformationDataBean.fullName}" size="75" id="fullName" &gt; &lt;f:validator validatorId="fullNameValidator" /&gt; &lt;/h:inputText&gt; &lt;font color="red"&gt;&lt;br /&gt;&lt;h:message for="fullName"/&gt;&lt;/font&gt; </code></pre> <p>In java below is what I have</p> <pre><code>public class FullNameValidator implements Validator { public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException { String enteredName = (String) value; // Pattern p = Pattern.compile("([a-zA-Z]+|[a-zA-Z]+\\s[a-zA-Z]+)"); Pattern p = Pattern.compile("([a-zA-Z\\s]+)"); Matcher m = p.matcher(enteredName.trim()); System.out.println("trimmed data is " + enteredName.trim()); boolean matchFound = m.matches(); if (enteredName.trim().length() == 0) { FacesMessage message = new FacesMessage(); message.setSummary("Please enter name."); throw new ValidatorException(message); } if (enteredName.trim().length() &lt; 10) { FacesMessage message = new FacesMessage(); message.setSummary("Name should be atleast 10 characters."); throw new ValidatorException(message); } if (!matchFound) { FacesMessage message = new FacesMessage(); message.setSummary("Invalid Name."); throw new ValidatorException(message); } // FacesMessage message = new FacesMessage(); // message.setSummary(""); // throw new ValidatorException(message); } } </code></pre> <p>When I run project locally, it runs perfectly.</p> <p>When I took this project online, I am facing problem.</p> <pre><code>++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + fullName data as + Error Message + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + 123343543534545 + Invalid Name + + fahim + Full name should be 10 characters + + null (blank) + NO MESSAGE, here I was expecting + + + result as Please enter name + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ </code></pre> <p>I don't understand when I don't pass any value, why I don't get error message saying Please enter name. Any idea what I am missing here?</p> <p><strong>Note:</strong></p> <p>I don't even get <code>trimmed data is</code> in <code>catalina.out</code> file where I get all message which I have printed under <code>System.out.println</code></p> <p>The problem is when I pass data at that time only validation is called. Else validation is not happening. Please let me know what I am missing here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload