Package org.apache.struts.action

Examples of org.apache.struts.action.ActionMapping


   */
  public FormData getFormData(HttpServletRequest request, String action, boolean create) {
    ActionForm form = null;

    // Look up the action mapping
    ActionMapping mapping = getActionMapping(action);
    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 form bean configuration information to use
    FormBeanConfig config =
      moduleConfig.findFormBeanConfig(mapping.getName());
    if (config == null) {
      return null;
    }

    // Look up any existing form bean instance
    if ("request".equals(mapping.getScope())) {
      form = (ActionForm) request.getAttribute(attribute);
    } else {
      form = (ActionForm) request.getSession().getAttribute(attribute);
    }

    if (form == null && create) {
      // get the action form instance
      form = RequestUtils.createActionForm(config, servlet);
      if (form == null) {
        return null;
      }
      if ("request".equals(mapping.getScope())) {
        request.setAttribute(attribute, form);
      } else {
        request.getSession().setAttribute(attribute, form);
      }
    }
View Full Code Here


   * (non-Javadoc)
   * @see de.odysseus.calyxo.forms.FormsSupport#removeFormData(javax.servlet.http.HttpServletRequest, java.lang.String)
   */
  public void removeFormData(HttpServletRequest request, String action) {
    // Look up the action mapping
    ActionMapping mapping = getActionMapping(action);
    if (mapping == null)
      return;

    // Is there a form bean associated with this mapping?
    String attribute = mapping.getAttribute();
    if (attribute == null) {
      return;
    }

    // Look up the form bean configuration information to use
    FormBeanConfig config =
      moduleConfig.findFormBeanConfig(mapping.getName());
    if (config == null) {
      return;
    }

    // Remove existing form bean instance
    if ("request".equals(mapping.getScope())) {
      request.removeAttribute(attribute);
    } else {
      request.getSession().removeAttribute(attribute);
    }
  }
View Full Code Here

   * (non-Javadoc)
   * @see de.odysseus.calyxo.forms.FormsSupport#lookupFormName(java.lang.String)
   */
  protected String lookupFormName(String action) {
    // Look up the action mapping
    ActionMapping mapping = getActionMapping(action);
    // answer the form name
    return mapping == null ? null : mapping.getName();
  }
View Full Code Here

        // to the ModuleConfig instance for the selected module
    }

    protected void setUpDefaultApp() {
        ActionFormBean formBean = null;
        ActionMapping mapping = null;

        ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();

        moduleConfig = factoryObject.createModuleConfig("");

        context.setAttribute(Globals.MODULE_KEY, moduleConfig);

        // Forward "external" to "http://jakarta.apache.org/"
        moduleConfig.addForwardConfig(new ActionForward("external",
                "http://jakarta.apache.org/", false));

        // Forward "foo" to "/bar.jsp"
        moduleConfig.addForwardConfig(new ActionForward("foo", "/bar.jsp", false));

        // Forward "relative1" to "relative.jsp" non-context-relative
        moduleConfig.addForwardConfig(new ActionForward("relative1",
                "relative.jsp", false));

        // Forward "relative2" to "relative.jsp" context-relative
        moduleConfig.addForwardConfig(new ActionForward("relative2",
                "relative.jsp", false));

        // Form Bean "static" is a standard ActionForm subclass
        formBean =
            new ActionFormBean("static", "org.apache.struts.mock.MockFormBean");
        moduleConfig.addFormBeanConfig(formBean);

        // Action "/static" uses the "static" form bean in request scope
        mapping = new ActionMapping();
        mapping.setInput("/static.jsp");
        mapping.setName("static");
        mapping.setPath("/static");
        mapping.setScope("request");
        mapping.setType("org.apache.struts.mock.MockAction");
        moduleConfig.addActionConfig(mapping);

        // Form Bean "dynamic" is a DynaActionForm with the same properties
        formBean =
            new ActionFormBean("dynamic",
                "org.apache.struts.action.DynaActionForm");
        formBean.addFormPropertyConfig(new FormPropertyConfig(
                "booleanProperty", "boolean", "false"));
        formBean.addFormPropertyConfig(new FormPropertyConfig(
                "stringProperty", "java.lang.String", null));
        moduleConfig.addFormBeanConfig(formBean);

        // Action "/dynamic" uses the "dynamic" form bean in session scope
        mapping = new ActionMapping();
        mapping.setInput("/dynamic.jsp");
        mapping.setName("dynamic");
        mapping.setPath("/dynamic");
        mapping.setScope("session");
        mapping.setType("org.apache.struts.mock.MockAction");
        moduleConfig.addActionConfig(mapping);

        // Form Bean "/dynamic0" is a DynaActionForm with initializers
        formBean =
            new ActionFormBean("dynamic0",
                "org.apache.struts.action.DynaActionForm");
        formBean.addFormPropertyConfig(new FormPropertyConfig(
                "booleanProperty", "boolean", "true"));
        formBean.addFormPropertyConfig(new FormPropertyConfig(
                "stringProperty", "java.lang.String", "String Property"));
        formBean.addFormPropertyConfig(new FormPropertyConfig("intArray1",
                "int[]", "{1,2,3}", 4)); // 4 should be ignored
        formBean.addFormPropertyConfig(new FormPropertyConfig("intArray2",
                "int[]", null, 5)); // 5 should be respected
        formBean.addFormPropertyConfig(new FormPropertyConfig("principal",
                "org.apache.struts.mock.MockPrincipal", null));
        formBean.addFormPropertyConfig(new FormPropertyConfig("stringArray1",
                "java.lang.String[]", "{aaa,bbb,ccc}", 2)); // 2 should be ignored
        formBean.addFormPropertyConfig(new FormPropertyConfig("stringArray2",
                "java.lang.String[]", null, 3)); // 3 should be respected
        moduleConfig.addFormBeanConfig(formBean);

        // Action "/dynamic0" uses the "dynamic0" form bean in request scope
        mapping = new ActionMapping();
        mapping.setName("dynamic0");
        mapping.setPath("/dynamic0");
        mapping.setScope("request");
        mapping.setType("org.apache.struts.mock.MockAction");
        moduleConfig.addActionConfig(mapping);

        // Action "/noform" has no form bean associated with it
        mapping = new ActionMapping();
        mapping.setPath("/noform");
        mapping.setType("org.apache.struts.mock.MockAction");
        moduleConfig.addActionConfig(mapping);

        // Configure global forward declarations
        moduleConfig.addForwardConfig(new ForwardConfig("moduleForward",
                "/module/forward", false)); // No redirect, same module
View Full Code Here

                "/context")); // Specify module
    }

    protected void setUpSecondApp() {
        ActionFormBean formBean = null;
        ActionMapping mapping = null;

        ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();

        moduleConfig2 = factoryObject.createModuleConfig("/2");

        context.setAttribute(Globals.MODULE_KEY + "/2", moduleConfig2);

        // Forward "external" to "http://jakarta.apache.org/"
        moduleConfig2.addForwardConfig(new ActionForward("external",
                "http://jakarta.apache.org/", false));

        // Forward "foo" to "/baz.jsp" (different from default)
        moduleConfig2.addForwardConfig(new ActionForward("foo", "/baz.jsp",
                false));

        // Forward "relative1" to "relative.jsp" non-context-relative
        moduleConfig2.addForwardConfig(new ActionForward("relative1",
                "relative.jsp", false));

        // Forward "relative2" to "relative.jsp" context-relative
        moduleConfig2.addForwardConfig(new ActionForward("relative2",
                "relative.jsp", false));

        // Form Bean "static" is a standard ActionForm subclass (same as default)
        formBean =
            new ActionFormBean("static", "org.apache.struts.mock.MockFormBean");
        moduleConfig2.addFormBeanConfig(formBean);

        // Action "/static" uses the "static" form bean in request scope (same as default)
        mapping = new ActionMapping();
        mapping.setInput("/static.jsp");
        mapping.setName("static");
        mapping.setPath("/static");
        mapping.setScope("request");
        mapping.setType("org.apache.struts.mock.MockAction");
        moduleConfig2.addActionConfig(mapping);

        // Form Bean "dynamic2" is a DynaActionForm with the same properties
        formBean =
            new ActionFormBean("dynamic2",
                "org.apache.struts.action.DynaActionForm");
        formBean.addFormPropertyConfig(new FormPropertyConfig(
                "booleanProperty", "boolean", "false"));
        formBean.addFormPropertyConfig(new FormPropertyConfig(
                "stringProperty", "java.lang.String", null));
        moduleConfig2.addFormBeanConfig(formBean);

        // Action "/dynamic2" uses the "dynamic2" form bean in session scope
        mapping = new ActionMapping();
        mapping.setInput("/dynamic2.jsp");
        mapping.setName("dynamic2");
        mapping.setPath("/dynamic2");
        mapping.setScope("session");
        mapping.setType("org.apache.struts.mock.MockAction");
        moduleConfig2.addActionConfig(mapping);

        // Action "/noform" has no form bean associated with it (same as default)
        mapping = new ActionMapping();
        mapping.setPath("/noform");
        mapping.setType("org.apache.struts.mock.MockAction");
        moduleConfig2.addActionConfig(mapping);

        // Configure global forward declarations
        moduleConfig2.addForwardConfig(new ForwardConfig("moduleForward",
                "/module/forward", false)); // No redirect, same module
View Full Code Here

     * 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);
        }

