-->

How to concatenate 2 action class variables in Str

2019-08-25 02:57发布

问题:

I have 2 variable in my action class, id1 and id2. Joined by a _, they're used as a map key.

I am not able to retrieve the map value using this code:

<s:property value="%{mymap[id1_id2]}" /> 

How should I retrieve the map value?

回答1:

The expression id1_id2 in OGNL will assume the presence of a variable named id1_id2, since it's a perfectly legal identifier.

If you want to concatenate strings, you'd need:

<s:property value="%{mymap[id1 + '_' + id2]}" />

I'd likely create a separate variable to use as the key:

<s:set var="mapKey" value="%{id1 + '_' + id2}" />
<s:property value="%{mymap[#mapKey]}" />

Or more likely, I'd do it somewhere besides the view layer.