ulil
Oct 8th, 2004, 05:46 AM
I've make rules for input validation :
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 :
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.buildRightAlignedB ar
(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
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 :
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.buildRightAlignedB ar
(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