Note that there are some explanatory texts on larger screens.

plurals
  1. POWarn user of invalid email with JSF
    primarykey
    data
    text
    <p>I would like to <em>warn</em> a user if his e-mail seems invalid, but still allow him to submit the e-mail if he wants to. As I've read, there's no easy way to validate an e-mail besides sending a confirmation message, but I still wants to warn him of silly mistakes as forgetting to put ".com" after gmail.</p> <p>I'm using JSF, and the code looks like the following:</p> <p>XHTML</p> <pre><code>&lt;h:inputText id="email" required="true" requiredMessage="Required field" value="#{signupBean.email}"&gt; &lt;f:ajax event="valueChange" listener="#{signupBean.validateEmail}"/&gt; &lt;/h:inputText&gt; &lt;h:message for="email"/&gt; </code></pre> <p>SignupBean</p> <pre><code>public void validateEmail(AjaxBehaviorEvent event){ if (email != null &amp;&amp; !email.matches(emailRegex)){ String id = event.getComponent().getClientId(); FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Your e-mail seems invalid", "Did you miss the '@' or '.com'?"); FacesContext.getCurrentInstance().addMessage(id, msg); } } </code></pre> <p>As it is, the message is lost, appearing as a warning log. The <code>id</code> that appears is <code>j_id_f:email</code>, but it won't work if I hardcode as <code>email</code>. Also, I've tried using <code>action</code> instead of <code>listener</code>, but the method isn't even called!</p> <p>I'd like some advice if that's the way to go, or if there's some way to do such 'weak' validation in JSF alone. I'm using pure JSF, but would consider using extensions.</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.
    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