Announcement Announcement Module
Collapse
No announcement yet.
Validation in Spring RCP Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Validation in Spring RCP

    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

  • #2
    Approach 1
    You need to have a RulesSource implementation (see the org.springframework.richclient.samples.petclinic.d omain.PetClinicValidationRulesSource class for an example).

    Code:
    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)
    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") });
        }
    }
    The RulesSource is registered in the rich-clientappication-context.xml file:
    Code:
    <bean id="rulesSource" class="org.springframework.richclient.samples.petclinic.domain.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

    Comment


    • #3
      The User documentation has been updated. It now includes this answer.

      http://opensource.atlassian.com/conf...play/RCP/Forms

      Comment


      • #4
        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

        Comment


        • #5
          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

          Comment


          • #6
            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>

            Comment

            Working...
            X