Results 1 to 7 of 7

Thread: Declaritive Validation

Hybrid View

  1. #1
    Join Date
    Aug 2004
    Location
    Seattle
    Posts
    30

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Mount Joy, PA
    Posts
    34

    Default

    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.

  3. #3
    Join Date
    Aug 2004
    Location
    Montréal, Canada
    Posts
    845

    Default

    Matt Raible describes, in this web log entry, how to use Commons Validator with Spring Framework.
    Omar Irbouh

    Spring Modules Team
    http://irbouh.blogspot.com/

  4. #4
    Join Date
    Aug 2004
    Location
    Melbourne, FL
    Posts
    2,794

    Default

    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

  5. #5
    Join Date
    Aug 2004
    Location
    Seattle
    Posts
    30

    Default 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?

  6. #6
    Join Date
    Aug 2004
    Posts
    109

    Default

    check out the tests in sandbox, they might clue you in on how to start using it.
    Thanks,
    Alex.

  7. #7
    Join Date
    Aug 2004
    Posts
    109

    Default Re: need validation rules example

    Quote 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
    Thanks,
    Alex.

Similar Threads

  1. Replies: 2
    Last Post: Oct 10th, 2005, 05:12 PM
  2. Rules-Based Validation - Does this exist?
    By leask in forum Container
    Replies: 2
    Last Post: Sep 28th, 2005, 05:37 AM
  3. Lost with Validation
    By RAPHEAD in forum Architecture
    Replies: 6
    Last Post: May 29th, 2005, 06:01 AM
  4. Domain Object Validation
    By lhilden in forum Architecture
    Replies: 4
    Last Post: Dec 14th, 2004, 07:00 AM
  5. Replies: 0
    Last Post: Nov 15th, 2004, 11:25 AM

Posting Permissions

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