Announcement Announcement Module
Collapse
No announcement yet.
util:list with scope Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • util:list with scope

    I thought I would be able to simplify my configurations slightly by using the nice new util:list syntax, so modified my context as follows...
    Code:
    <bean id="virtualResource" class="fwk.versioning.VirtualResource"
        init-method="initialise" abstract="true">
    </bean>
    
    <bean id="EmailSubmissionConfirmation" parent="virtualResource">
        <property name="resourceName" value="EmailSubmissionConfirmation" />
        <util:list id="resourceWrappers">
            <bean class="fwk.versioning.VersionedResourceWrapper">
                <property name="resource">
                    <bean class="print.templates.VelocityTemplateHolder">
                        <property name="templateName" 
                            value="templates/EmailSubmissionConfirmation.001.vm" />
                    </bean>
                </property>
            </bean>
        </util:list>
    </bean>
    
    <bean id="AssessmentLetterFlat" parent="virtualResource">
        <property name="resourceName" value="AssessmentLetterFlat" />
        <util:list id="resourceWrappers">
            <bean class="fwk.versioning.VersionedResourceWrapper">
                <property name="resource">
                    <bean class="print.templates.VelocityTemplateHolder">
                        <property name="templateName"
                            value="templates/CNBSAssessmentLetterFlat.001.vm" />
                    </bean>
                </property>
            </bean>
            <bean class="fwk.versioning.VersionedResourceWrapper">
                <property name="resource">
                    <bean class="print.templates.VelocityTemplateHolder">
                        <property name="templateName"
                            value="templates/CNBSAssessmentLetterFlat2.001.vm" />
                    </bean>
                </property>
            </bean>
        </util:list>
    </bean>

    As you can see, I have duplicate util:list ids of "resourceWrappers", which is the property of VirtualResource, so I cannot have different names. I had assumed that as it was declared within a bean definition, it would be local to that bean.
    As it was rejected at runtime, is it only possible to do this with the (it has to be said, only slightly) more verbose...

    Code:
    	
    <property name="resourceWrappers">
        <list>
            ...etc...
        </list>
    </property>

    or have I missed a trick?

    Kind regards

  • #2
    I thought the point behind the util:list was to make a defining a ListFactoryBean cleaner. If you are just embedding the property do you really gain anything from doing it this way?
    http://www.springframework.org/docs/...emas-util-list

    I've not tried this, but does this work?
    Code:
    <bean id="EmailSubmissionConfirmation" parent="virtualResource">
        <property name="resourceName" value="EmailSubmissionConfirmation" />
    
        <property name="resourceWrappers">
        <util:list id="blah">
            <bean class="fwk.versioning.VersionedResourceWrapper">
                <property name="resource">
                    <bean class="print.templates.VelocityTemplateHolder">
                        <property name="templateName" 
                            value="templates/EmailSubmissionConfirmation.001.vm" />
                    </bean>
                </property>
            </bean>
        </util:list>
        </property>
    </bean>

    Comment


    • #3
      Karls way should work.

      The id property of the util:list is only there so it can be referenced by it like you reference anyother bean.

      Code:
      <util:list id="resourceWrappers">
        <bean class="fwk.versioning.VersionedResourceWrapper">
          <property name="resource">
            <bean class="print.templates.VelocityTemplateHolder">
              <property name="templateName" value="templates/EmailSubmissionConfirmation.001.vm" />
            </bean>
          </property>
        </bean>
      </util:list>
      
      <bean id="EmailSubmissionConfirmation" parent="virtualResource">
          <property name="resourceName" value="EmailSubmissionConfirmation" />
          <property name="resourceWrappers" ref="resourceWrappers"/>
      </bean>

      Comment


      • #4
        I would have thought if you want to reuse a list then it's better to use <util:list>. If you are using ListFactoryBean, it would also be much cleaner. In your example however the lists are specific to the bean, I don't see any advantage of using the new <util:list> notation.

        Code:
        <bean id="EmailSubmissionConfirmation" parent="virtualResource">
            <property name="resourceName" value="EmailSubmissionConfirmation" />
        
            <property name="resourceWrappers">
            <list>
                <bean class="fwk.versioning.VersionedResourceWrapper">
                    <property name="resource">
                        <bean class="print.templates.VelocityTemplateHolder">
                            <property name="templateName" 
                                value="templates/EmailSubmissionConfirmation.001.vm" />
                        </bean>
                    </property>
                </bean>
            </list>
            </property>
        </bean>

        Comment


        • #5
          Many thanks for your speedy replies guys.
          Looks like the gains are going to be minimal, so I will probably forget it.
          If I had been able to simplify the xml with it, then it might have been worth pursuing.

          Cheers

          Comment


          • #6
            I don't think you will get any real gain unless you are reusing lists. One area though that might be worth considering, is the new extensible XML authoring. There seems to be quite a lot of repitition when defining each entry in the list, this might cut it down for you.
            http://www.springframework.org/docs/...sible-xml.html

            Comment

            Working...
            X