View Full Version : Validation in Spring RCP
maggie
Oct 7th, 2004, 04:52 AM
Hi, i'am newbie....
I want to ask about validation in Spring RCP, i've been track the source code.. but i not found.
Somebody help me to tell how to validate the framework, like login form, new owner form...
Thx to help
pdbruycker
Oct 7th, 2004, 05:16 AM
Approach 1
You need to have a RulesSource implementation (see the org.springframework.richclient.samples.petclinic.d omain.PetClinicValidationRulesSource class for an example).
public class PetClinicValidationRulesSource extends DefaultRulesSource {
public PetClinicValidationRulesSource() {
addRules(createOwnerRules());
}
Here are the rules for the Owner class defined (firstName and lastName attributes are required, max 25 long and must be alphabetic, and the address attribute is required)
private Rules createOwnerRules() {
Rules rules = Rules.createRules(Owner.class);
rules.add("firstName", getNamePropertyConstraint());
rules.add("lastName", getNamePropertyConstraint());
rules.add("address", required());
return rules;
}
private Constraint getNamePropertyConstraint() {
return all(new Constraint[] { required(), maxLength(25),
regexp("[a-zA-Z]*", "alphabetic") });
}
}
The RulesSource is registered in the rich-clientappication-context.xml file:
<bean id="rulesSource" class="org.springframework.richclient.samples.petclinic.d omain.PetClinicValidationRulesSource"/>
This will cause all owner forms use these validation rules.
Approach 2
The FormModel object of the LoginForm, implements the RulesSource interface, thus providing the validation rules.
Hope this helps.
Peter
pdbruycker
Oct 7th, 2004, 05:32 AM
The User documentation has been updated. It now includes this answer.
http://opensource.atlassian.com/confluence/spring/display/RCP/Forms
maggie
Oct 7th, 2004, 09:53 PM
If i want to make my own form : "FormTest.java",
there are 2 components : JTextField and JButton.
When i press the button, i want to validate the textfield.
I must register my textfield for the validation, isn't it?
How can i register my textfield?
Thx for helping
pdbruycker
Oct 8th, 2004, 09:11 AM
You have to register the rules to your textfield as shown in the examples above. There is no need for a button to validate the user input. The validation will happen automatically when the user types.
Hope this helps,
Peter
Dominique
Sep 24th, 2006, 11:45 AM
Hi,
Could you add in the documentation that we need to register the rulesSource in the application service ;-)
<bean id="applicationServices"
class="org.springframework.richclient.application.support .DefaultApplicationServices">
<property name="imageSourceId"><idref bean="imageSource"/></property>
<property name="formComponentInterceptorFactoryId"><idref bean="formComponentInterceptorFactory"/></property>
<property name="applicationObjectConfigurerId"><idref bean="applicationObjectConfigurer" /></property>
<property name="rulesSourceId"><idref bean="rulesSource"/></property>
</bean>
Powered by vBulletin® Version 4.2.1 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.