You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Kr...@ext.ec.europa.eu on 2008/07/17 09:11:30 UTC

[S2-ActionComponent] Action not on the stack while evaluating body

Hello,

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...


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


Re: [S2-ActionComponent] Action not on the stack while evaluating body

Posted by beaumkr <kr...@ext.ec.europa.eu>.
thanks for the reply, 

I created https://issues.apache.org/struts/browse/WW-2724
and started changing my code to using AJAX for the form...but I'd prefer
this solution...

best regards,
Kris


Jeromy Evans - Blue Sky Minds wrote:
> 
> 
> Thorough analysis! I cringe thinking of how much time it's cost you as 
> I've been there myself.  Unfortunately the s:action tag contains several 
> major bugs like this (browse JIRA); another major one is that 
> ThreadLocal context is replaced by the nested action's context and is 
> never restored afterwards, potentially causing problems for tags AFTER 
> the closing action tag. 
> 
> I recommended you raise the issue in JIRA and not to use the s:action 
> tag as a component like this.  It's only useful in the simplest cases.
> 
> regards,
>  Jeromy Evans
> 
> PS. it's usually best to describe the problem the top of the email, 
> otherwise we trail off before reaching the end (speaking for myself 
> anyway, although I got there eventually).
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2-ActionComponent--Action-not-on-the-stack-while-evaluating-body-tp18502819p18523087.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [S2-ActionComponent] Action not on the stack while evaluating body

Posted by Jeromy Evans <je...@blueskyminds.com.au>.
Kris.BEAUMONT@ext.ec.europa.eu wrote:
> Hello,
>
> 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:
>   
Thorough analysis! I cringe thinking of how much time it's cost you as 
I've been there myself.  Unfortunately the s:action tag contains several 
major bugs like this (browse JIRA); another major one is that 
ThreadLocal context is replaced by the nested action's context and is 
never restored afterwards, potentially causing problems for tags AFTER 
the closing action tag. 

I recommended you raise the issue in JIRA and not to use the s:action 
tag as a component like this.  It's only useful in the simplest cases.

regards,
 Jeromy Evans

PS. it's usually best to describe the problem the top of the email, 
otherwise we trail off before reaching the end (speaking for myself 
anyway, although I got there eventually).



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org