// 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.unwrapFormBean( previousForm ) );
}
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() );
}