|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectPageFlowManagedObject
FlowController
public abstract class FlowController
Base class for user-written flow controllers - PageFlowControllers and Global.app.
Field Summary | |
---|---|
protected static Locale |
defaultLocale
Deprecated. Use getDefaultLocale() . |
protected ActionServlet |
servlet
Deprecated. This variable will be removed with no replacement. In most cases, PageFlowManagedObject.getServletContext() is sufficient; for other cases, the ActionServlet itself
is in the ServletContext attribute Globals.ACTION_SERVLET_KEY . |
Constructor Summary | |
---|---|
protected |
FlowController()
Default constructor. |
Method Summary | |
---|---|
protected void |
addValidationError(String propertyName,
String messageKey)
Add a validation error that will be shown with the Errors and Error tags. |
protected void |
addValidationError(String propertyName,
String messageKey,
Object[] messageArgs)
Add a validation error that will be shown with the Errors and Error tags. |
protected void |
afterAction()
Callback that occurs after any user action method is invoked. |
protected boolean |
alwaysTrackPreviousAction()
When the current page flow does not use a @jpf:forward with a
return-to="previousAction" attribute, the following methods always return
null by default. |
protected boolean |
alwaysTrackPreviousPage()
When the current page flow does not use a @jpf:forward with either a
return-to="currentPage" or a return-to="previousPage" attribute,
the following methods always return null by default. |
protected void |
beforeAction()
Callback that occurs before any user action method is invoked. |
protected void |
delete()
|
ActionForward |
execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
Perform decision logic to determine the next URI to be displayed. |
protected String |
generateToken(HttpServletRequest request)
Deprecated. Use |
protected ActionMapping |
getActionMapping()
Get the current Struts ActionMapping, which is information from the Struts-XML <action> tag that corresponds to the current page flow action being executed. |
protected Method |
getActionMethod(String methodName,
Class argType)
Get an action handler method of the given name/signature . |
String[] |
getActions()
Get a list of the names of actions handled by methods in this PageFlowController. |
protected String |
getCurrentActionName()
Get the name of the current action being executed. |
protected DataSource |
getDataSource(HttpServletRequest request)
Return the default data source for the module associated with this page flow. |
protected DataSource |
getDataSource(HttpServletRequest request,
String key)
Return the specified data source for the current module. |
protected static Locale |
getDefaultLocale()
Get the system default locale. |
protected Locale |
getLocale()
Return the user's currently selected Locale. |
protected Locale |
getLocale(HttpServletRequest request)
Deprecated. Use getLocale() . |
protected ActionMapping |
getMapping()
Deprecated. Use getActionMapping() instead. |
ModuleConfig |
getModuleConfig()
|
ModuleConfig |
getModuleConfig(ServletContext servletContext,
HttpServletRequest request)
Gets the Struts module configuration associated with this controller. |
abstract String |
getModulePath()
Get the Struts module path for this controller. |
protected HttpServletRequest |
getRequest()
Get the current HttpServletRequest. |
protected MessageResources |
getResources()
Deprecated. This method can only return the resources for the default module. Use getResources(HttpServletRequest) to get the resources for the current module. |
protected MessageResources |
getResources(HttpServletRequest request)
Return the default message resources for the current module. |
protected MessageResources |
getResources(HttpServletRequest request,
String key)
Return the specified message resources for the current module. |
protected HttpServletResponse |
getResponse()
Get the current HttpServletResponse. |
protected ActionServlet |
getServlet()
Deprecated. This method will be removed with no replacement. In most cases, PageFlowManagedObject.getServletContext() is
sufficient; for other cases, the ActionServlet itself is in the ServletContext attribute
Globals.ACTION_SERVLET_KEY . |
protected HttpSession |
getSession()
Get the current user session. |
protected ActionForward |
handleException(Throwable ex,
ActionMapping mapping,
String actionName,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
Handle the given exception - invoke user code if appropriate and return a destination URI. |
protected ActionForward |
internalExecute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
|
protected ActionForward |
invokeActionMethod(Method method,
Object arg)
Invoke the given action handler method, passing it an argument if appropriate. |
ActionForward |
invokeExceptionHandler(Method method,
Throwable ex,
String actionName,
String message,
Object formBean,
ActionForm wrappedFormBean,
ActionMapping actionMapping,
HttpServletRequest request,
HttpServletResponse response,
boolean readonly)
Invoke the given exception handler method. |
boolean |
isAction(String name)
Tell whether a given String is the name of an action handled by a method in this PageFlowController. |
protected boolean |
isCancelled(HttpServletRequest request)
Returns true if the current form's cancel button was
pressed. |
protected boolean |
isNestable()
Tell whether this PageFlowController can be "nested", i.e., if it can be invoked from another page flow with the intention of returning to the original one. |
boolean |
isPageFlow()
Tell whether this is a PageFlowController . |
protected boolean |
isSingleton()
Tell whether this is a "singleton" page flow. |
protected boolean |
isTokenValid(HttpServletRequest request)
Return true if there is a transaction token stored in
the user's current session, and the value submitted as a request
parameter with this action matches it. |
protected boolean |
isTokenValid(HttpServletRequest request,
boolean reset)
Return true if there is a transaction token stored in
the user's current session, and the value submitted as a request
parameter with this action matches it. |
void |
login(String username,
String password)
Log in the user, using "weak" username/password authentication. |
void |
logout(boolean invalidateSessions)
Log out the current user. |
static ActionResult |
lookup(String actionName,
ServletContext context,
HttpServletRequest request,
HttpServletResponse response)
Deprecated. Use PageFlowUtils.strutsLookup(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String[]) instead. |
static ActionResult |
lookup(String actionName,
ServletContext context,
HttpServletRequest request,
HttpServletResponse response,
String actionServletClassName)
Deprecated. Use PageFlowUtils.strutsLookup(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String[]) instead. |
protected void |
onCreate()
Callback that is invoked when this controller instance is created. |
protected void |
onDestroy()
Deprecated. onDestroy(javax.servlet.http.HttpSession) should be used instead. |
protected void |
onDestroy(HttpSession session)
Callback that is invoked when this controller instance is "destroyed", i.e., removed from the user session. |
protected void |
onRefresh()
Callback that is invoked when this controller is involved in a refresh request, as can happen in a portal environment on a request where no action is run in the current page flow, but a previously-displayed JSP in the page flow is re-rendered. |
void |
refresh(HttpServletRequest request,
HttpServletResponse response)
Called on this object for non-lookup (refresh) requests. |
void |
reinitialize(HttpServletRequest request,
HttpServletResponse response,
ServletContext servletContext)
Initialize transient data that may have been lost during session failover. |
protected void |
resetToken(HttpServletRequest request)
Reset the saved transaction token in the user's session. |
String |
resolveAction(String actionName,
Object form)
Deprecated. Use resolveAction(String, Object, HttpServletRequest, HttpServletResponse) instead. |
String |
resolveAction(String actionName,
Object form,
HttpServletRequest request,
HttpServletResponse response)
Call an action and return the result URI. |
static Locale |
retrieveUserLocale(HttpServletRequest request,
String locale)
|
protected void |
saveErrors(HttpServletRequest request,
ActionErrors errors)
Save the specified error messages keys into the appropriate request attribute for use by the <html:errors> tag, if any messages are required. |
protected void |
saveMessages(HttpServletRequest request,
ActionMessages messages)
Save the specified messages keys into the appropriate request attribute for use by the <html:messages> tag (if messages="true" is set), if any messages are required. |
protected void |
saveToken(HttpServletRequest request)
Save a new transaction token in the user's current session, creating a new session if necessary. |
protected void |
sendError(String errText,
HttpServletRequest request,
HttpServletResponse response)
Send a Page Flow error to the browser. |
protected void |
sendError(String errText,
HttpServletResponse response)
Deprecated. Use sendError(String, HttpServletRequest, HttpServletResponse) instead. |
protected void |
setLocale(HttpServletRequest request,
Locale locale)
Deprecated. Use setLocale(java.util.Locale) . |
protected void |
setLocale(Locale locale)
|
Methods inherited from class PageFlowManagedObject |
---|
deleteFromSession, ensureFailover, fieldIsUninitialized, getDisplayName, getServletContext, initializeField, valueBound, valueUnbound |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface ActionResolver |
---|
getURI |
Field Detail |
---|
protected static Locale defaultLocale
getDefaultLocale()
.
protected transient ActionServlet servlet
PageFlowManagedObject.getServletContext()
is sufficient; for other cases, the ActionServlet itself
is in the ServletContext attribute Globals.ACTION_SERVLET_KEY
.
Constructor Detail |
---|
protected FlowController()
Method Detail |
---|
public void reinitialize(HttpServletRequest request, HttpServletResponse response, ServletContext servletContext)
PageFlowManagedObject
reinitialize
in class PageFlowManagedObject
public void login(String username, String password) throws LoginException
username
- the user's login namepassword
- the user's password
LoginException
- if the authentication failedpublic void logout(boolean invalidateSessions)
invalidateSessions
- if true, the session is invalidated (on all single-signon webapps);
otherwise the session and its data are left intact (except for authentication
information used internally by the server). To invalidate the session in only the
current webapp, set this parameter to false
and call
getSession()
.invalidate().protected void sendError(String errText, HttpServletResponse response) throws IOException
sendError(String, HttpServletRequest, HttpServletResponse)
instead.
errText
- the error message to display.response
- the current HttpServletResponse.
IOException
protected void sendError(String errText, HttpServletRequest request, HttpServletResponse response) throws IOException
errText
- the error message to display.response
- the current HttpServletResponse.
IOException
protected ActionForward handleException(Throwable ex, ActionMapping mapping, String actionName, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
ex
- the Exception to handle.mapping
- the Struts action mapping for current Struts action being processed.actionName
- the name of the Struts action being processed.form
- the form-bean (if any) associated with the Struts action being processed. May be null.request
- the current HttpServletRequest.response
- the current HttpServletResponse.
Exception
- if another Exception is thrown during handling of ex
.protected String getCurrentActionName()
execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
(where any user action method is invoked), and during the lifecycle
methods beforeAction()
and afterAction()
.
IllegalStateException
- if this method is invoked outside of action method
execution (i.e., outside of the call to execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
, and outside of
onCreate()
, beforeAction()
, afterAction()
.public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
mapping
- the Struts ActionMapping for the current action being processed.form
- the form-bean (if any) associated with the Struts action being processed. May be null.request
- the current HttpServletRequest.response
- the current HttpServletResponse.
Exception
- if an Exception was thrown during user action-handling code.protected ActionForward internalExecute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
Exception
public abstract String getModulePath()
getModulePath
in interface ActionResolver
PageFlowController
and "/-global" for Global.app.protected void beforeAction() throws Exception
getRequest()
,
getResponse()
, getSession()
, and getActionMapping()
may all be used
during this method. The action to be run can be discovered by calling
ActionConfig.getPath()
on the value returned from getActionMapping()
.
Exception
protected void afterAction() throws Exception
getRequest()
,
getResponse()
, getSession()
, and getActionMapping()
may all be used
during this method. The action that was run can be discovered by calling
ActionConfig.getPath()
on the value returned from getActionMapping()
.
Exception
protected void onCreate() throws Exception
getRequest()
,
getResponse()
, getSession()
may all be used during this method.
onCreate
in class PageFlowManagedObject
Exception
protected void onDestroy()
onDestroy(javax.servlet.http.HttpSession)
should be used instead.
getRequest()
, getResponse()
, and getActionMapping()
may not
be used during this method, since it may be called due to session termination outside of a
request. getSession()
also may not be used, but the session is passed as an argument
to onDestroy(javax.servlet.http.HttpSession)
, which should be used in place of this
method.
protected void onDestroy(HttpSession session)
getRequest()
, getResponse()
, and getActionMapping()
may not
be used during this method, since it may be called due to session termination outside of a
request. getSession()
also may not be used, but the session is passed as an argument.
onDestroy
in class PageFlowManagedObject
protected Method getActionMethod(String methodName, Class argType)
methodName
- the name of the action handler method to query.argType
- the type of the argument to the action handler method; if null
,
the method takes no arguments.
null
if it doesn't exist.protected ActionForward invokeActionMethod(Method method, Object arg) throws Exception
method
- the action handler method to invoke.arg
- the form-bean to pass; may be null
.
Exception
- if an Exception was raised in user code.protected final HttpServletRequest getRequest()
execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
(where
any user action method is invoked), and during the lifecycle methods onCreate()
,
beforeAction()
, afterAction()
.
IllegalStateException
- if this method is invoked outside of action method
execution (i.e., outside of the call to execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
, and outside of
onCreate()
, beforeAction()
, afterAction()
.protected final HttpServletResponse getResponse()
execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
(where
any user action method is invoked), and during the lifecycle methods onCreate()
,
beforeAction()
, afterAction()
.
IllegalStateException
- if this method is invoked outside of action method
execution (i.e., outside of the call to execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
, and outside of
onCreate()
, beforeAction()
, afterAction()
.protected final ActionMapping getMapping()
getActionMapping()
instead.
execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
(where any user action method is invoked), and during the lifecycle
methods beforeAction()
and afterAction()
.
IllegalStateException
- if this method is invoked outside of action method
execution (i.e., outside of the call to execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
, and outside of
onCreate()
, beforeAction()
, afterAction()
.protected final ActionMapping getActionMapping()
execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
(where any user action method is invoked), and during the lifecycle
methods beforeAction()
and afterAction()
.
IllegalStateException
- if this method is invoked outside of action method
execution (i.e., outside of the call to execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
, and outside of
onCreate()
, beforeAction()
, afterAction()
.protected final HttpSession getSession()
execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
(where
any user action method is invoked), and during the lifecycle methods onCreate()
,
onDestroy()
, beforeAction()
, afterAction()
.
IllegalStateException
- if this method is invoked outside of action method
execution (i.e., outside of the call to execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
, and outside of
onCreate()
, onDestroy()
, beforeAction()
, afterAction()
.public final ModuleConfig getModuleConfig()
public ModuleConfig getModuleConfig(ServletContext servletContext, HttpServletRequest request)
servletContext
- the current ServletContext.
public static ActionResult lookup(String actionName, ServletContext context, HttpServletRequest request, HttpServletResponse response) throws Exception
PageFlowUtils.strutsLookup(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String[])
instead.
PageFlowActionServlet
.
Note: this method invokes the full action-processing cycle on a ScopedRequest
. Use
resolveAction(java.lang.String, java.lang.Object, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
to resolve the URI for an action in the current page flow.
Exception
public static ActionResult lookup(String actionName, ServletContext context, HttpServletRequest request, HttpServletResponse response, String actionServletClassName) throws Exception
PageFlowUtils.strutsLookup(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String, java.lang.String[])
instead.
ScopedRequest
. Use
resolveAction(java.lang.String, java.lang.Object, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
to resolve the URI for an action in the current page flow.
Exception
public String resolveAction(String actionName, Object form, HttpServletRequest request, HttpServletResponse response) throws Exception
actionName
- the name of the action to run.form
- the form bean instance to pass to the action, or null
if none should be passed.
ActionNotFoundException
- when the given action does not exist in this page flow.
Exception
- if the action method throws an Exception.public String resolveAction(String actionName, Object form) throws Exception
resolveAction(String, Object, HttpServletRequest, HttpServletResponse)
instead.
actionName
- the name of the action to run.form
- the form bean instance to pass to the action, or null
if none should be passed.
ActionNotFoundException
- when the given action does not exist in this page flow.
Exception
- if the action method throws an Exception.public String[] getActions()
public boolean isAction(String name)
name
- the action-name to query.
true
if name
is the name of an action handled by a method in this
PageFlowController.public boolean isPageFlow()
PageFlowController
.
isPageFlow
in interface ActionResolver
true
if this is a PageFlowController
.protected ActionServlet getServlet()
PageFlowManagedObject.getServletContext()
is
sufficient; for other cases, the ActionServlet itself is in the ServletContext attribute
Globals.ACTION_SERVLET_KEY
.
public final void refresh(HttpServletRequest request, HttpServletResponse response)
refresh
in interface ActionResolver
protected void onRefresh()
protected void delete()
protected boolean isSingleton()
delete()
is called. Navigating to another page flow hides
the current singleton controller, but does not remove it.
protected boolean isNestable()
@jpf:controller nested="true"
annotation.
true
if this PageFlowController can be nested.protected boolean alwaysTrackPreviousAction()
@jpf:forward
with a
return-to="previousAction"
attribute, the following methods always return
null
by default.
alwaysTrackPreviousAction
(which always returns false
)
to enable these methods in all cases.
true
if the previous action should always be tracked, regardless
of whether return-to="previousAction"
is used.PageFlowController.getPreviousActionInfo()
,
PageFlowController.getPreviousActionURI()
,
PageFlowController.getPreviousForm()
protected boolean alwaysTrackPreviousPage()
@jpf:forward
with either a
return-to="currentPage"
or a return-to="previousPage"
attribute,
the following methods always return null
by default.
alwaysTrackPreviousPage
(which always returns false
)
to enable these methods in all cases.
true
if the previous page should always be tracked, regardless
of whether return-to="currentPage"
or return-to="previousPage"
is used.PageFlowController.getCurrentPageInfo()
,
PageFlowController.getPreviousPageInfo()
,
PageFlowController.getCurrentForwardPath()
,
PageFlowController.getPreviousForwardPath()
public ActionForward invokeExceptionHandler(Method method, Throwable ex, String actionName, String message, Object formBean, ActionForm wrappedFormBean, ActionMapping actionMapping, HttpServletRequest request, HttpServletResponse response, boolean readonly) throws Exception
method
- the action handler method to invoke.ex
- the Throwable that is to be handled.actionName
- the name of the Struts action being processed.message
- the String message that is to be passed to the handler method.formBean
- the form bean that is associated with the action being processed; may be
null
.request
- the current HttpServletRequest.response
- the current HttpServletResponse.readonly
- if true
, session failover will not be triggered after invoking the method.
Exception
- if an Exception was raised in user code.protected void addValidationError(String propertyName, String messageKey, Object[] messageArgs)
propertyName
- the name of the property with which to associate this error.messageKey
- the message-resources key for the error message.messageArgs
- an array of arguments for the error message.protected void addValidationError(String propertyName, String messageKey)
propertyName
- the name of the property with which to associate this error.messageKey
- the message-resources key for the error message.protected static Locale getDefaultLocale()
protected String generateToken(HttpServletRequest request)
request
- the current request.protected DataSource getDataSource(HttpServletRequest request)
request
- the current request.protected DataSource getDataSource(HttpServletRequest request, String key)
request
- The servlet request we are processingkey
- The key specified in the
<message-resources>
element for the
requested bundleprotected Locale getLocale(HttpServletRequest request)
getLocale()
.
request
- the current request.
protected Locale getLocale()
public static Locale retrieveUserLocale(HttpServletRequest request, String locale)
protected MessageResources getResources()
protected MessageResources getResources(HttpServletRequest request)
request
- The servlet request we are processingprotected MessageResources getResources(HttpServletRequest request, String key)
request
- the current request.key
- The bundle key specified in a
Jpf.MessageResource
annotation.
<message-resources>
element for the
requested bundleprotected boolean isCancelled(HttpServletRequest request)
Returns true
if the current form's cancel button was
pressed. This method will check if the Globals.CANCEL_KEY
request attribute has been set, which normally occurs if the cancel
button generated by CancelTag was pressed by the user
in the current request. If true
, validation performed
by an ActionForm's validate()
method
will have been skipped by the controller servlet.
request
- The servlet request we are processingCancelTag
protected boolean isTokenValid(HttpServletRequest request)
true
if there is a transaction token stored in
the user's current session, and the value submitted as a request
parameter with this action matches it. Returns false
under any of the following circumstances:
request
- The servlet request we are processingprotected boolean isTokenValid(HttpServletRequest request, boolean reset)
true
if there is a transaction token stored in
the user's current session, and the value submitted as a request
parameter with this action matches it. Returns false
request
- The servlet request we are processingreset
- Should we reset the token after checking it?protected void resetToken(HttpServletRequest request)
request
- The servlet request we are processingprotected void saveErrors(HttpServletRequest request, ActionErrors errors)
request
- The servlet request we are processingerrors
- Error messages objectprotected void saveMessages(HttpServletRequest request, ActionMessages messages)
request
- The servlet request we are processingmessages
- Messages objectprotected void saveToken(HttpServletRequest request)
request
- The servlet request we are processingprotected void setLocale(HttpServletRequest request, Locale locale)
setLocale(java.util.Locale)
.
request
- The request we are processinglocale
- The user's selected Locale to be set, or null
to select the server's default Localeprotected void setLocale(Locale locale)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |