Struts 2 Dynamic Message with OGNL

In the Struts 2 project, review the message resource section below:

export.filename.accountsummary=customer ${export} 

The action has export served with the installer and the receiver. If you call getText("export.filename.accountsummary") , then the struts automatically call getExport() and fill it with the correct value. (I think struts use OGNL, also look at resource messages that support ${} ). Is it correct?!

I am trying to use customer ${#sessionScope.CurrentUser.userName} expected struts to use this OGNL expression, but it did not work.

+2
jsp el struts2 resourcebundle ognl
Sep 05 '15 at 9:12
source share
2 answers

It seems that the sessionScope variable sessionScope not available in context (unless you manually placed it). Do not confuse it with the scope of the JSP session (the syntax is similar to the syntax used in JSP for EL, but Struts2 does not use the JSP EL mechanism there), everything in the OGNL expression is evaluated against the OGNL context. You can use the ${} syntax in messages, Struts parses its value for an OGNL expression, and this syntax defines the scope of the expression that evaluates after the removal of ${} .

+2
Sep 05 '15 at 9:43
source share

I found that the vale stack already has a session in it with #session , so

 ${#session.['CurrentUser'].farsiFirstName} ${#session.CurrentUser.farsiFirstName} 

works great.

+1
Sep 06 '15 at 14:03
source share



All Articles