Announcement Announcement Module
Collapse
No announcement yet.
Referring to Nested Properties Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Referring to Nested Properties

    I am using the following spring configuration, for Customer.city I want to push the value that is present in Address.city.

    <beans>

    <bean id="Customer" class="com.hsbc.es.Customer">
    <property name="city" ref="Address.city"/>
    </bean>

    <bean id="Address" class="com.hsbc.es.Address">
    <property name="city" value="Chicago"/>
    </bean>
    </beans>

    Is there anyway by which I can do this (the Address.city syntax does not work).

  • #2
    Have a look at PropertyPathFactoryBean which allows exactly what you want. In the API documentation of that class there are also examples of its usage.

    Regards,
    Andreas

    Comment


    • #3
      Thanks for the response I was able to get that specific example running.

      I have a scenario where the bean configuration could be something like


      <bean id="Address" class="com.hsbc.es.Address">
      <property name="capitals[India]" value="Delhi"/>
      <property name="capitals[England]" value="London"/>
      <property name="capitals[Pakistan]">
      <bean class="org.springframework.beans.factory.config.Pr opertyPathFactoryBean">
      <property name="targetBeanName" value="Address"/>
      <property name="propertyPath" value="capitals[India]"/>
      </bean>
      </property>
      </bean>

      As per this configuration I want to push the value "Delhi" for key "Pakistan" in the map which is present in Address class.

      I am unable to get this configuration to work, my understanding is that the bean Address is not initialized completely therefore PropertyPathFactoryBean will always be using the uninitialized capitals map. Is my understanding correct or there is a workaround for this.

      Comment


      • #4
        I'm not sure about the behavior in this scenario. After all, you try to modify the property which you are currently defining. I fear, this could not be solved this way.

        I take it that your point is to have the exact same instance in both locations. The only way I am currently aware of, is to define the string (or what object ever) as standalone singleton bean and refer to it via "ref" tags from both places.

        Regards,
        Andreas

        Comment

        Working...
        X