Struts 2
  1. Struts 2
  2. WW-3742

Using dispatcher FORWARD on FilterDispatcher causes ValueStack to be reseted

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Not A Problem
    • Affects Version/s: 2.3.1.1
    • Fix Version/s: Future
    • Component/s: Dispatch Filter
    • Labels:
      None
    • Environment:

      Windows 7, Apache Tomcat 5.5.34

    • Flags:
      Important

      Description

      I need to allow struts 2 filter to work on Forward requests. The reason why I need it - we need to implement SEO Friendly urls with http://www.tuckey.org/urlrewrite/.
      And to make it work transparent for user, the above module does forward of all requests from user friendly url to "struts-friendly url"

      I have added the following filter mapping to web.xml to allow struts filter to be invoked on forward:

          <filter>
              <filter-name>struts2</filter-name>
              <filter-class>
                  org.apache.struts2.dispatcher.FilterDispatcher
              </filter-class>
          </filter>
      ....
          <filter-mapping>
              <filter-name>struts2</filter-name>
              <url-pattern>/*</url-pattern>
               <dispatcher>REQUEST</dispatcher>
               <dispatcher>FORWARD</dispatcher>
          </filter-mapping>
      

      Also in my struts.xml I have the following constant set

      <constant name="struts.locale" value="ru_RU"/>

      Just to note that I have all keys ONLY in MyResource_ru.properties defined.
      MyResource.properties - has no keys at all

      Now a few experiment that I perform:
      1) If I call <s:text name="some.key"/> on jsp - text is rendered correctly and retrieved from "_ru" resource bundle
      2) Now if I call from my action or from JSP using OGNL "getText" method on key that exists in "_ru" resource bundle, but do not exists in default resource bundle, I got key returned itself (e.g. "some.key")

      I've debugged the following method in LocalizedTextUtil class

          public static String findText(Class aClass, String aTextName, Locale locale, String defaultMessage, Object[] args) {
              ValueStack valueStack = ActionContext.getContext().getValueStack();
              return findText(aClass, aTextName, locale, defaultMessage, args, valueStack);
      
          }
      

      SO, during <s:text> call "valueStack.context" property, contains 22 values. There is also "locale" defined, so retrieval of key from resource bundle works correctly.
      But during call to "getText" method, "valueStack.context" contains only 7 values. And locale is set to en_US

      So looks like context is not initialized

        Activity

        Hide
        Oleg added a comment -

        Stating the obvious - without <dispatcher> tags in web.xml, everything works correctly.

        Show
        Oleg added a comment - Stating the obvious - without <dispatcher> tags in web.xml, everything works correctly.
        Hide
        Lukasz Lenart added a comment -

        Did you try to use org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter ?

        Show
        Lukasz Lenart added a comment - Did you try to use org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter ?
        Hide
        Lukasz Lenart added a comment -

        More details [1], FilterDispatcher is deprecated

        [1] http://struts.apache.org/2.x/docs/webxml.html

        Show
        Lukasz Lenart added a comment - More details [1] , FilterDispatcher is deprecated [1] http://struts.apache.org/2.x/docs/webxml.html
        Hide
        Oleg added a comment -

        WoW! Just tried it and it seems to solve the problem.
        Do you foresee any side effects of using "StrutsPrepareAndExecuteFilter" instead of "FilterDispatcher"?

        Is "StrutsPrepareAndExecuteFilter" is actually recommended filter?

        Show
        Oleg added a comment - WoW! Just tried it and it seems to solve the problem. Do you foresee any side effects of using "StrutsPrepareAndExecuteFilter" instead of "FilterDispatcher"? Is "StrutsPrepareAndExecuteFilter" is actually recommended filter?
        Hide
        Lukasz Lenart added a comment -

        StrutsPrepareAndExecuteFilter is preferred and the old FilterDispatcher will be removed as from 2.5 version.

        Show
        Lukasz Lenart added a comment - StrutsPrepareAndExecuteFilter is preferred and the old FilterDispatcher will be removed as from 2.5 version.
        Hide
        Oleg added a comment -

        Thanks! Than issue can be closed

        Show
        Oleg added a comment - Thanks! Than issue can be closed

          People

          • Assignee:
            Unassigned
            Reporter:
            Oleg
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development