View Full Code Here

        if (action instanceof ScopedModelDriven) {
            ScopedModelDriven modelDriven = (ScopedModelDriven) action;
            Object model = modelDriven.getModel();
            if (model != null && model instanceof ActionForm) {
                Struts1Factory factory = new Struts1Factory(configuration);
                ActionMapping mapping = factory.createActionMapping(invocation.getProxy().getConfig());
                HttpServletRequest req = ServletActionContext.getRequest();
                ((ActionForm)model).reset(mapping, req);
            }
        }
        return invocation.invoke();
View Full Code Here

     */
    public void testCreateActionMapping() {
        PackageConfig packageConfig = configuration.getPackageConfig(PACKAGE_NAME);
        com.opensymphony.xwork2.config.entities.ActionConfig actionConfig =
                (com.opensymphony.xwork2.config.entities.ActionConfig) packageConfig.getActionConfigs().get("action1");
        ActionMapping mapping = factory.createActionMapping(actionConfig);
        assertNotNull(mapping);

        assertNotNull(mapping.findForward("result1"));
        assertNotNull(mapping.findForwardConfig("result2"));

        ForwardConfig[] configs = mapping.findForwardConfigs();
        assertNotNull(configs);
        assertEquals(2, configs.length);

        String[] forwards = mapping.findForwards();
        assertNotNull(forwards);
        assertEquals(2, forwards.length);
       
        ActionForward fwd = mapping.findForward("result1");
        assertNotNull(fwd);
        assertEquals("result1", fwd.getName());

        assertNotNull(mapping.findException(NullPointerException.class));
        assertNotNull(mapping.findExceptionConfig("java.lang.IllegalStateException"));

        ExceptionConfig[] exceptionConfigs = mapping.findExceptionConfigs();
        assertNotNull(exceptionConfigs);
        assertEquals(2, exceptionConfigs.length);
       
        ModuleConfig moduleConfig = mapping.getModuleConfig();
        assertNotNull(moduleConfig);
       
        // For now, the path will be null if the ActionMapping was created on its own (as opposed to from a
        // WrapperModuleConfig, which knows the path).
        assertNull(mapping.getPath());
       
        // These methods are currently not implemented -- replace as functionality is added.
        assertNYI(mapping, "getInputForward", null);
        assertNYI(mapping, "getForward", null);
        assertNYI(mapping, "getInclude", null);
View Full Code Here

            ScopedModelDriven modelDriven = (ScopedModelDriven) action;
            Object model = modelDriven.getModel();
            if (model != null) {
                HttpServletRequest req = ServletActionContext.getRequest();
                Struts1Factory strutsFactory = new Struts1Factory(configuration);
                ActionMapping mapping = strutsFactory.createActionMapping(invocation.getProxy().getConfig());
                ModuleConfig moduleConfig = strutsFactory.createModuleConfig(invocation.getProxy().getConfig().getPackageName());
                req.setAttribute(Globals.MODULE_KEY, moduleConfig);
                req.setAttribute(Globals.MESSAGES_KEY, new WrapperMessageResources((TextProvider)invocation.getAction()));
               
                mapping.setAttribute(modelDriven.getScopeKey());
               
                ActionForm form = (ActionForm) model;
                form.setServlet(new ActionServlet(){
                    public ServletContext getServletContext() {
                        return ServletActionContext.getServletContext();
View Full Code Here

        }
       
        // We should call setServlet() here, but let's stub that out later
       
        Struts1Factory strutsFactory = new Struts1Factory(Dispatcher.getInstance().getConfigurationManager().getConfiguration());
        ActionMapping mapping = strutsFactory.createActionMapping(actionConfig);
        HttpServletRequest request = ServletActionContext.getRequest();
        HttpServletResponse response = ServletActionContext.getResponse();
        ActionForward forward = action.execute(mapping, actionForm, request, response);
       
        ActionMessages messages = (ActionMessages) request.getAttribute(Globals.MESSAGE_KEY);
View Full Code Here

TOP

Related Classes of org.apache.struts.action.ActionMapping

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.