Struts2のアプリケーション全体のバルエスタックライフサイクルですか?

StackOverflow https://stackoverflow.com/questions/5037561

質問

私はいくつかの方法で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().    
.

これら4つの設定方法のそれぞれのライフサイクルについて知りたいです。アプリケーション間のものです。 ValueStack はすべての要求を作成し、アプリケーションとセッションの値はリクエストごとに設定されますか?

私は4番目の方法が最も一般的なアプローチであることを知っていますが、アクションクラスが簡単にアクセスできないすべての場所でそれを使用していない可能性があります。

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 がアクセスしていることを理解しています、私は異なる根元であり、それはバルエスタックであるデフォルトルートの子です。 8番目にデフォルトのルートから検索が開始されます。

私は http://struts.apache.org/2.1.2/ctruts2-core/apidocs/com/opensymphony/xwork2/util/valuestack.html とむしろこのリンク http://www.opensymphony.com/ognl/html/developerguide/introduction.html#EmbedDognl

これらすべてがstack.getContext().put()メソッドを使用することはほとんどないと、URLを明確にに設定することによって値が明確になることができますか?debug= browser 。私が間違っているのなら私に助言します。

役に立ちましたか?

解決

The ValueStack is per-request. If you place values on the stack, they are accessible later in the request (i.e., in the view layer), but would not survive a redirect, which would be a new HTTP request and have its own ValueStack.

Under normal conditions, parameters in the URL or in a form post would be set on the action using the action's setter methods. In an interceptor, you can add values directly to the stack. For example, the ExceptionMappingInterceptor uses the stack.push(Object) method to publish exceptions for use on error pages.

  • stack.getContext().put(String, Object) -- Places the key/value into a map that lives on the stack. The map represents the context of the stack.
  • stack.set(String, Object) -- Places the key/value into a map that lives on the stack. I'm not sure how this relates to the previous method, other than it is a different map.
  • stack.push(Object) -- This places the object on the root of the stack.

You shouldn't need to place anything on the stack from within the view layer, so I'm curious what you are trying to do that necessitates that.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top