Announcement Announcement Module
Collapse
No announcement yet.
Form backing object and validator in one singular bean, ok? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form backing object and validator in one singular bean, ok?

    Hi guys,

    anything (technically) against using a form backing object and it's validator in one bean? Like this:

    Code:
    public class RequestPasswordHintForm implements Validator {
    
    	private String email;
    	private String username;
    
    	public String getEmail() { return email; }
    	public void setEmail(String email) { this.email = email; }
    
    	public String getUsername() { return username; }
    	public void setUsername(String username) { this.username = username; }
    
    	// ~ Validation ------------------------------------------------------------
    
    	public boolean supports(Class clazz) {
    		return RequestPasswordHintForm.class.isAssignableFrom(clazz);
    	}
    
    	public void validate(Object command, Errors errors) {
    		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "ume.ui.err.requiredEmail", null);
    		
    		// more basic validation
    		
    	}
    }
    It seems to work and i like to use it that way caus it's basically a complete UI Form represented as a Java object.

    Wiring looks like that:

    Code:
    	<bean id="/self-service-request-hint" class="com.thyrell.cdb.ui.web.ume.RequestPasswordHintController">
    		<property name="selfService" ref="spring&#58;comp/env/ume/CustomerSelfService"/>
    		<property name="formView" value="/self-service-request-hint"/>
    		<property name="successView" value="/self-service-request-hint-sent"/>
    		<property name="validator">
    			<bean class="com.thyrell.cdb.ui.web.ume.RequestPasswordHintForm"/>
    		</property>
    	</bean>
    Any technical objections? The same class would exist as a singleton in the bean framework and as objects factored in controller:formBackingObjcet(); Could it cause problems? Someone used it already? I'm grateful for any input.

    Best,
    Andi

  • #2
    Any technical objections?
    Can't think of any. Seems like a reasonable option to me.

    Comment


    • #3
      Cool, thnx This saves me a couple of extra classes.

      -andi

      Comment

      Working...
      X