Results 1 to 6 of 6

Thread: Validation in Spring RCP

  1. #1
    Join Date
    Oct 2004
    Posts
    2

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

    Default

    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

  3. #3
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

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

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

  4. #4
    Join Date
    Oct 2004
    Posts
    2

    Default

    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

  5. #5
    Join Date
    Sep 2004
    Location
    Ghent, Belgium
    Posts
    224

    Default

    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

  6. #6
    Join Date
    Sep 2006
    Location
    Belgium
    Posts
    70

    Default

    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>

Similar Threads

  1. Spring MVC Web Framework versus Struts
    By biguniverse in forum Web Flow
    Replies: 27
    Last Post: Aug 29th, 2012, 03:57 AM
  2. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  3. Replies: 1
    Last Post: Oct 2nd, 2005, 07:10 PM
  4. Replies: 4
    Last Post: Aug 2nd, 2005, 11:57 AM
  5. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM

Posting Permissions

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