Announcement Announcement Module
Collapse
No announcement yet.
'type' attribute for the value tag Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 'type' attribute for the value tag

    Just wondering if anyone else would find a 'type' attribute on the 'value' tag useful (or even possible)...optional of course. It would be especially useful for building lists/maps when I want to take advantage of PropertyEditors to create the actual value for the entry. For example, if I wanted a List of Resources, I could do:
    Code:
    <list>
       <value type="org.springframework.core.io.Resource">/WEB-INF/blah.xml</value>
       <value type="org.springframework.core.io.Resource">/WEB-INF/blah2.xml</value>
    </list>
    In my particular case, I was trying to create a MethodMapTransactionAttributeSource and set the map...I'd love to be able to use the TransactionAttributeEditor for the values in the map.

  • #2
    Just use an inner bean definition. Instead of the 'value' tag, use a 'bean' tag and define whatever type of bean you want.

    Am I missing something?

    Comment


    • #3
      I was thinking the same thing as Colin, the following config works just fine:
      Code:
      <beans>
        <bean id="myBean" class="MyBean">
          <property name="values">
           <list>
             <bean class="org.springframework.core.io.ClassPathResource">
               <constructor-arg index="0"><value>blah.xml</value></constructor-arg>
             </bean>
             <bean class="org.springframework.core.io.FileSystemResource">
               <constructor-arg index="0"><value>blah2.xml</value></constructor-arg>
             </bean>
           </list>
          </property>
        </bean>
      </beans>
      This is however a little bit verbose!!!

      Comment


      • #4
        At the end of the day, its really just asking that the dtd/container help me take advantage of the PropertyEditors wherever I can. I would say that, personally, there are probably not enough instances of the issue to warrant changing the dtd, etc...just be verbose in these cases. Thats why I posted the question...to see if others would find it useful.

        Perhaps the example was too trivial. In my case, this is what I wound up doing:
        Code:
        <bean id="matchEndingIn_TX" 
        class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
        	<property name="properties">
        		<props>
        			<prop key="*_TX">PROPAGATION_REQUIRED,-RecordException</prop>
        		</props>
        	</property>
        </bean>
        What I was trying to do originally (before I noticed I could set it as properties) was:
        Code:
        <bean id="matchEndingIn_TX" 
        class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
        	<property name="nameMap">
        		<map>
        			<entry key="*_TX"><value>PROPAGATION_REQUIRED,-RecordException</value></prop>
        		</map>
        	</property>
        </bean>
        which, of course, didn't work. So this is where I started thinking it would be nice to be able to tell spring the underlying type that I wanted it to convert the String to. I could have used an inner bean, but that would have been really verbose (actually at the time I was needing it, I thought it would be even more verbose because I didn't notice I could set the Propogation Behavior and Isolation Level by name).

        So, the setProperties method lets me take advantage of the Property Editor as I wanted...but it would be nice if the solution were more globally applicable. I.E. instead of saying: "anywhere you have a map property whose values can be fairly complicated and would like to be able to take advantage of property editors for the values, then also supply a setProperties method that will directly convert using the appropriate property editor", I think it would be nice to instead say: "anywhere you have a map/list/Object/generic property whose values can be fairly complicated and would like to be able to take advantage of property editors for the values, just specify the type in the value tag and the property will be converted using the associated property editor"

        Comment


        • #5
          Gentlemen,

          I'm struggling with a similar problem and was wondering if I could ask you for help?

          I need to do the following but Spring is not accepting the multiple values
          for the list have I defined the list incorrectly? In the class TestConfig I do my set and gets for the Java List - thank you :

          <bean id="TestConfig" class="com.services.testConfiguration">
          <property name="convBonds">
          <list>
          <value>CVB</value>
          <value>CVP</value>
          </list>
          </property>
          <property name="altIds">
          <list>
          <value>MC</value>
          <value>SE</value>
          <value>IS</value>
          <value>RC</value>
          </list>
          </property>
          </bean>

          Comment

          Working...
          X