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

Reply via email to