Advanced Wildcard Mappings Parameters not found in Prepare() method

久未见 提交于 2019-11-27 02:07:18

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.

@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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!