Results 1 to 4 of 4

Thread: Referring to Nested Properties

  1. #1
    Join Date
    Jul 2006
    Posts
    9

    Default 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. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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

  3. #3
    Join Date
    Jul 2006
    Posts
    9

    Default

    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.

  4. #4
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    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

Posting Permissions

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