Results 1 to 6 of 6

Thread: util:list with scope

  1. #1
    Join Date
    Aug 2006
    Posts
    4

    Thumbs up 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. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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>

  3. #3
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    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>
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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>

  5. #5
    Join Date
    Aug 2006
    Posts
    4

    Default

    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

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    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

Posting Permissions

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