Results 1 to 3 of 3

Thread: setting property of one bean using property of other bean

  1. #1
    Join Date
    Aug 2005
    Posts
    4

    Default setting property of one bean using property of other bean

    Hi,

    I have 2classes, e.g. Class Car and Class Properties. Class Car has properties like door, tyres etc. and only some of the properties of Car are stored in Properties object. Car contains Properties object.

    I need to implement this using Spring core Framework. I would really appreciate if someone could tell me how to do this. Also please point me to the resources where I can get information on the same.

    Thanks in advance.

    Regards
    Harish

  2. #2
    Join Date
    Aug 2004
    Posts
    1,905

    Default

    Code:
      <bean id="myCar" class="my.company.Car">
        <property name="properties">
          <list>
            <bean class="my.company.Property">
              <constructor-arg index="0" value="type"/>
              <constructor-arg index="1" value="MPV"/>
            </bean>
            <bean class="my.company.Property">
              <constructor-arg index="0" value="numberOfDoors"/>
              <constructor-arg index="1" value="4"/>
            </bean>
          </list>
        </property>
        <property name="familyCar" value="true"/>
      </bean>
    with the following classes:

    Code:
      class Car &#123;
        private Collection<Property> properties;
        private boolean familyCar;
    
        public void setProperties&#40;final Collection<Property> properties&#41; &#123;
          this.properties = properties;
        &#125;
    
        public void setFamilyCar&#40;final boolean familyCar&#41; &#123;
          this.familyCar = familyCar;
        &#125;
      &#125;
    and
    Code:
      class Property &#123;
        private final String name;
        private final String value;
        public Property&#40;final String name, final String value&#41; &#123;
          this.name = name;
          this.value = value;
        &#125;
      &#125;
    You really need to read the samples

  3. #3
    Join Date
    Aug 2005
    Posts
    4

    Default thanks

    Hi yatesco,

    Thanks a lot, its working. Since I am new to this, I had problems.

    Thanks & Regards
    Harish

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
  •