DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20996>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=20996

ActionForm beans plus Multiple modules can cause conflict





------- Additional Comments From [EMAIL PROTECTED]  2003-06-22 12:13 -------
PROPOSED PATCH:

Changes to org.apache.struts.utils.RequestUtils

ADD NEW METHOD:

     /**
      * Compute a "module aware" key to store the ActionForm instance under.
      * 
      * @param mapping
      * @param moduleConfig
      * @return String key value to use
      */
    public static String computeActionFormKey(ActionMapping mapping, 
ModuleConfig moduleConfig) {
        
                return mapping.getAttribute()+moduleConfig.getPrefix();
    }


CHANGED createActionForm() method.  Used generated key for lookup of ActionForm 
instances that is module aware.

     /**
     * Create (if necessary) and return an ActionForm instance appropriate
     * for this request.  If no ActionForm instance is required, return
     * <code>null</code>.
     *
     * @param request The servlet request we are processing
     * @param mapping The action mapping for this request
     * @param moduleConfig The configuration for this module
     * @param servlet The action servlet
     * @return ActionForm instance associated with this request
     */
    public static ActionForm createActionForm(
        HttpServletRequest request,
        ActionMapping mapping,
        ModuleConfig moduleConfig,
        ActionServlet servlet) {

        // 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
        String name = mapping.getName();
        FormBeanConfig config = moduleConfig.findFormBeanConfig(name);
        if (config == null) {
            return (null);
        }

                //Compute the key used to store this ActionForm instance
                String key = computeActionFormKey(mapping, moduleConfig);
                
        // Look up any existing form bean instance
        if (log.isDebugEnabled()) {
            log.debug(
                " Looking for ActionForm bean instance in scope '"
                    + mapping.getScope()
                    + "' under attribute key '"
                    + key
                    + "'");
        }
        ActionForm instance = null;
        HttpSession session = null;
        if ("request".equals(mapping.getScope())) {
            instance = (ActionForm) request.getAttribute(key);
        } else {
            session = request.getSession();
            instance = (ActionForm) session.getAttribute(key);
        }

        // Can we recycle the existing form bean instance (if there is one)?
        if (instance != null) {
            if (config.getDynamic()) {
                String className = ((DynaBean) instance).getDynaClass().getName
();
                if (className.equals(config.getName())) {
                    if (log.isDebugEnabled()) {
                        log.debug(
                            " Recycling existing DynaActionForm instance "
                                + "of type '"
                                + className
                                + "'");
                        log.trace(" --> " + instance);
                    }
                    return (instance);
                }
            } else {
                try {
                    Class configClass = applicationClass(config.getType());
                    if (configClass.isAssignableFrom(instance.getClass())) {
                        if (log.isDebugEnabled()) {
                            log.debug(
                                " Recycling existing ActionForm instance "
                                    + "of class '"
                                    + instance.getClass().getName()
                                    + "'");
                            log.trace(" --> " + instance);
                        }
                        return (instance);
                    }
                } catch (Throwable t) {
                    log.error(servlet.getInternal().getMessage("formBean", 
config.getType()), t);
                    return (null);
                }
            }
        }

        // Create and return a new form bean instance
        if (config.getDynamic()) {
            try {
                DynaActionFormClass dynaClass =
                    DynaActionFormClass.createDynaActionFormClass(config);
                instance = (ActionForm) dynaClass.newInstance();
                ((DynaActionForm) instance).initialize(mapping);
                if (log.isDebugEnabled()) {
                    log.debug(
                        " Creating new DynaActionForm instance "
                            + "of type '"
                            + config.getType()
                            + "'");
                    log.trace(" --> " + instance);
                }
            } catch (Throwable t) {
                log.error(servlet.getInternal().getMessage("formBean", 
config.getType()), t);
                return (null);
            }
        } else {
            try {
                instance = (ActionForm) applicationInstance(config.getType());
                if (log.isDebugEnabled()) {
                    log.debug(
                        " Creating new ActionForm instance "
                            + "of type '"
                            + config.getType()
                            + "'");
                    log.trace(" --> " + instance);
                }
            } catch (Throwable t) {
                log.error(servlet.getInternal().getMessage("formBean", 
config.getType()), t);
                return (null);
            }
        }
        instance.setServlet(servlet);
        return (instance);

    }


In org.apache.struts.action.RequestProcessor:

CHANGED processActionForm() method.  Used generated key for storing ActionForm 
instance that is module aware.

        /**
         * 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>.
         *
         * @param request The servlet request we are processing
         * @param response The servlet response we are creating
         * @param mapping The mapping we are using
         */
        protected ActionForm processActionForm(
                HttpServletRequest request,
                HttpServletResponse response,
                ActionMapping mapping) {

                // Create (if necessary a form bean to use
                ActionForm instance =
                        RequestUtils.createActionForm(
                                request,
                                mapping,
                                moduleConfig,
                                servlet);
                if (instance == null) {
                        return (null);
                }
                
                //compute a module aware key to store this instance under.
                String key = RequestUtils.computeActionFormKey(mapping, 
moduleConfig);

                // Store the new instance in the appropriate scope
                if (log.isDebugEnabled()) {
                        log.debug(
                                " Storing ActionForm bean instance in scope '"
                                        + mapping.getScope()
                                        + "' under attribute key '"
                                        + key
                                        + "'");
                }
                if ("request".equals(mapping.getScope())) {
                        request.setAttribute(key, instance);
                }
                else {
                        HttpSession session = request.getSession();
                        session.setAttribute(key, instance);
                }
                return (instance);

        }

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to