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

  • Declaritive Validation

    I was hoping that Spring v1.1 would have declaritive validation support as Keith Donald outlined in his blog back in April.

    http://opensource.atlassian.com/conf...ive+Validation

    According to the JIRA roadmap it is scheduled for v1.2.

    http://opensource.atlassian.com/proj...report=roadmap

    I would like to be able to declare validation rules somehow that match what and XML Schema defines. This included number ranges, matching against a list of values(enumeration), and a few others. I'm writing xsd2jibx (www.jibx.org) for Java/XML data binding. That it what I need to find some sort of validation form. Any suggestions would be appreciated.

    Any status on the declaritive validation support?

    Thanks,
    Cameron

  • #2
    You can always try the Commons-Validator adapter for Spring. It's in the sandbox. If you have any problems getting it working, feel free to ask here on the forum. I will do my best to help out.

    Comment


    • #3
      Matt Raible describes, in this web log entry, how to use Commons Validator with Spring Framework.

      Comment


      • #4
        The code in the sandbox, specifically, the
        Code:
        org.springframework.rules
        package and related sub-packages contain the work that's been done on the declarative validation module to-date. We're using this code in rich client now to drive as-you-type client-side validation, and so far it's been footing the bill quite nicely.

        As far as status:

        - As the total size of the packages is over 100 KB, and it's plausible that as new out-of-the-box rules are provided it will grow further, we've decided to create a "spring-rules" sub-module within the /cvsroot/springframework repository. So we'll be effectively turning this effort into its own mini-subproject with its own release schedule. This will happen by the first rich client release date, and by Spring 1.2. I'll be posting announcements then, and to mark the module as fit for general use.

        Keith

        Comment


        • #5
          need validation rules example

          I checked out Spring from CVS and I've been looking through the org.springframework.rules packages, but I'm not sure where to begin. How could I validate a Person bean like so:

          Code:
          public class Person{
            public String name;
            public float feetTall;
          }
          Let's say I wanted to make sure that ther person's name was set and feetTall was between 1.0 and 8.0. How would I do that simple validation?

          Comment


          • #6
            check out the tests in sandbox, they might clue you in on how to start using it.

            Comment


            • #7
              Re: need validation rules example

              Originally posted by ctaggart
              Let's say I wanted to make sure that ther person's name was set and feetTall was between 1.0 and 8.0. How would I do that simple validation?
              Let's see, here is what's currently in rules-context.xml of the tests that I was referring to in my previous post:

              Code:
               <beans>
              	<!-- The xml here is *not* the best format to define rules...it's too fine grained and as a result 
              	      way to verbose!!! -->
              	<!-- direct java / groovy / beanshell / jython or some other scripting solution is better
              	     Using the Constraints factory and builders is preferred -->
              
              	<bean  id="messageSource" 
                	    class="org.springframework.context.support.ResourceBundleMessageSource">
                	  <property name="basenames">
                	  	<list>
                	  		<value>org.springframework.rules.messages</value>
                	  	</list>
                	  </property>
                	</bean>
              	     
                	<bean id="rulesSource" class="org.springframework.rules.DefaultRulesSource">
                		<property name="rules">
                			<list>
              				<bean class="org.springframework.rules.Rules">
              					<property name="beanClass">
              						<value>org.springframework.rules.Person</value>
              					</property>
              	  				<property name="propertyRules">
              	  		 			<map>
              	  		 				<entry key="firstName">
              	  							<ref bean="required"/>
              	  		 				</entry>
              	  		 				<entry key="lastName">
              	  		 					<list>
              		  							<ref bean="required"/>
              		  							<bean class="org.springframework.rules.predicates.StringLengthConstraint">
              		  								<constructor-arg index="0">
              		  									<value>10</value>
              		  								</constructor-arg>
              		  							</bean>
              		  							<bean class="org.springframework.rules.predicates.UnaryNot">
              		  								<constructor-arg index="0">
              		  									<bean class="org.springframework.rules.predicates.ParameterizedBinaryPredicate">
              		  										<constructor-arg index="0">
              		  											<ref bean="equals"/>
              		  										</constructor-arg>
              		  										<constructor-arg index="1">
              		  											<value>Keith</value>
              		  										</constructor-arg>
              		  									</bean>
              		  								</constructor-arg>
              		  							</bean>
              		  						</list>
              	  		 				</entry>
              	  					</map>
              	  				</property>
              				</bean>
              			</list>
                		</property>
                	</bean>
                	
                	<bean id="equals" class="org.springframework.rules.predicates.EqualTo"/>
                	<bean id="required" class="org.springframework.rules.predicates.Required"/>
              </beans>
              My guess you would need to change this to something like:
              Code:
              <beans>
              	<!-- The xml here is *not* the best format to define rules...it's too fine grained and as a result 
              	      way to verbose!!! -->
              	<!-- direct java / groovy / beanshell / jython or some other scripting solution is better
              	     Using the Constraints factory and builders is preferred -->
              
              	<bean  id="messageSource" 
                	    class="org.springframework.context.support.ResourceBundleMessageSource">
                	  <property name="basenames">
                	  	<list>
                	  		<value>org.springframework.rules.messages</value>
                	  	</list>
                	  </property>
                	</bean>
              	     
                	<bean id="rulesSource" class="org.springframework.rules.DefaultRulesSource">
                		<property name="rules">
                			<list>
              				<bean class="org.springframework.rules.Rules">
              					<property name="beanClass">
              						<value>org.springframework.rules.Person</value>
              					</property>
              	  				<property name="propertyRules">
              	  		 			<map>
              	  		 				<entry key="firstName">
              	  							<ref bean="required"/>
              	  		 				</entry>
              	  		 				<entry key="feetTall">
              	  		 					<list>
              		  							<ref bean="required"/>
              		  							<bean class="org.springframework.rules.predicates.Range">
              		  								<constructor-arg index="0">
              		  									<value>1.0</value>
              		  								</constructor-arg>
              		  								<constructor-arg index="1">
              		  									<value>8.0</value>
              		  								</constructor-arg>
              		  							</bean>
              		  						</list>
              	  		 				</entry>
              	  					</map>
              	  				</property>
              				</bean>
              			</list>
                		</property>
                	</bean>
                	
                	<bean id="required" class="org.springframework.rules.predicates.Required"/>
              </beans>
              And this is just my guess as I have not tried it, but it seems to make sense

              HTH

              Comment

              Working...
              X