コード例 #1
0
  /**
   * Cache the <code>ModuleConfig</code> and <code>MessageResources</code> instances for the
   * sub-application module to be used for processing this request.
   *
   * @param actionCtx The <code>Context</code> for the current request
   * @return <code>false</code> so that processing continues
   * @throws IllegalArgumentException if no valid ModuleConfig or MessageResources can be identified
   *     for this request
   * @throws Exception if thrown by the Action class
   */
  public boolean execute(ActionContext actionCtx) throws Exception {
    String prefix = getPrefix(actionCtx);

    // Cache the corresponding ModuleConfig and MessageResources instances
    ModuleConfig moduleConfig =
        (ModuleConfig) actionCtx.getApplicationScope().get(Globals.MODULE_KEY + prefix);

    if (moduleConfig == null) {
      throw new IllegalArgumentException("No module config for prefix '" + prefix + "'");
    }

    actionCtx.setModuleConfig(moduleConfig);

    String key = Globals.MESSAGES_KEY + prefix;
    MessageResources messageResources = (MessageResources) actionCtx.getApplicationScope().get(key);

    if (messageResources == null) {
      throw new IllegalArgumentException(
          "No message resources found in application scope under " + key);
    }

    actionCtx.setMessageResources(messageResources);

    return (false);
  }
コード例 #2
0
  /**
   * Set common properties on the given <code>ActionContext</code> instance so that commands in the
   * chain can count on their presence. Note that while this method does not require that its
   * argument be an instance of <code>ServletActionContext</code>, at this time many common Struts
   * commands will be expecting to receive an <code>ActionContext</code> which is also a <code>
   * ServletActionContext</code>.
   *
   * @param context The ActionContext we are processing
   */
  protected void initializeActionContext(ActionContext context) {
    if (context instanceof ServletActionContext) {
      ((ServletActionContext) context).setActionServlet(this.servlet);
    }

    context.setModuleConfig(this.moduleConfig);
  }