View Javadoc

    1   /*
    2    * $Id: ActionFormResetInterceptor.java 478625 2006-11-23 17:31:52Z wsmoak $
    3    *
    4    * Copyright 2000-2004 The Apache Software Foundation.
    5    *
    6    * Licensed under the Apache License, Version 2.0 (the "License");
    7    * you may not use this file except in compliance with the License.
    8    * You may obtain a copy of the License at
    9    *
    10   *      http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18
    19  package org.apache.struts2.s1;
    20
    21  import javax.servlet.http.HttpServletRequest;
    22
    23  import org.apache.struts.action.ActionForm;
    24  import org.apache.struts.action.ActionMapping;
    25  import org.apache.struts2.ServletActionContext;
    26  import org.apache.struts2.dispatcher.Dispatcher;
    27
    28  import com.opensymphony.xwork2.ActionInvocation;
    29  import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
    30  import com.opensymphony.xwork2.interceptor.ScopedModelDriven;
    31
    32  /***
    33   *  Calls the reset() method on the ActionForm, if it exists.
    34   */
    35  public class ActionFormResetInterceptor extends AbstractInterceptor {
    36
    37      @Override
    38      public String intercept(ActionInvocation invocation) throws Exception {
    39          Object action = invocation.getAction();
    40
    41          if (action instanceof ScopedModelDriven) {
    42              ScopedModelDriven modelDriven = (ScopedModelDriven) action;
    43              Object model = modelDriven.getModel();
    44              if (model != null && model instanceof ActionForm) {
    45                  Struts1Factory factory = new Struts1Factory(Dispatcher.getInstance().getConfigurationManager().getConfiguration());
    46                  ActionMapping mapping = factory.createActionMapping(invocation.getProxy().getConfig());
    47                  HttpServletRequest req = ServletActionContext.getRequest();
    48                  ((ActionForm)model).reset(mapping, req);
    49              }
    50          }
    51          return invocation.invoke();
    52      }
    53  }