Results 1 to 2 of 2

Thread: Rules Source

  1. #1
    Join Date
    Sep 2004
    Posts
    8

    Default 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. #2
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

    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

Similar Threads

  1. JBoss 3.2.6 & Spring Deployment issues
    By difranr in forum Container
    Replies: 2
    Last Post: Sep 18th, 2005, 10:08 PM
  2. Help: the boolean property exception!
    By linwei in forum Swing
    Replies: 2
    Last Post: Nov 17th, 2004, 07:11 PM
  3. listener tag exception
    By hyuan in forum Web
    Replies: 3
    Last Post: Nov 17th, 2004, 03:53 PM
  4. Replies: 6
    Last Post: Nov 8th, 2004, 06:43 AM
  5. NameNotFoundException: ejb not bound
    By alesj in forum EJB
    Replies: 2
    Last Post: Oct 19th, 2004, 11:55 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •