Examples of FormBeanConfig


Examples of org.apache.struts.config.FormBeanConfig

        if (LOG.isTraceEnabled()) {
            LOG.trace("Look up form-bean " + name);
        }

        // Look up the corresponding FormBeanConfig (if any)
        FormBeanConfig formBeanConfig =
            actionConfig.getModuleConfig().findFormBeanConfig(name);

        if (formBeanConfig == null) {
            LOG.warn("No FormBeanConfig found in module "
                + actionConfig.getModuleConfig().getPrefix() + " under name "
                + name);
            actionCtx.setActionForm(null);

            return (false);
        }

        Map scope = actionCtx.getScope(actionConfig.getScope());

        ActionForm instance;

        instance = (ActionForm) scope.get(actionConfig.getAttribute());

        // Can we recycle the existing instance (if any)?
        if (!formBeanConfig.canReuse(instance)) {
            instance = formBeanConfig.createActionForm(actionCtx);
        }

        // TODO: Remove ServletActionContext when ActionForm no longer
        //  directly depends on ActionServlet
        if (actionCtx instanceof ServletActionContext) {
View Full Code Here

Examples of org.apache.struts.config.FormBeanConfig

        if (name == null) {
            return;
        }

        // Look up the FormBeanConfig we are processing
        FormBeanConfig fbConfig = moduleConfig.findFormBeanConfig(name);
        if (fbConfig == null) {
            throw new IllegalArgumentException("Cannot find form bean '" +
                                               name + "' configuration");
        }

        // Does a usable form bean attribute already exist?
        String attribute = actionConfig.getAttribute();
        String scope = actionConfig.getScope();
        ActionForm instance = null;
        if ("request".equals(scope)) {
            instance = (ActionForm)
                context.getExternalContext().getRequestMap().get(attribute);
        } else if ("session".equals(scope)) {
            HttpSession session = (HttpSession)
                context.getExternalContext().getSession(true);
            instance = (ActionForm)
                context.getExternalContext().getSessionMap().get(attribute);
        }
        if (instance != null) {
            if (fbConfig.getDynamic()) {
                String className =
                    ((DynaBean) instance).getDynaClass().getName();
                if (className.equals(fbConfig.getName())) {
                    if (log.isDebugEnabled()) {
                        log.debug
                            (" Recycling existing DynaActionForm instance " +
                             "of type '" + className + "'");
                    }
                    return;
                }
            } else {
                try {
                    Class configClass =
                        RequestUtils.applicationClass(fbConfig.getType());
                    if (configClass.isAssignableFrom(instance.getClass())) {
                        if (log.isDebugEnabled()) {
                            log.debug
                                (" Recycling existing ActionForm instance " +
                                 "of class '" + instance.getClass().getName()
                                 + "'");
                        }
                        return;
                    }
                } catch (Throwable t) {
                    throw new IllegalArgumentException
                        ("Cannot load form bean class '" +
                         fbConfig.getType() + "'");
                }
            }
        }

        // Create a new form bean instance
        if (fbConfig.getDynamic()) {
            try {
                DynaActionFormClass dynaClass =
                    DynaActionFormClass.createDynaActionFormClass(fbConfig);
                instance = (ActionForm) dynaClass.newInstance();
                if (log.isDebugEnabled()) {
                    log.debug
                        (" Creating new DynaActionForm instance " +
                         "of type '" + fbConfig.getType() + "'");
                    log.trace(" --> " + instance);
                }
            } catch (Throwable t) {
                throw new IllegalArgumentException
                    ("Cannot create form bean of type '" +
                     fbConfig.getType() + "'");
            }
        } else {
            try {
                instance = (ActionForm)
                    RequestUtils.applicationInstance(fbConfig.getType());
                if (log.isDebugEnabled()) {
                    log.debug
                        (" Creating new ActionForm instance " +
                         "of type '" + fbConfig.getType() + "'");
                    log.trace(" --> " + instance);
                }
            } catch (Throwable t) {
                throw new IllegalArgumentException
                    ("Cannot create form bean of class '" +
                     fbConfig.getType() + "'");
            }
        }

        // Configure and cache the form bean instance in the correct scope
        ActionServlet servlet = (ActionServlet)
View Full Code Here

Examples of org.apache.struts.config.FormBeanConfig

                PageContext.REQUEST_SCOPE);
            throw e;
        }

        // Look up the form bean definition
        FormBeanConfig formBeanConfig =
            moduleConfig.findFormBeanConfig(mapping.getName());

        if (formBeanConfig == null) {
            JspException e = null;

            if (mapping.getName() == null) {
                e = new JspException(messages.getMessage("formTag.name", calcAction));
            } else {
                e = new JspException(messages.getMessage("formTag.formBean",
                            mapping.getName(), calcAction));
            }

            pageContext.setAttribute(Globals.EXCEPTION_KEY, e,
                PageContext.REQUEST_SCOPE);
            throw e;
        }

        // Calculate the required values
        beanName = mapping.getAttribute();
        beanScope = mapping.getScope();
        beanType = formBeanConfig.getType();
    }
View Full Code Here

Examples of org.apache.struts.config.FormBeanConfig

        ModuleConfigImpl moduleConfig = new ModuleConfigImpl("/");

        context.setModuleConfig(moduleConfig);

        FormBeanConfig fooFBC = new FormBeanConfig();

        fooFBC.setName("foo");
        fooFBC.setType("org.apache.struts.mock.MockFormBean");
        moduleConfig.addFormBeanConfig(fooFBC);

        FormBeanConfig barFBC = new FormBeanConfig();

        barFBC.setName("bar");
        barFBC.setType("org.apache.struts.action.DynaActionForm"); // use a different type so we can verify lookups better

        FormPropertyConfig fpc = new FormPropertyConfig();

        fpc.setName("property");
        fpc.setType("java.lang.String");
        fpc.setInitial("test");
        barFBC.addFormPropertyConfig(fpc);
        moduleConfig.addFormBeanConfig(barFBC);

        ActionConfig testActionConfig = new ActionConfig();

        testActionConfig.setPath("/Test");
View Full Code Here

Examples of org.apache.struts.config.FormBeanConfig

        ModuleConfigFactory factoryObject = ModuleConfigFactory.createFactory();

        moduleConfig = factoryObject.createModuleConfig("");

        // Setup the base form
        baseFormBean = new FormBeanConfig();
        baseFormBean.setName("baseForm");
        baseFormBean.setType("org.apache.struts.action.DynaActionForm");

        // Set up id, name, and score
        FormPropertyConfig property = new FormPropertyConfig();
View Full Code Here

Examples of org.apache.struts.config.FormBeanConfig

     * Test that initModuleFormBeans throws an exception when a form with a
     * null type is present.
     */
    public void testInitModuleFormBeansNullFormType()
        throws ServletException {
        FormBeanConfig formBean = new FormBeanConfig();

        formBean.setName("noTypeForm");
        moduleConfig.addFormBeanConfig(formBean);

        try {
            actionServlet.initModuleFormBeans(moduleConfig);
            fail("An exception should've been thrown here.");
View Full Code Here

Examples of org.apache.struts.config.FormBeanConfig

        CustomFormBeanConfig customBase = new CustomFormBeanConfig();

        customBase.setName("customBase");
        moduleConfig.addFormBeanConfig(customBase);

        FormBeanConfig customSub = new FormBeanConfig();

        customSub.setName("customSub");
        customSub.setExtends("customBase");
        customSub.setType("org.apache.struts.action.DynaActionForm");
        moduleConfig.addFormBeanConfig(customSub);

        FormBeanConfig result =
            actionServlet.processFormBeanConfigClass(customSub, moduleConfig);

        assertTrue("Incorrect class of form bean config",
            result instanceof CustomFormBeanConfig);
        assertEquals("Incorrect name", customSub.getName(), result.getName());
        assertEquals("Incorrect type", customSub.getType(), result.getType());
        assertEquals("Incorrect extends", customSub.getExtends(),
            result.getExtends());
        assertEquals("Incorrect 'restricted' value", customSub.isRestricted(),
            result.isRestricted());

        assertSame("Result was not registered in the module config", result,
            moduleConfig.findFormBeanConfig("customSub"));
    }
View Full Code Here

Examples of org.apache.struts.config.FormBeanConfig

     */
    public void testProcessFormBeanConfigClassNoExtends()
        throws Exception {
        moduleConfig.addFormBeanConfig(baseFormBean);

        FormBeanConfig result = null;

        try {
            result =
                actionServlet.processFormBeanConfigClass(baseFormBean,
                    moduleConfig);
View Full Code Here

Examples of org.apache.struts.config.FormBeanConfig

     */
    public void testProcessFormBeanConfigClassSubFormCustomClass()
        throws Exception {
        moduleConfig.addFormBeanConfig(baseFormBean);

        FormBeanConfig customSub = new FormBeanConfig();

        customSub.setName("customSub");
        customSub.setExtends("baseForm");
        moduleConfig.addFormBeanConfig(customSub);

        FormBeanConfig result =
            actionServlet.processFormBeanConfigClass(customSub, moduleConfig);

        assertSame("The instance returned should be the param given it.",
            customSub, result);
    }
View Full Code Here

Examples of org.apache.struts.config.FormBeanConfig

        CustomFormBeanConfigArg customBase =
            new CustomFormBeanConfigArg("customBase");

        moduleConfig.addFormBeanConfig(customBase);

        FormBeanConfig customSub = new FormBeanConfig();

        customSub.setName("customSub");
        customSub.setExtends("customBase");
        moduleConfig.addFormBeanConfig(customSub);

        try {
            actionServlet.processFormBeanConfigClass(customSub, moduleConfig);
            fail("Exception should be thrown");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.