HOWTO set parameter via "result" tag in struts2 and retrieve it in the resulting template jsp -
i have workflow need render exception page. exception page generic , can called form various situations. need display custom text in each of these exception pages. figured can set "param" in result tag & automatically available in eventual jsp page. unable retrieve (or set) it. here relevant code -
struts.xml -
<global-results> <result name="tv_access_not_alllowed"> <param name="location">/jsp/base/exception/accessnotallowedexception.jsp</param> <param name="appdisplayname">television</param> </result> <result name="radio_access_not_alllowed"> <param name="location">/jsp/base/exception/accessnotallowedexception.jsp</param> <param name="appdisplayname">radio</param> </result> </global-results>
in jsp page tried below options -
<gs:property value="%{appdisplayname}" /> <gs:property value="#appdisplayname" /> <gs:property value="appdisplayname" /> <gs:property value="%{param.appdisplayname}" /> <gs:property value="#param.appdisplayname" /> <gs:property value="param.appdisplayname" />
none of them worked. if guys can point me right direction appreciated. there way print variables available in current context incl. session, page, request scopes?
update ended resolving issue setting variable in parent action, triggered exception. did not want because did not want pollute parent action, modified template handling normal flow of things make use of new variable.
use global exception mappings purpose not result, you'll need result exception mapping resolves result see here: https://cwiki.apache.org/ww/exception-handling.html
i'm not sure manually print out want want, #session map of iteratable items following should work (not tested):
<h1>from session</h1> <s:iterator value="#session"> session key: <s:property/> <ol> <s:iterator> <li><s:parameter/></li> </s:iterator> </ol> </s:iterator>
you need above #application, #request, #page... whatever.
an easier way if don't mind json... create action "aware" interfaces json result type (using struts2-json plugin) nice json plugin serialize public members of objects no matter how nested.
Comments
Post a Comment