我可以用几种方式在ValueStack
上设置一个属性。Struts2中应用程序的ValueStack生命周期是什么?
ValueStack stack = ActionContext.getContext().getValueStack();
stack.getContext().put("resultDTO",resultDTO); //1. creates a different branch
//parallel to root
stack.set("resultDTO", resultDTO); //2. pushes on root as a Map?
stack.push(resultDTO); //3. pushes on root
myActionClass.setProperty(); //4. normal action accessor
我需要能够得到所有这些值回JSP,FreeMarker和Java的像
stack.findValue() or stack.findString().
我想知道有关这些设置方法的生命周期。它是否跨越应用程序?是否为每个请求创建了ValueStack,并为其设置了应用程序和会话值?
我知道第四种方法是最常用的方法,但我可能不会在所有地方使用这种方法,其中操作类不容易访问。
我对自己在JSP
<s:push value="resultDTO" ><s:property value="data.form1[0]" /></s:push>
<!--5.works for context.put() & stack.set() both-->
<s:property value="#resultDTO.data.form1[0].countryofissue" /> <!--6.context.put()-->
<s:property value="resultDTO.data.form1[0].countryofissue" /> <!--7.stack.set()-->
<s:property value="data.form1[0].countryofissue" /> <!--8.stack.push()-->
访问其他疑问,我也想知道怎么点在5日都stack.getContex().put()
和stack.set()
的作品?据我所知,在第6个resultDTO我正在访问,是一个不同的根,并在7日,它是默认的根,这是ValueStack的孩子。 8日开始从默认根目录搜索。
我通过http://struts.apache.org/2.0.11.1/docs/ognl.html去,http://struts.apache.org/2.1.2/struts2-core/apidocs/com/opensymphony/xwork2/util/ValueStack.html和相当混乱这个链接http://www.opensymphony.com/ognl/html/DeveloperGuide/introduction.html#embeddingOGNL
说了这些,我有点倾向于使用stack.getContext().put()
方法,我可以清楚地看到中的值设置URL作为?调试=浏览器。告诉我,如果我出错了。
我正在尝试使用值堆栈来传递预结果钩子和一些泛型pojos中的某些数据集,以便某些setter和getter不会在所有操作类中重复。在一个场合中,我返回一些数据作为流结果,因为我需要在Action类中获取数据表单值栈。 – 2011-02-19 09:08:31