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