}
// Session-form mode: retrieve form object from portlet session attribute.
PortletSession session = request.getPortletSession(false);
if (session == null) {
throw new PortletSessionRequiredException("Must have session when trying to bind (in session-form mode)");
}
String formAttrName = getFormSessionAttributeName(request);
Object sessionFormObject = session.getAttribute(formAttrName);
if (sessionFormObject == null) {
throw new PortletSessionRequiredException("Form object not found in session (in session-form mode)");
}
// Remove form object from porlet session: we might finish the form workflow
// in this request. If it turns out that we need to show the form view again,
// we'll re-bind the form object to the portlet session.
if (logger.isDebugEnabled()) {
logger.debug("Removing form session attribute [" + formAttrName + "]");
}
session.removeAttribute(formAttrName);
// Check the command object to make sure its valid
if (!checkCommand(sessionFormObject)) {
throw new PortletSessionRequiredException("Object found in session does not match commandClass");
}
return sessionFormObject;
}