Package org.apache.struts.action

Examples of org.apache.struts.action.ActionForm


                    + mapping.getScope()
                    + "' under attribute key '"
                    + attribute
                    + "'");
        }
        ActionForm instance = null;
        HttpSession session = null;
        if ("request".equals(mapping.getScope())) {
            instance = (ActionForm) request.getAttribute(attribute);
        } else {
            session = request.getSession();
            instance = (ActionForm) session.getAttribute(attribute);
        }

        // 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);

    }
View Full Code Here


                }
            } else {
                log.trace("  No form bean for this action");
            }
        }
        ActionForm result =
            super.processActionForm(request, response, mapping);
        if (log.isDebugEnabled()) {
            log.debug("Standard action form returned " +
                      result);
        }
View Full Code Here

                }
            } else {
                log.trace("  No form bean for this action");
            }
        }
        ActionForm result =
            super.processActionForm(request, response, mapping);
        if (log.isDebugEnabled()) {
            log.debug("Standard action form returned " +
                      result);
        }
View Full Code Here

     * @see org.directwebremoting.Creator#getInstance()
     */
    public Object getInstance() throws InstantiationException
    {
        // fills for the first time the moduleConfig
        ActionForm formInstance = (ActionForm) WebContextFactory.get().getSession().getAttribute(formBean);
        if (formInstance == null)
        {
            throw new InstantiationException("Can't find formInstance  for " + formBean);
        }

View Full Code Here

        assert name != null : mapping.getPath();
        if ( name == null ) return null;

        FormBeanConfig config = moduleConfig.findFormBeanConfig( name );
        ActionForm instance;
       
        //
        // Create the form bean.  There's special handling for dyna-form-beans.
        //
        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() + '\'' );
                }
            }
            catch ( Exception e )
            {
                _log.error( servlet.getInternal().getMessage( "formBean", config.getType() ), e );
                return null;
            }
        }
        else
        {
            try
            {
                instance = ( ActionForm ) InternalUtils.newReloadableInstance( config.getType(), getServletContext() );
               
                if ( _log.isDebugEnabled() )
                {
                    _log.debug( " Creating new ActionForm instance " + "of type '" + config.getType() + '\'' );
                }
            }
            catch ( Exception e )
            {
                _log.error( servlet.getInternal().getMessage( "formBean", config.getType() ), e );
                return null;
            }
        }
       
        instance.setServlet( servlet );
        return instance;
    }
View Full Code Here

        // This happens when a pageflow action forwards to another pageflow,
        // whose begin action expects a form.  In this case, the form is already
        // constructed, and shouldn't be instantiated anew or populated from request
        // parameters.
        //
        ActionForm previousForm = InternalUtils.getForwardedFormBean( request, false );
       
        if ( previousForm != null )
        {
            //
            // If there was a forwarded form, and if this action specifies a pageflow-scoped form member,
            // set the member with this form.
            //
            if ( formMemberField != null )
            {
                try
                {
                    FlowController fc = PageFlowRequestWrapper.get( request ).getCurrentFlowController();
                    assert fc != null : "no FlowController in request " + request.getRequestURI();
                    formMemberField.set( fc, InternalUtils.unwrapFormBeanpreviousForm ) );
                }
                catch ( IllegalAccessException e )
                {
                    _log.error( "Could not access page flow member " + formMemberField.getName()
                                  + " as the form bean.", e );
                }
            }
           
            //
            // Return the forwarded form.
            //
            previousForm.setServlet( servlet );
            return previousForm;
        }
       
        //
        // First see if the previous action put a pageflow-scoped form in the request.  If so, remove it;
        // we don't want a normal request-scoped action to use this pageflow-scoped form.
        //
        String pageFlowScopedFormName = PageFlowRequestWrapper.get( request ).getPageFlowScopedFormName();
        if ( pageFlowScopedFormName != null )
        {
            request.removeAttribute( pageFlowScopedFormName );
            PageFlowRequestWrapper.get( request ).setPageFlowScopedFormName( null );
        }
       
        //
        // If this action specifies a pageflow-scoped form member variable, use it.
        //
        if ( formMemberField != null )
        {
            try
            {
                FlowController fc = PageFlowRequestWrapper.get( request ).getCurrentFlowController();
                ActionForm form = InternalUtils.wrapFormBean( formMemberField.get( fc ) );
               
                if ( form == null ) // the pageflow hasn't filled the value yet
                {
                    form = createActionForm( mapping, request );
                    form.reset( mapping, request );
                    formMemberField.set( fc, InternalUtils.unwrapFormBean( form ) );
                }
               
                //
                // Store the form in the right place in the request, so Struts can see it.
                // But, mark a flag so we know to remove this on the next action request -- we don't
                // want this form used by another action unless that action uses the pageflow-scoped
                // form.
                //
                String formAttrName = mapping.getAttribute();
                request.setAttribute( formAttrName, form );
                PageFlowRequestWrapper.get( request ).setPageFlowScopedFormName( formAttrName );
                return form;
            }
            catch ( IllegalAccessException e )
            {
                _log.error( "Could not access page flow member " + formMemberField.getName() + " as the form bean.", e );
            }
        }
       
        ActionForm bean = super.processActionForm( request, response, mapping );
        if ( bean == null )
        {
            bean = InternalUtils.createActionForm( mapping, moduleConfig, servlet, getServletContext() );
        }
       
View Full Code Here

        throws ServletException
    {
        //
        // If a previous action forwarded us a form, use that -- don't populate it from request parameters.
        //
        ActionForm previousForm = InternalUtils.getForwardedFormBean( request, true );

        if ( previousForm != null )
        {
            return;
        }
View Full Code Here

        if ( fc != null )
        {
            try
            {
                ActionMapping mapping = InternalUtils.getCurrentActionMapping( request );
                ActionForm form = InternalUtils.getCurrentActionForm( request );
                ActionForward fwd = fc.handleException( th, mapping, form, request, response );
                processForwardConfig( request, response, fwd );
                return true;
            }
            catch ( Throwable t )
View Full Code Here

            //
            if ( fwd instanceof PageFlowActionForward )
            {
                ActionMapping mapping = ( ActionMapping ) request.getAttribute( Globals.MAPPING_KEY );
                assert mapping != null;
                ActionForm form = InternalUtils.getFormBean( mapping, request );
                Forward pfFwd = new Forward( ( ActionForward ) fwd, servletContext );
                ActionForwardHandler handler = _handlers.getActionForwardHandler();
                fwd = handler.doForward( context, pfFwd, mapping, InternalUtils.getActionName( mapping ), null, form );
            }
           
View Full Code Here

                                     HttpServletResponse response )
    {
        try
        {
            ActionMapping mapping = InternalUtils.getCurrentActionMapping( request );
            ActionForm form = InternalUtils.getCurrentActionForm( request );
            ActionForward fwd = fc.handleException( th, mapping, form, request, response );
            fc.getRequestProcessor().doActionForward( request, response, fwd );
            return true;
        }
        catch ( Throwable t )
View Full Code Here

TOP

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

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.