Class SwingValidator<B>

java.lang.Object
org.nuiton.validator.bean.AbstractValidator<O>
org.nuiton.validator.bean.simple.SimpleBeanValidator<B>
jaxx.runtime.validator.swing.SwingValidator<B>
Type Parameters:
B - le type de bean a valider

public class SwingValidator<B>
extends org.nuiton.validator.bean.simple.SimpleBeanValidator<B>
La surcharge de SimpleBeanValidator pour les ui swing Permet d'ajouter facilement le support de la validation des champs d'un bean et de le relier a une interface graphique. Utilise xwork pour la validation et JXLayer pour la visualisation. Le mieux pour son integration dans Jaxx est de faire de la generation pour force la compilation du code suivant:
 myValidor.getBean().get<field>();
 
et ceci pour chaque field ajoute a la map fieldRepresentation. De cette facon meme si le champs field est en texte on a une verification de son existance a la compilation. La representation en tag pourrait etre
 <validator id="myValidator" beanClass="{Personne.class}"
 errorList="$list">
   <field name="name" component="$name"/>
   <field name="firstName" component="$firstName"/>
   <field name="birthDate" component="$birthDate"/>
 </validator>
 <validator beanClass="{Personne.class}" autoField="true"
 errorList="$list">
   <fieldRepresentation name="name" component="$lastName"/>
 </validator>
 
dans le premier exemple on fait un mapping explicite des champs, mais on voit que le nom du composant graphique est le meme que celui du champs. Pour eviter de longue saisie, il est possible d'utiliser le flag autoField qui pour chaque champs du ayant une methode get du bean recherche un composant avec cet Id. Il est aussi possible de surcharge un champs explicitement comme ici name, dans le cas ou le composant qui porterait ce nom serait utilise pour autre chose. Il faut un handler particulier pour ce composant car les attributs beanClass et autoField ne sont present que dans le XML jaxx et servent a la generation. Il faut aussi prendre en compte les elements fieldRepresentation fils du tag validator. Voici ce que pourrait etre le code genere par jaxx
 // declaration du bean
 BeanValidator<beanClass> $myValidator;
 // init du bean
 protected void createMyValidator() {
   $myValidator = new BeanValidator<beanClass>();
   // genere seulement si autoField = true
   for (Method m : beanClass.getMethod()) {
     if (m.getName().startsWith("get")) {
       String fieldName = m.getName().substring(3).toLowerCase();
       $myValidator.setFieldRepresentation(fieldName,
 $objectMap.get(fieldName));
     }
   }
   // pour chaque tag fieldRepresentation
   myValidator.setFieldRepresentation("name", $lastName);
   // si beanClass est specifie et n'est pas Object, on force l'acces au
 champs
   // pour validation a la compilation
   $myValidator.getBean().getName();
   $objectMap.put("myValidator", $myValidator);
 }
 
Version:
1.0
Author:
Tony Chemit - chemit@codelutin.com
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.nuiton.validator.bean.simple.SimpleBeanValidator

    org.nuiton.validator.bean.simple.SimpleBeanValidator.NuitonValidatorContext<O extends java.lang.Object>
  • Field Summary

    Fields
    Modifier and Type Field Description
    protected SwingValidatorMessageListModel errorListModel
    Object servant a contenir la liste des erreurs
    protected SwingValidatorMessageTableModel errorTableModel
    Object servant a contenir la liste des erreurs
    protected java.util.Map<java.lang.String,​javax.swing.JComponent> fieldRepresentation
    permet de faire le lien en un champs du bean et l'objet qui permet de l'editer
    protected java.lang.Class<? extends AbstractBeanValidatorUI> uiClass
    ui renderer class

    Fields inherited from class org.nuiton.validator.bean.simple.SimpleBeanValidator

    BEAN_PROPERTY, context, parentValidator

    Fields inherited from class org.nuiton.validator.bean.AbstractValidator

    canValidate, changed, CHANGED_PROPERTY, CONTEXT_PROPERTY, l, listenerList, pcs, SCOPES_PROPERTY, valid, VALID_PROPERTY, validatorProvider
  • Constructor Summary

    Constructors
    Constructor Description
    SwingValidator​(java.lang.Class<B> beanClass, java.lang.String contextName)  
    SwingValidator​(java.lang.Class<B> beanClass, java.lang.String contextName, org.nuiton.validator.NuitonValidatorScope... filterScopes)  
    SwingValidator​(org.nuiton.validator.NuitonValidatorProvider provider, java.lang.Class<B> beanClass, java.lang.String contextName, org.nuiton.validator.NuitonValidatorScope... filterScopes)  
  • Method Summary

    Modifier and Type Method Description
    javax.swing.JComponent getFieldRepresentation​(java.lang.String fieldname)  
    SwingValidator<?> getParentValidator()  
    java.lang.Class<? extends AbstractBeanValidatorUI> getUiClass()  
    void installUIs()
    install ui on required components
    static <O> SwingValidator<O> newValidator​(java.lang.Class<O> type, java.lang.String context, org.nuiton.validator.NuitonValidatorScope... scopes)
    Obtain a new SimpleBeanValidator for the given parameters.
    static <O> SwingValidator<O> newValidator​(java.lang.String providerName, java.lang.Class<O> type, java.lang.String context, org.nuiton.validator.NuitonValidatorScope... scopes)
    Obtain a new SimpleBeanValidator for the given parameters.
    void reloadBean()
    To reload a bean in the validator.
    void setContext​(java.lang.String context)  
    void setErrorListModel​(SwingValidatorMessageListModel errorListModel)  
    void setErrorTableModel​(SwingValidatorMessageTableModel errorTableModel)  
    void setFieldRepresentation​(java.lang.String fieldname, javax.swing.JComponent c)
    Permet d'indiquer le composant graphique responsable de l'affichage d'un attribut du bean
    void setFieldRepresentation​(java.util.Map<java.lang.String,​javax.swing.JComponent> fieldRepresentation)  
    protected void setMessageRepresentation​(java.lang.String fieldname, javax.swing.JComponent old, javax.swing.JComponent c, java.lang.Class<? extends AbstractBeanValidatorUI> uiClass)
    Deprecated.
    protected void setMessageRepresentation​(javax.swing.JComponent c, java.util.Collection<java.lang.String> fieldnames, java.lang.Class<? extends AbstractBeanValidatorUI> uiClass)  
    void setParentValidator​(SwingValidator<?> parentValidator)  
    void setUiClass​(java.lang.Class<? extends AbstractBeanValidatorUI> uiClass)  

    Methods inherited from class org.nuiton.validator.bean.simple.SimpleBeanValidator

    addSimpleBeanValidatorListener, convert, convert, doValidate, doValidate, fireFieldChanged, getBean, getDelegate, getHighestScope, getSimpleBeanValidatorListeners, hasErrors, hasFatalErrors, hasInfos, hasWarnings, isValid, mergeMessages, rebuildDelegateValidator, removeSimpleBeanValidatorListener, setBean, setParentValidator, validate

    Methods inherited from class org.nuiton.validator.bean.AbstractValidator

    addPropertyChangeListener, addPropertyChangeListener, containsField, firePropertyChange, getContext, getEffectiveFields, getEffectiveFields, getEffectiveScopes, getModel, getScopes, getType, isCanValidate, isChanged, isValid, removePropertyChangeListener, removePropertyChangeListener, setCanValidate, setChanged, setScopes, setValid

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • fieldRepresentation

      protected final java.util.Map<java.lang.String,​javax.swing.JComponent> fieldRepresentation
      permet de faire le lien en un champs du bean et l'objet qui permet de l'editer
    • errorListModel

      protected SwingValidatorMessageListModel errorListModel
      Object servant a contenir la liste des erreurs
    • errorTableModel

      protected SwingValidatorMessageTableModel errorTableModel
      Object servant a contenir la liste des erreurs
    • uiClass

      protected java.lang.Class<? extends AbstractBeanValidatorUI> uiClass
      ui renderer class
  • Constructor Details

    • SwingValidator

      public SwingValidator​(org.nuiton.validator.NuitonValidatorProvider provider, java.lang.Class<B> beanClass, java.lang.String contextName, org.nuiton.validator.NuitonValidatorScope... filterScopes)
    • SwingValidator

      public SwingValidator​(java.lang.Class<B> beanClass, java.lang.String contextName, org.nuiton.validator.NuitonValidatorScope... filterScopes)
    • SwingValidator

      public SwingValidator​(java.lang.Class<B> beanClass, java.lang.String contextName)
  • Method Details

    • newValidator

      public static <O> SwingValidator<O> newValidator​(java.lang.Class<O> type, java.lang.String context, org.nuiton.validator.NuitonValidatorScope... scopes) throws java.lang.NullPointerException
      Obtain a new SimpleBeanValidator for the given parameters. Note: It will use the default provider of NuitonValidator
      Type Parameters:
      O - type of bean to validate
      Parameters:
      type - type of bean to validate
      context - context of validation
      scopes - authorized scopes (if null, will use all scopes)
      Returns:
      the new instanciated SimpleBeanValidator.
      Throws:
      java.lang.NullPointerException - if type is null
      See Also:
      NuitonValidatorFactory.getDefaultProviderName()
    • newValidator

      public static <O> SwingValidator<O> newValidator​(java.lang.String providerName, java.lang.Class<O> type, java.lang.String context, org.nuiton.validator.NuitonValidatorScope... scopes) throws java.lang.NullPointerException
      Obtain a new SimpleBeanValidator for the given parameters. Note: It will use the provider of NuitonValidator defined by the providerName.
      Type Parameters:
      O - type of bean to validate
      Parameters:
      providerName - name of NuitonValidator to use
      type - type of bean to validate
      context - context of validation
      scopes - authorized scopes (if null, will use all scopes)
      Returns:
      the new instanciated SimpleBeanValidator.
      Throws:
      java.lang.NullPointerException - if type is null
      See Also:
      NuitonValidatorFactory.getProvider(String)
    • reloadBean

      public void reloadBean()
      To reload a bean in the validator. This method is used to reload ui, since some editors could not exist when validator is init, so some messages should not be attached to an editor.
    • getFieldRepresentation

      public javax.swing.JComponent getFieldRepresentation​(java.lang.String fieldname)
    • getUiClass

      public java.lang.Class<? extends AbstractBeanValidatorUI> getUiClass()
    • setErrorListModel

      public void setErrorListModel​(SwingValidatorMessageListModel errorListModel)
    • setErrorTableModel

      public void setErrorTableModel​(SwingValidatorMessageTableModel errorTableModel)
    • setUiClass

      public void setUiClass​(java.lang.Class<? extends AbstractBeanValidatorUI> uiClass)
    • setContext

      public void setContext​(java.lang.String context)
      Overrides:
      setContext in class org.nuiton.validator.bean.AbstractValidator<B>
    • setFieldRepresentation

      public void setFieldRepresentation​(java.lang.String fieldname, javax.swing.JComponent c)
      Permet d'indiquer le composant graphique responsable de l'affichage d'un attribut du bean
      Parameters:
      fieldname - the field name in the bean
      c - the editor component for the field
    • setFieldRepresentation

      public void setFieldRepresentation​(java.util.Map<java.lang.String,​javax.swing.JComponent> fieldRepresentation)
    • getParentValidator

      public SwingValidator<?> getParentValidator()
      Overrides:
      getParentValidator in class org.nuiton.validator.bean.simple.SimpleBeanValidator<B>
    • setParentValidator

      public void setParentValidator​(SwingValidator<?> parentValidator)
    • installUIs

      public void installUIs()
      install ui on required components
    • setMessageRepresentation

      protected void setMessageRepresentation​(javax.swing.JComponent c, java.util.Collection<java.lang.String> fieldnames, java.lang.Class<? extends AbstractBeanValidatorUI> uiClass) throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.NoSuchMethodException
      Throws:
      java.lang.reflect.InvocationTargetException
      java.lang.IllegalAccessException
      java.lang.InstantiationException
      java.lang.NoSuchMethodException
    • setMessageRepresentation

      @Deprecated protected void setMessageRepresentation​(java.lang.String fieldname, javax.swing.JComponent old, javax.swing.JComponent c, java.lang.Class<? extends AbstractBeanValidatorUI> uiClass) throws java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessException, java.lang.InstantiationException, java.lang.NoSuchMethodException
      Deprecated.
      Throws:
      java.lang.reflect.InvocationTargetException
      java.lang.IllegalAccessException
      java.lang.InstantiationException
      java.lang.NoSuchMethodException