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

  • Validation and Interfaces

    Hi all

    I have my own ValidationRulesSource in which I add rules exactly as in the PetStore example. The only problem seems that I cannot use an interface in the new Rules(Class domainObectClass ) call.

    We are using JAXB in our application and all JAXB objects are interfaces with implementation classes, in order to get the validation to work I have to use XXXXImpl.class and not the interface.class.

    Another scenario I have is that I have twenty objects that all implement the same interface. The user can use any of these objects as a template to create a new one, edit the properties and save it for later use. In this scenario it would be very useful for me to designate the interface and have all implementing classes adhere to the rules.

    I tried stepping though the code and found that the rules are stored in a map keyed by the class registered and that backing form objects class is used to look up. So obviously if you register the rules with Connection.class, and your form is backed by ConnectionImpl.class, the lookup will fail.

    I guess my question is, Is there any plans to support this sort of thing?, Or am I completely losing my mind and missing something fundamental here.

    Thanks
    Trevor

  • #2
    So I have a solution.

    All I did was override getRules(Class bean, String contextID) from DefaultRulesSource and if the super call returned null I retrieved the interfaces from the bean and checked those.

    Thanks
    Trevor

    Code:
    @Override
        public Rules getRules(Class bean, String contextId) {
            Rules rules =  super.getRules(bean, contextId);
            if (rules == null) {
                Class interfaces[] = bean.getInterfaces();
                for (Class clazz : interfaces) {
                    if ((rules = super.getRules(clazz, contextId)) != null) {
                        return rules;
                    }
                }
            }
            
            return rules;
        }

    Comment


    • #3
      One step further

      Code:
      @Override
        public Rules getRules( Class bean, String contextId ) {
          Rules rules = super.getRules( bean, contextId );
          if ( rules != null ) {
            return rules;
          }
          
          Class<?>[] interfaces = bean.getInterfaces();
          for ( Class<?> clazz : interfaces ) {
            if ( ( rules = super.getRules( clazz, contextId ) ) != null ) {
              return rules;
            }
          }
      
          //Now check for super classes
          Class<?> superClass = bean.getSuperclass();
          while ( superClass != null ) {
            if ( ( rules = super.getRules( superClass, contextId ) ) != null ) {
              return rules;
            }
            superClass = superClass.getSuperclass();
          }
          return rules;
        }

      Comment


      • #4
        I just added this feature to DefaultRulesSource.

        Comment


        • #5
          Great, thanks.

          Comment

          Working...
          X