Advanced Wildcard Mappings Parameters not found in Prepare() method

前端 未结 2 1090

From the documentation: Struts2\'s Advanced Wildcard Mappings:

Advanced Wildcards

From 2.1.9+ regular expressions can be

相关标签:
2条回答
  • 2020-11-29 12:25

    @Andrea solution is the good one, but I had some problems:

    • staticParams, actionMappingParams and params interceptor are called twice
    • file upload is broken

    So, I use this really close stack instead:

    <interceptor-stack name="myOwnParamsPrepareParamsStack">
      <interceptor-ref name="exception"/>
      <interceptor-ref name="alias"/>
      <interceptor-ref name="i18n"/>
      <!-- Needed for advanced wildcards parameters setted before prepare() -->
      <interceptor-ref name="fileUpload"/>
      <interceptor-ref name="staticParams"/>
      <interceptor-ref name="actionMappingParams"/>
      <interceptor-ref name="params"/>
      <!-- /Needed for advanced wildcards parameters setted before prepare() -->
      <interceptor-ref name="checkbox"/>
      <interceptor-ref name="datetime"/>
      <interceptor-ref name="multiselect"/>
      <interceptor-ref name="servletConfig"/>
      <interceptor-ref name="prepare"/>
      <interceptor-ref name="chain"/>
      <interceptor-ref name="modelDriven"/>
      <interceptor-ref name="conversionError"/>
      <interceptor-ref name="validation">
        <param name="excludeMethods">input,back,cancel,browse</param>
      </interceptor-ref>
      <interceptor-ref name="workflow">
        <param name="excludeMethods">input,back,cancel,browse</param>
      </interceptor-ref>
    </interceptor-stack>
    

    By the way, this is based on the default paramsPrepareParamsStack and on Andrea answer.

    0 讨论(0)
  • 2020-11-29 12:37

    That parameters are not set by the ParametersInterceptor (like those coming from the JSP), but by the StaticParametersInterceptor.
    To have them filled in the prepare() method, the same trick of the paramsPrepareParamsStack must be applied.
    Since there is not an Interceptor Stack that does that out-of-the-box, you must define it.
    Starting from the defaultStack, we should create a Stack like this:

    <interceptor-stack name="allYourParamsAreBelongToUsStack">
        <interceptor-ref name="exception"/>
        <interceptor-ref name="alias"/>
        <interceptor-ref name="servletConfig"/>
        <interceptor-ref name="i18n"/>
     <!-- THE TRICK: NOW PREPARE() WILL FIND EVERYTHING SET -->     
        <interceptor-ref name="staticParams"/>
        <interceptor-ref name="actionMappingParams"/>
        <interceptor-ref name="params">
            <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
        </interceptor-ref>
     <!-- END OF THE TRICK -->
        <interceptor-ref name="prepare"/>
        <interceptor-ref name="chain"/>
        <interceptor-ref name="scopedModelDriven"/>
        <interceptor-ref name="modelDriven"/>
        <interceptor-ref name="fileUpload"/>
        <interceptor-ref name="checkbox"/>
        <interceptor-ref name="multiselect"/>
        <interceptor-ref name="staticParams"/>
        <interceptor-ref name="actionMappingParams"/>
        <interceptor-ref name="params">
            <param name="excludeParams">dojo\..*,^struts\..*,^session\..*,^request\..*,^application\..*,^servlet(Request|Response)\..*,parameters\...*</param>
        </interceptor-ref>
        <interceptor-ref name="conversionError"/>
        <interceptor-ref name="validation">
            <param name="excludeMethods">input,back,cancel,browse</param>
        </interceptor-ref>
        <interceptor-ref name="workflow">
            <param name="excludeMethods">input,back,cancel,browse</param>
        </interceptor-ref>
        <interceptor-ref name="debugging"/>
    </interceptor-stack>
    

    Note: ActionMappingParams is not needed, just included for future uses.

    Please comment in case you discover any problem related to this. AFAIK, it works flawlessly.

    0 讨论(0)
提交回复
热议问题