4

I am trying to do something similar to this question but the answers don't fix my problem. I'm using Struts2 version 2.3.28.1.

I'm trying to access data in the session using a <s:property> tag and a dynamic value string literal.

If I do:

<s:property value="#session.data_1"></s:property>

Then the correct data is displayed. Now when I try the following:

<s:set var="part1" value="#variable.code"></s:set>
<s:set var="part2" value="'#session.data_'+#part1"></s:set>

<s:property value="part2"></s:property> 
<s:property value="%{part2}"></s:property> 
<s:property value="%{#part2}"></s:property>
<s:property value="#attr[#part2]" default="Not working"></s:property>
<s:property value="(#part2)" default="Not working"></s:property>
<s:property value="%{(#part2)}" default="Not working"></s:property>

Which displays :

#session.data_1
#session.data_1
#session.data_1
Not working
#session.data_1
#session.data_1

(Yes I kinda tried every possible combination that I could think of even if they don't make sense...)

How can I make the <s:property> tag evaluate #part2 instead of interpreting as a string literal? In my understanding %{} should have done the trick but nope.

Community
  • 1
  • 1
Flanfl
  • 508
  • 8
  • 27

1 Answers1

3

You are trying to retrieve value from the session and going through the #attr it isn't going to work.

There is simpler way. Use the #session keyword directly.

<s:property value="#session['data_' + #variable.code]" />
Aleksandr M
  • 23,647
  • 12
  • 63
  • 129