[ 
https://issues.apache.org/struts/browse/WW-2724?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Musachy Barroso resolved WW-2724.
---------------------------------

    Resolution: Won't Fix

Documentation updated to reflect this limitation

> [S2-ActionComponent] Action not on the stack while evaluating body
> ------------------------------------------------------------------
>
>                 Key: WW-2724
>                 URL: https://issues.apache.org/struts/browse/WW-2724
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Other
>    Affects Versions: 2.1.1
>         Environment: weblogic10.0, windows XP
>            Reporter: kris beaumont
>
> as advised in the mailing list, I create a BUG request for this...
> http://www.nabble.com/-S2-ActionComponent--Action-not-on-the-stack-while-evaluating-body-td18502819.html
> I think I found a problem in struts 2.1.1 (or misunderstood the 
> documentation).
> I have an action that can search for persons (querystring for name, list of 
> persons retreived).
> I wanted to reuse that functionality for a form where a user has to be picked 
> (to be added to a group of users).
> So I did this:
> [code]
>         <div>
>             <span>choose a person: </span>
>             <s:action name="viewUsers" namespace="/security/users" 
> executeResult="false" var="usersAction">
>                 <div class="searchForm">
>                     <s:text name="search.query"/>
>                     <s:form action="addUser" id="searchForm" 
> namespace="/ref/groups">
>                         <s:textfield name="queryString" 
> value="%{#attr[usersAction].queryString}" label="search.query" 
> labelposition="left" labelSeparator=":"/>
>                         <s:submit value="OK"/>
>                     </s:form>
>                 </div>
>                 <s:hidden name="groupId" />
> .... More code with display tag table and some buttons etc....
>             </s:action>
>       </div>
> [/code]
> %{#attr[usersAction].queryString} and other variations never got evaluated, 
> and when I debug the textcomponent I can't find the usersAction on the 
> valuestack...
> I think it's because of a bug in ActionComponent that only executes the 
> action in the 'end' method so it's not yet on the stack when the body is 
> evaluated.
> More specific details:
> This is componentTagSupport:
> [code]
>     public int doStartTag() throws JspException {
>         component = getBean(getStack(), (HttpServletRequest) 
> pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
>         Container container = Dispatcher.getInstance().getContainer();
>         container.inject(component);
>        
>         populateParams();
>         boolean evalBody = component.start(pageContext.getOut());
>         if (evalBody) {
>             return component.usesBody() ? EVAL_BODY_BUFFERED : 
> EVAL_BODY_INCLUDE;
>         } else {
>             return SKIP_BODY;
>         }
>     }
> [/code]
> That returns EVAL_BODY_INCLUDE, so it'll evaluate the body, but the action is 
> not yet on the stack
> While the ActionComponent does
> [code]
>    public boolean end(Writer writer, String body) {
>         boolean end = super.end(writer, "", false);
>         try {
>             if (flush) {
>                 try {
>                     writer.flush();
>                 } catch (IOException e) {
>                     LOG.warn("error while trying to flush writer ", e);
>                 }
>             }
>             executeAction();
>             if ((getVar() != null) && (proxy != null)) {
>                 getStack().setValue("#attr['" + getVar() + "']",
>                         proxy.getAction());
>             }
>         } finally {
>             popComponentStack();
>         }
>         return end;
>     }
> [/code]
> So the action is executed and then again removed from the stack 
> (popComponentStack) before it can  be used in the body ...
> While this is in the docs (http://struts.apache.org/2.0.11.2/docs/action.html 
> ):
> [quote]
> This tag enables developers to call actions directly from a JSP page by 
> specifying the action name and an optional namespace. The body content of the 
> tag is used to render the results from the Action. Any result processor 
> defined for this action in struts.xml will be ignored, unless the 
> executeResult parameter is specified.
> Parameters can be passed to the action using nested param 
> <http://struts.apache.org/2.0.11.2/docs/param.html>  tags.
> [/quote]
> So I think the pop thing should happen in the end, but the executeAction 
> should happen in the '"start" method.
> Unless I'm making a huge thinking-error (meaning I need a vacation, which my 
> boss will certainly contend :))
> Thanks already for reading!
> Kris 

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to