문제

I got a bean beanName and a variable paramName that holds the name of the property to be used so that:

<s:textfield name="%{'beanName.' + paramName}"/>

outputs (given paramName == "year" and beanName.getYear() == 1976):

<input type="text" name="beanName.year" value="1976" >

How am I supposed to use <s:property> to output the same property value?

I'd suppose that:

<s:push value="beanName">
   <s:property value="%{paramName}"/>
</s:push>

would do that, but it just writes paramName value.

도움이 되었습니까?

해결책

You need to evaluate paramName first before using it to get value from the bean.

Use square brackets for that:

<s:property value="beanName[paramName]" />

OGNL firstly gets value of paramName and then gets value from beanName with this resolved variable.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top