Search in sources :

Example 16 with ActionForm

use of org.apache.struts.action.ActionForm in project sonarqube by SonarSource.

the class ExceptionHandler method handle.

// ------------------------------------------------------- Protected Methods
protected ForwardConfig handle(ActionContext context, Exception exception, ExceptionConfig exceptionConfig, ActionConfig actionConfig, ModuleConfig moduleConfig) throws Exception {
    // Look up the remaining properties needed for this handler
    ServletActionContext sacontext = (ServletActionContext) context;
    ActionForm actionForm = (ActionForm) sacontext.getActionForm();
    HttpServletRequest request = sacontext.getRequest();
    HttpServletResponse response = sacontext.getResponse();
    // Handle this exception
    org.apache.struts.action.ExceptionHandler handler = (org.apache.struts.action.ExceptionHandler) ClassUtils.getApplicationInstance(exceptionConfig.getHandler());
    return (handler.execute(exception, exceptionConfig, (ActionMapping) actionConfig, actionForm, request, response));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AbstractExceptionHandler(org.apache.struts.chain.commands.AbstractExceptionHandler) ActionMapping(org.apache.struts.action.ActionMapping) ActionForm(org.apache.struts.action.ActionForm) ServletActionContext(org.apache.struts.chain.contexts.ServletActionContext) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 17 with ActionForm

use of org.apache.struts.action.ActionForm in project sonarqube by SonarSource.

the class RequestUtils method createActionForm.

/**
     * <p>Create and return an <code>ActionForm</code> instance appropriate to
     * the information in <code>config</code>.</p>
     *
     * <p>Does not perform any checks to see if an existing ActionForm exists
     * which could be reused.</p>
     *
     * @param config  The configuration for the Form bean which is to be
     *                created.
     * @param servlet The action servlet
     * @return ActionForm instance associated with this request
     */
public static ActionForm createActionForm(FormBeanConfig config, ActionServlet servlet) {
    if (config == null) {
        return (null);
    }
    ActionForm instance = null;
    // Create and return a new form bean instance
    try {
        instance = config.createActionForm(servlet);
        if (log.isDebugEnabled()) {
            log.debug(" Creating new " + (config.getDynamic() ? "DynaActionForm" : "ActionForm") + " instance of type '" + config.getType() + "'");
            log.trace(" --> " + instance);
        }
    } catch (Throwable t) {
        log.error(servlet.getInternal().getMessage("formBean", config.getType()), t);
    }
    return (instance);
}
Also used : ActionForm(org.apache.struts.action.ActionForm)

Example 18 with ActionForm

use of org.apache.struts.action.ActionForm in project sonarqube by SonarSource.

the class ConfigHelper method getActionForm.

/*
     * <p>
     * Retrieve and return the <code>ActionForm</code> bean associated with
     * this mapping, creating and stashing one if necessary.  If there is no
     * form bean associated with this mapping, return <code>null</code>.
     * </p>
     */
public ActionForm getActionForm() {
    // Is there a mapping associated with this request?
    ActionMapping mapping = getMapping();
    if (mapping == null) {
        return (null);
    }
    // Is there a form bean associated with this mapping?
    String attribute = mapping.getAttribute();
    if (attribute == null) {
        return (null);
    }
    // Look up the existing form bean, if any
    ActionForm instance;
    if ("request".equals(mapping.getScope())) {
        instance = (ActionForm) this.request.getAttribute(attribute);
    } else {
        instance = (ActionForm) this.session.getAttribute(attribute);
    }
    return instance;
}
Also used : ActionMapping(org.apache.struts.action.ActionMapping) ActionForm(org.apache.struts.action.ActionForm)

Example 19 with ActionForm

use of org.apache.struts.action.ActionForm in project sonarqube by SonarSource.

the class TestCopyFormToContext method testLookupByNameAndRequestScope.

public void testLookupByNameAndRequestScope() throws Exception {
    CopyFormToContext command = new CopyFormToContext();
    String formName = "foo";
    command.setFormName(formName);
    command.setScope("request");
    command.setToKey(POST_EXECUTION_CONTEXT_KEY);
    assertNull(context.get(POST_EXECUTION_CONTEXT_KEY));
    assertNull(context.getRequestScope().get(formName));
    assertNull(context.getSessionScope().get(formName));
    command.execute(context);
    assertNotNull(context.get(POST_EXECUTION_CONTEXT_KEY));
    assertNotNull(context.getRequestScope().get(formName));
    assertNull(context.getSessionScope().get(formName));
    assertSame(context.get(POST_EXECUTION_CONTEXT_KEY), context.getRequestScope().get(formName));
    ActionForm theForm = (ActionForm) context.get(POST_EXECUTION_CONTEXT_KEY);
    assertTrue(theForm instanceof MockFormBean);
}
Also used : ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm) MockFormBean(org.apache.struts.mock.MockFormBean)

Example 20 with ActionForm

use of org.apache.struts.action.ActionForm in project sonarqube by SonarSource.

the class TestCopyFormToContext method testLookupByActionPath.

public void testLookupByActionPath() throws Exception {
    CopyFormToContext command = new CopyFormToContext();
    command.setActionPath("/Test");
    command.setToKey(POST_EXECUTION_CONTEXT_KEY);
    // we know this, even though it's not being used for the lookup.
    String formName = "foo";
    assertNull(context.get(POST_EXECUTION_CONTEXT_KEY));
    assertNull(context.getRequestScope().get(formName));
    assertNull(context.getSessionScope().get(formName));
    command.execute(context);
    assertNotNull(context.get(POST_EXECUTION_CONTEXT_KEY));
    assertNotNull(context.getRequestScope().get(formName));
    assertNull(context.getSessionScope().get(formName));
    assertSame(context.get(POST_EXECUTION_CONTEXT_KEY), context.getRequestScope().get(formName));
    ActionForm theForm = (ActionForm) context.get(POST_EXECUTION_CONTEXT_KEY);
    assertTrue(theForm instanceof MockFormBean);
}
Also used : ActionForm(org.apache.struts.action.ActionForm) DynaActionForm(org.apache.struts.action.DynaActionForm) MockFormBean(org.apache.struts.mock.MockFormBean)

Aggregations

ActionForm (org.apache.struts.action.ActionForm)25 DynaActionForm (org.apache.struts.action.DynaActionForm)12 ActionMapping (org.apache.struts.action.ActionMapping)9 MockFormBean (org.apache.struts.mock.MockFormBean)5 ActionConfig (org.apache.struts.config.ActionConfig)4 Map (java.util.Map)3 FormBeanConfig (org.apache.struts.config.FormBeanConfig)3 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 Enumeration (java.util.Enumeration)1 HashMap (java.util.HashMap)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 HttpSession (javax.servlet.http.HttpSession)1 DynaBean (org.apache.commons.beanutils.DynaBean)1 MutableDynaClass (org.apache.commons.beanutils.MutableDynaClass)1 Action (org.apache.struts.action.Action)1 ActionErrors (org.apache.struts.action.ActionErrors)1