Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-5261

Refactor TagUtils#getStack()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Major
    • Resolution: Fixed
    • None
    • 6.2.0
    • Core, Core Tags
    • None

    Description

      Such code

      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();
              }
      

      should be replaced with an exception, if stack is null, it means tag was used out of action scope.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              lukaszlenart Lukasz Lenart
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 40m
                  40m