Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: <util:list> and merge attribute

  1. #1

    Default <util:list> and merge attribute

    I try to use the new <util:list> configuration, especially with the ability to merge lists. Unfortunately, I wasn't able to get it work.

    For example, I have two lists with email addresses which should be merged. The merged list should be an attribute of another bean.
    Code:
    <util:list id="emailAdresses">
        <value>foo@bar.com</value>
    </util:list>
    
    <util:list id="emailAdresses" merge="true">
       <value>someone@something.com</value>
       <value>someoneelse@something.com</value>
    </util:list>
    
    <bean id="someBean" class="my.bean.Class">
        <property name="emailAdresses" ref="emailAdresses" />
    </bean>
    The behaviour is, of course, that one list overrides the other. First I tried to use the parent-child-mechanism to merge the list but there is no parent-attribute for <util:list>.

    What am I doing wrong? Has anybody an example of this?

  2. #2
    Join Date
    Aug 2005
    Location
    Lexington, KY
    Posts
    36

    Default

    Did you look at the 2.0 Reference Manual? I think this exact example is used.
    Jamie Bisotti

  3. #3

    Default

    Yes, I read the Spring 2.0 Reference Manual, and yes, there is a chapter about collection merging (3.3.3.4.1). The example in this chapter works pretty fine for me. Unfortunately, it is based on the usage of the parent-child-relation of two lists and can therefor be used with ListFactoryBean. There is no example for list merging with <util:list> and additionaly the parent-child-relation can not be used because there is no parent-attribute for <util:list>. Any ideas?

  4. #4
    Join Date
    Aug 2005
    Location
    Lexington, KY
    Posts
    36

    Default

    From the Reference Manual; 3.3.3.4.1. Collection merging
    As of Spring 2.0, the container also supports the merging of collections. This allows an application developer to define a parent-style list, map, set or props element, and have child-style list, map, set or props elements inherit and override values from the parent collection; i.e. the child collection's values will be the result obtained from the merging of the elements of the parent and child collections, with the child's collection elements overriding values specified in the parent collection.
    So, there HAS to be a parent/child relationship in order to merge.

    In your example above, all you are doing is defining two different beans, but using the same id. When this happens, last one wins.
    Jamie Bisotti

  5. #5
    Join Date
    Sep 2006
    Posts
    5

    Default

    Hi,

    well, I guess merging in a parent-child relationship only works if you use old-style spring xml declaration. Spring 2.0 XSD for the <util:/> namespace does indeed not provide a parent attribute which might be needed for the parent-child relationship.

    Am I missing something here. I am also unable to merge map beans in Spring 2.0.

    Regards
    dokmatik

  6. #6
    Join Date
    Jun 2007
    Posts
    19

    Default Is there a built-in way to merge multiple lists?

    Hi everyone,
    I have defined several lists using util:list and now I want to merge all of them into one list. How can I do that?
    The problem I am trying to solve is: I have several components coming in JAR files, each of them uses Spring+Hibernate and defines the mapping resources as a list that can be referenced by external Hibernate session factory bean definition.
    Now I'm building this application that uses these JARs and I need to define a Hibernate session factory bean with the mapping resources being the merge of all these existing lists. Otherwise, I have to copy the content of the mapping resources list from each JAR and merge them manually.
    Your advice is greatly appreciated. :-)
    Alex

  7. #7
    Join Date
    Jun 2007
    Posts
    15

    Default

    Hello, I also am trying to do the same thing. Has anyone been successfully able to do this?

  8. #8

    Default Some Links, but no solution

    I also wanted to use this feature, but am too lazy to dig through the code. According to the documentation on <util:list/> (see the end of the section) this should work:
    Finally, you can also control the merging behavior using the 'merge' attribute of the <util:list/> element; collection merging is described in more detail in the section entitled Section 3.3.2.4.1, “Collection merging”.
    The schema (2.5) does not allow the merge attribute. I also had a look at the context file for the (in my interpretation) relevant test case: testUtilNamespace.xml (rev 1.21). I cannot see any hint on how to use collection merging.

    Is there anyone who can bring some insight into this topic? I would raise a JIRA issue if I knew how to raise it in this situation.

  9. #9
    Join Date
    Nov 2005
    Location
    Reutlingen, Germany
    Posts
    2,098

    Default

    Quote Originally Posted by kariem View Post
    Is there anyone who can bring some insight into this topic? I would raise a JIRA issue if I knew how to raise it in this situation.
    It seems this has just been forgotten. So yes, I'd just raise a Jira issue at Spring Jira.

    Joerg
    This post can contain insufficient information.

  10. #10

    Default Found JIRA Issue

    Thank you for the reply, Jörg.

    I actually found an old forum post, and a related issue: SPR-2887. According to the issue, this should be fixed in Spring 3.0 M1.

Posting Permissions

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