You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Lukasz Lenart (Jira)" <ji...@apache.org> on 2022/11/10 20:21:00 UTC

[jira] [Created] (WW-5261) Refactor TagUtils#getStack()

Lukasz Lenart created WW-5261:
---------------------------------

             Summary: Refactor TagUtils#getStack()
                 Key: WW-5261
                 URL: https://issues.apache.org/jira/browse/WW-5261
             Project: Struts 2
          Issue Type: Improvement
          Components: Core, Core Tags
            Reporter: Lukasz Lenart
             Fix For: 6.2.0


Such code
{code:java}
if (stack == null) {

            HttpServletResponse res = (HttpServletResponse) pageContext.getResponse();
            Dispatcher du = Dispatcher.getInstance();
            if (du == null) {
                throw new ConfigurationException("The Struts dispatcher cannot be found.  This is usually caused by "+
                        "using Struts tags without the associated filter. Struts tags are only usable when the request "+
                        "has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag.");
            }
            stack = du.getContainer().getInstance(ValueStackFactory.class).createValueStack();

            HttpParameters params = HttpParameters.create(req.getParameterMap()).build();

            Map<String, Object> extraContext = du.createContextMap(new RequestMap(req),
                    params,
                    new SessionMap<>(req),
                    new ApplicationMap(pageContext.getServletContext()),
                    req,
                    res);
            extraContext.put(ServletActionContext.PAGE_CONTEXT, pageContext);
            stack.getContext().putAll(extraContext);
            req.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);

            // also tie this stack/context to the ThreadLocal
            ActionContext.of(stack.getContext()).bind();
        }
{code}
should be replaced with an exception, if {{stack}} is null, it means tag was used out of action scope.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)