jsf - PrimeFaces input components are not highlighted on validation error -


i using seam 2.3.1 final. , have added custom emailvalidation on form.

@name("emailvalidator") @bypassinterceptors @org.jboss.seam.annotations.faces.validator public class emailvalidator implements validator {     private static final string email_regex = "^[_a-za-z0-9-]+(\\.[_a-za-z0-9-]+)*@[a-za-z0-9-]+(\\.[a-za-z0-9-]+)*(\\.[a-za-z]{2,})$";      /**      * <a href="http://www.mkyong.com/regular-expressions/how-to-validate-email      * -address-with-regular-expression/">source</a> <br/>      * modification : autorisation des "-" dans le nom de domaine <br/>      * exemple valide : jean-michel-75440.exemple42@email-pro.mon-entreprise.com      */     public void validate(facescontext context, uicomponent component,                          object value) throws validatorexception {          /* create correct mask */         pattern mask = pattern.compile(email_regex);          /* string value of current field */         string emailfield = (string) value;          /* check see if value valid email */         matcher matcher = mask.matcher(emailfield);          if (!matcher.matches()) {             facesmessage message = new facesmessage();             message.setdetail("e-posta adresi geçerli değil!");             message.setsummary("e-posta hatasi");             message.setseverity(facesmessage.severity_error);              throw new validatorexception(message);         }     }      public string getvalidatorid() {         return "emailvalidator";     } } 

and jsf

 <h:form id="editpersonelform">      <p:messages showdetail="true" autoupdate="true" closable="true"/>          <p:outputlabel for="personname" value="ad"/>         <p:inputtext id="personname" placeholder="ad" value="#{personelbean.personel.name}" required="true"                      requiredmessage="ad alanını doldurmak zorunludur." validatormessage="ad alanı zorunludur.">           <p:outputlabel for="personemail" value="e-posta"/>         <p:inputtext id="personemail" value="#{personelbean.personel.email}" placeholder="e-posta" >             <f:validator validatorid="emailvalidator" />         </p:inputtext>          <p:outputlabel for="personelsavebtn" value=""/>         <p:commandbutton id="personelsavebtn" value="kaydet"                          action="#{personelbean.saveorpersist}"                          oncomplete="if (args &amp;&amp; !args.validationfailed) pf('personedit').hide();"                          update=":tableform" ajax="true">          </p:commandbutton>     </p:panelgrid> </h:form> 

it works, when type invalid email, gives error message text. however, input fields not switch error-state mode. there no redline border of input anymore.

you need explicitly cover inputs in ajax-update well. 1 way adding @form represents current form.

<p:commandbutton ... update=":tableform @form" /> 

or explicit id.

<p:commandbutton ... update=":tableform :editpersonelform" /> 

another way using pfs/jquery selector reference inputs.

<p:commandbutton ... update=":tableform @(#editpersonelform :input)" /> 

a different way using omnifaces <o:highlight> put primefaces own style sheet on associated inputs (and labels) never need worry explicitly ajax-updating them.

<o:highlight styleclass="ui-state-error" /> 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -