Announcement Announcement Module
Collapse
No announcement yet.
Rules Source Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Rules Source

    I've make rules for input validation :

    Code:
    public class TextValidation implements RulesProvider 
    {
     private RulesSource rulesSource;
    
      public TextValidation()
      {
            DefaultRulesSource rulesSource = new DefaultRulesSource();
            rulesSource.addRules(getRules());
            this.rulesSource = rulesSource;
            
      }
      
      protected Rules getRules() 
      {
            Rules rules = Rules.createRules(getClass());
            Constraints c = Constraints.instance();
            rules.add("inputString", c.all(new Constraint[] { c.required(),  
                 c.maxLength(8) }));
            return rules;
      }
      
      public PropertyConstraint getRules(String property) 
      {
           return rulesSource.getRules(getClass(), property);
      }
    
    }
    The form :
    Code:
    public class Text extends JFrame implements ActionListener 
    {
        private JTextField textUserID = new JTextField();
        private JPasswordField password = new JPasswordField();
        private JButton ok = new JButton("Ok");
        private JButton cancel = new JButton("Cancel");
        private TextValidation validation = new TextValidation();
        
        public Text()
        {
            ok.addActionListener(this);
            FormLayout layout = new FormLayout("r:50dlu,3dlu,80dlu","");
            DefaultFormBuilder builder = new DefaultFormBuilder(layout);
            builder.setDefaultDialogBorder();
            
            builder.append("User ID", textUserID);
            builder.nextLine();
            builder.append("Password",password);
            builder.nextLine();
            builder.append(ButtonBarFactory.buildRightAlignedBar  
                 (ok,cancel),3);
            getContentPane().add(builder.getPanel());
            pack();
            show();
      }
      
        public static void main(String args[])
        {
              Text text = new Text();
        }
    
      public void actionPerformed(ActionEvent e)
      {
          String s = e.getActionCommand();
          if(s.equals("Ok"))
          {
                   //here i want to validate value of user ID (textUserID)
          }
      }
    }
    How I can register my textUserID ?

    Thx before


    Ulil

  • #2
    You need to use a Form implementation to use the validation. You have two options:
    1. provide an application wide RulesSource
    2. make your form model object implement RulesProvider

    More info on validation: http://opensource.atlassian.com/conf...rms-Validation
    When you want to work without a form (as you show in your code), you will have to register the appropriate listeners to your input fields, and call the validation framework from their methods.

    Greetz,

    Peter

    Comment

    Working...
    X