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
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
Approach 1
You need to have a RulesSource implementation (see the org.springframework.richclient.samples.petclinic.d omain.PetClinicValidationRulesSource class for an example).
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)Code:public class PetClinicValidationRulesSource extends DefaultRulesSource { public PetClinicValidationRulesSource() { addRules(createOwnerRules()); }
The RulesSource is registered in the rich-clientappication-context.xml file:Code: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") }); } }
This will cause all owner forms use these validation rules.Code:<bean id="rulesSource" class="org.springframework.richclient.samples.petclinic.domain.PetClinicValidationRulesSource"/>
Approach 2
The FormModel object of the LoginForm, implements the RulesSource interface, thus providing the validation rules.
Hope this helps.
Peter
The User documentation has been updated. It now includes this answer.
http://opensource.atlassian.com/conf...play/RCP/Forms
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
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
Hi,
Could you add in the documentation that we need to register the rulesSource in the application service ;-)
Code:<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>