Announcement Announcement Module
Collapse

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions (http://www.springsource.org/extensions) project, this forum has been decommissioned in favour of Spring Extensions one at:
http://forum.springsource.org/forumdisplay.php?f=44

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Cheers,
Costin Leau
SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
http://twitter.com/costinl
See more
See less
programmatic annotation with beanvalidator Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • programmatic annotation with beanvalidator

    Hi Guys,
    I am having issue beanvalidator with webflow.
    My validation extends springmodules beanvalidator.
    It is validating the domain but if it has errors it is not redirecting to error page.


    The same thing works if i use springframework.validation.ValidationUtils

    any suggestion would be appreciated.

    code with springmodules beanvalidator.
    Code:
        public void validate(BusinessListingFormWrapper listingForm, Errors errors) {
        //	BusinessListingFormWrapper listingForm = (BusinessListingFormWrapper)obj; 
        	Listing listing = listingForm.getListing();
    		AnnotationBeanValidationConfigurationLoader loader = new AnnotationBeanValidationConfigurationLoader();
    		loader.loadConfiguration(listingForm.getListing().getClass());
    		this.setConfigurationLoader(loader);
    		errors = new BindException(listingForm.getListing(), "BusinessListingFormWrapper");
            // applying the registered validation rules.
            super.validate(listingForm.getListing(), errors);
    
            System.out.println("  errors" +errors.getErrorCount());
        }

    eample with springframework.validation.ValidationUtils.

    Code:
       public void validate(BusinessListingFormWrapper listingForm, Errors errors) {
        //	BusinessListingFormWrapper listingForm = (BusinessListingFormWrapper)obj; 
        	Listing listing = listingForm.getListing();
    	
      
        	ValidationUtils
    		.rejectIfEmptyOrWhitespace(errors, "listing.businessName",
    				null, this.messages.getMessage(
    						"listing.businessname.required", null,
    						"default", null));
    
    		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "listing.contact",
    				null, this.messages.getMessage("listing.contact.valid", null,
    						"default", null));
    		
    		if (!FieldValidator.isPhoneValid(FieldValidator.formatPhone(listing
    				.getContact()))) {
    		
    			errors.rejectValue("listing.contact", null, this.messages
    					.getMessage("listing.contact.required", null, "default",
    							null));
    		
    		}	
            System.out.println("  errors" +errors.getErrorCount());
        }
    Last edited by indone; Mar 5th, 2007, 11:30 PM.

  • #2
    Hi Guys i am able to fix the problem.

    basically i was missing setting cascade validation for wrapperclass.


    Code:
    public class BusinessListingFormWrapper implements Serializable {
    	static final long serialVersionUID = 0;
    
    	@CascadeValidation
    	private Listing listing;

    Does any one know how to use resource bundle for annotations?

    Code:
    public class Listing extends Advertisement 
    	implements Serializable {
       @NotBlank
        @Length(min = 3, max = 5 , message = "feature name must be between 3-5 characters")
    	private String businessName;

    Comment


    • #3
      Guys.
      in my earlier mail i was looking for the solution domain annotations to handle the resource bundle. is there any way that i can pass the key instead of actual message?

      Does any one know how to use resource bundle for annotations?

      Code:
      public class Listing extends Advertisement 
      	implements Serializable {
         @NotBlank
          @Length(min = 3, max = 5 , message = "feature name must be between 3-5 characters")
      	private String businessName;
      Code:
      	<bean id="formAction"
      		class="com.idearc.feeos.web.spring.ListingAction">
      		<property name="formObjectClass"
      			value="com.idearc.feeos.web.spring.BusinessListingFormWrapper" />
      		<property name="formObjectName" value="bpmodel" />
      		<property name="formObjectScope" value="FLOW" />
      		<property name="validator"  ref="domainvalidator" />
      	</bean>
      
      
      	<bean id="domainvalidator" class="org.springmodules.validation.bean.BeanValidator">
      		<property name="configurationLoader" ref="configurationLoader"/>
      	</bean>
      	<bean id="configurationLoader" 
      		class="org.springmodules.validation.bean.conf.loader.annotation.AnnotationBeanValidationConfigurationLoader"/>

      Comment


      • #4
        Guys,
        i got the solution . Annotation has standard notation lookup for the resouce bundle key.

        for example

        Code:
        public class Listing extends Advertisement 
        	implements Serializable {
         @NotBlank
         private String businessName;
        
        }
        
        the properties file should have the key with
        
        Listing.businessName[not.blank]=Business name must not be empty

        Comment

        Working...
        X