Issue
I have a list of strings, that i would like to define in beans.xml.
<util:list id="myFractions" value-type="java.lang.String">
<value>#{ T(com.myapp.longname.verylong.WelcomeController).RED_FRACTION }</value>
<value>#{ T(com.myapp.longname.verylong.WelcomeController).BLUE_FRACTION }</value>
<value>#{ T(${my.prefix}).GREEN_FRACTION }</value>
</util:list>
It works fine, but each time I need to write the full qualified constant's name com.myapp.longname.verylong.WelcomeController
. I would like to write it only once. One solution I have found is to replace it with a property like my.prefix
so I can write only my short prefix instead of the real full path. But then I will need to pollute the global "namespace" with property that is only needed once. I would like to define a placeholder only for this list or at least only for this beans.xml file. I have already tried to define a property directly in beans.xml with PropertyPlaceholderConfigurer
and it works, but then all my inital properties are not available anymore.
So how can I avoid to writing com.myapp.longname.verylong.WelcomeController
each time in a list as a prefix and only define it once? Ideally something like
<util:list id="myFractions" value-type="java.lang.String">
<define-local-placeholder name="my.prefix" value="com.myapp.longname.verylong.WelcomeController" />
<value>#{ T(${my.prefix}).RED_FRACTION }</value>
<value>#{ T(${my.prefix}).BLUE_FRACTION }</value>
<value>#{ T(${my.prefix}).GREEN_FRACTION }</value>
</util:list>
Solution
Please give a try on this
<context:property-placeholder properties-ref="shorthandHelperConstants"/>
<util:properties id="shorthandHelperConstants">
<prop key="my.prefix">com.myapp.longname.verylong.WelcomeController</prop>
</util:properties>
<util:list id="myFractions" value-type="java.lang.String">
<value>#{ T(${shorthandHelperConstants['my.prefix']}).RED_FRACTION }</value>
<value>#{ T(${shorthandHelperConstants['my.prefix']}).BLUE_FRACTION }</value>
<value>#{ T(${shorthandHelperConstants['my.prefix']}).GREEN_FRACTION }</value>
</util:list>
Answered By - Arun Sai
Answer Checked By - Pedro (JavaFixing Volunteer)