0

There's a similar thread that was never answered properly.

I'm trying to call a Struts 2 Action method from a JSP using <s:property> and this method takes a param. The value I'd like to pass is in a variable.

     <s:set var="myvar" value="..." />
     Value of variable: <c:out value="${myvar}" /> <!-- This works OK -->

     <!-- Now, need to call a method called getActionCategory(str) which takes this var value --> 
     Method call: <s:property value="%{getActionCategory(myvar)}"/>

This doesn't work:

  • myvar comes in as NULL.

  • Also, inserting value="%{getActionCategory(${myvar})} into the parentheses doesn't work: According to TLD or attribute directive in tag file, attribute [value] does not accept any expressions

  • This simplified reference with no get and a param also brings in a NULL for the param value: <s:property value="actionCategory(myvar)" /> (contrary to this post)

The only thing that works is using literal constants, like value="%{getActionCategory('abc')}", which I don't want.

gene b.
  • 10,512
  • 21
  • 115
  • 227
  • It was answered properly (my answer); OGNL has changed more than once in the intervening eight years. My comment on my answer includes the `#`, which was not always required. Tangentially related--it's rare this kind of work belongs in the view layer. – Dave Newton Sep 06 '22 at 15:36

1 Answers1

0

I figured it out:

<s:property value="%{getActionCategory(#myvar)}"/>

gene b.
  • 10,512
  • 21
  • 115
  • 227