Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on May 6th, 2012  |  syntax: None  |  size: 1.58 KB  |  views: 27  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //JSF page
  2.  
  3. <h:panelGroup>Session ID</h:panelGroup>
  4. <h:panelGroup>
  5.     <h:inputText id="sessionid" value="#{DatabaseController.formMap['sessionid']}" >
  6.         <f:validateLength minimum="0" maximum="15"/>
  7.         <f:validator binding="#{ValidatorController.validateMessage}" >
  8.             <f:attribute name="type" value="sessionid" />
  9.         </f:validator>
  10.         <f:ajax event="blur" render="sessionid" />                                          
  11.     </h:inputText>
  12.     <h:message id="sessionidMessage" for="sessionid" />
  13. </h:panelGroup>
  14.  
  15. // validator
  16.  
  17. import java.io.Serializable;
  18. import javax.enterprise.context.SessionScoped;
  19. import javax.faces.application.FacesMessage;
  20. import javax.faces.component.UIComponent;
  21. import javax.faces.context.FacesContext;
  22. import javax.faces.validator.Validator;
  23. import javax.faces.validator.ValidatorException;
  24. import javax.inject.Named;
  25.  
  26. @Named("ValidatorController")
  27. @SessionScoped
  28. public class FormValidator implements Validator, Serializable {
  29.  
  30.     public FormValidator() {
  31.     }
  32.  
  33.     @Override
  34.     public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
  35.         throw new UnsupportedOperationException("Not supported yet.");
  36.     }
  37.  
  38.     public void validateMessage(FacesContext context, UIComponent component, Object value) throws ValidatorException {
  39.  
  40.         if (context.equals("test")) {
  41.             throw new ValidatorException(new FacesMessage(FacesMessage.SEVERITY_ERROR,
  42.                     "Session ID is already in use, please choose another.", null));
  43.         }
  44.     }
  45. }