Announcement Announcement Module
Collapse
No announcement yet.
setting property of one bean using property of other bean Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      thanks

      Hi yatesco,

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

      Thanks & Regards
      Harish

      Comment

      Working...
      X