Domanda

Posso impostare una proprietà su ValueStack in diversi modi.

 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
.

Devo essere in grado di ottenere tutti questi valori in JSP, Freemarker e Java come

 stack.findValue() or stack.findString().    
.

Voglio sapere del ciclo di vita di ciascuno di questi 4 metodi di impostazione. È attraverso l'applicazione. È il valore Valuana creata ogni richiesta e le applicazioni e i valori di sessione sono impostati in esso per ogni richiesta?

So che il 4 ° metodo è l'approccio più comune, ma potrei non usarlo in tutti i posti, dove la classe d'azione non è facilmente accessibile.

Ho un altro dubbio sull'accesso a 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()-->
.

Voglio anche sapere come il 5 ° punto funziona in stack.getContex().put() e stack.set()? Capisco che nel 6 ° RISULDERS Sto accedendo, è una radice diversa e al 7 °, è il figlio di root predefinito, che è valido. Nell'8, inizia a cercare dalla radice predefinita.

Sono andato avanti 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 e piuttosto confusione di questo link http://www.opensymphony.com/ognl/html/developerguide/introduction.html#embeddognl

Avendo detto tutti questi sono poco inclinato a utilizzare il metodo stack.getContext().put() come posso vedere chiaramente i valori impostando l'URL come ? Debug= Browser . Avvisami se sto andando male.

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top