Results 1 to 4 of 4

Thread: Trying to create bean with Hashmap

  1. #1
    Join Date
    Aug 2004
    Location
    Herndon, Virginia
    Posts
    28

    Default Trying to create bean with Hashmap

    I'm trying to create a class that looks like this

    Class MyClass
    {
    String pageName;
    Map pageMap

    }

    The pageMap Map is a <String,List> where the list is just a list of Strings. Basically, I want to provide a string and get a list of strings from the map.

    My bean is defined below...

    <bean id="beanName" class="com.MyClass">
    <property name="pageName">
    <value>pageName</value></property>
    <property name="pageMap">
    <map>
    <entry key="fiscalYear">
    <ref bean="groupList" /> <-- I want a list here or a bean that points to a list, ideally
    </entry>
    </map>
    </property>
    </bean>

    <bean id="groupList" class="????">
    <property name="name">
    <list>
    <value>Group1</value>
    <value>Group2</value>
    <value>Group3</value>
    </list>
    </property>
    </bean>

    But, it doesn't work.

    Is there anyway I can put a list directly into the value of the map, without creating a new class that just holds a list of Strings?
    ---------------------------------
    David H. McCoy


    ----------------------------------

  2. #2
    Join Date
    Aug 2004
    Location
    Toronto, Canada
    Posts
    736

    Default

    Code:
    <bean id="beanName" class="com.MyClass">
      <property name="pageName">
        <value>pageName</value>
      </property>
      <property name="pageMap">
        <map>
          <entry key="fiscalYear">
             <list>
               <value>Group1</value>
               <value>Group2</value>
               <value>Group3</value>
             </list> 
          </entry>
        </map>
      </property>
    </bean>
    Colin Sampaleanu
    SpringSource - http://www.springsource.com

  3. #3
    Join Date
    Aug 2004
    Location
    Herndon, Virginia
    Posts
    28

    Default

    Damn! That's fast! Thank you, Colin.

    Guys, I hope you never tire of hearing this, but this entire project is simply incredible. Frankly, I am in awe of this entire effort.

    I just started playing with dynamic proxies in the last quarter of last year thanks to a great article on onjava.com. Afterwards, I thought, "This is profound." My first crack was adding security to a system via DPs. It occured to me that this is the beginning of an excellent way of adding services. The article helped me better understand where AOP came in.

    Imagine my surprise as a read about Spring that you were building AOP support in. Further imagine, when I saw how advanced your support was.

    One the one hand I thought, "These are some sharp guys and I had some of the same ideas." Then I thought "Sheesh! These guys are WAY ahead at least my curve."

    I just spent a few ours deprecating my dynamic proxies for Springs because frankly, the Spring AOP support is just plain superior. I'm also taking advantage of Spring to unify all our various configuration files under a single umbrella.

    Keep up the good work and I eagerly anticipate December's book!
    ---------------------------------
    David H. McCoy


    ----------------------------------

  4. #4
    Join Date
    Jun 2005
    Posts
    1

    Default

    Hi Colin, and David

    I am a newbie in Spring World and I will appriciate your help. my problem is i am creating a page whose some fields are static while some text fields are dynamic ex

    static fiels -> number of args : 3

    dynamic field : arg1
    arg2
    arg3

    that means based upon my input to "number of args" field next textfileds will be created. for the obvious option for me is Javascript function.

    but these dynamically generated felds i need to bind with the List variable called "arguments" of the Bean. how can i do that ?


    thanks

    Abi

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

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