📄 processaction.java
字号:
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
// Did someone leave us a forward?
ActionForward forward = (ActionForward)
request.getAttribute(Tokens.FAILURE);
if (null==forward) {
// No override, use default
forward = super.findFailure(mapping,form,request,response);
}
else {
// Clear advice from the request
request.setAttribute(Tokens.FAILURE,null);
}
return forward;
} // end findFailure
/**
* Optional extension point for pre-processing.
* Default method does nothing.
* To branch to another URI, return an non-null ActionForward.
* If errors are logged (getErrors() et al),
* default behaviour will branch to findFailure().
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request
* @param request The HTTP request we are processing
* @param response The resonse we are creating
*/
protected void preProcess(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
// Check for cancelled
ActionForward forward = mapping.findForward(Tokens.CANCEL);
if ((null!=forward) && (isCancelled(request))) {
// Our findFailure looks for this
request.setAttribute(Tokens.FAILURE,forward);
// Post cancel error message
ActionErrors errors = getErrors(request,true);
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError(Tokens.ERROR_CANCEL));
return;
}
// Check for missing token
forward = mapping.findForward(Tokens.GET_TOKEN);
if ((null!=forward) && (!isTokenValid(request))) {
// Our findFailure looks for this
request.setAttribute(Tokens.FAILURE,forward);
// Post token error message
ActionErrors errors = getErrors(request,true);
errors.add(ActionErrors.GLOBAL_ERROR,
new ActionError(Tokens.ERROR_TOKEN));
return;
}
if (null!=forward) {
// reset to guard against duplicate request
resetToken(request);
}
// Check for save token directive (do this last)
forward = mapping.findForward(Tokens.SET_TOKEN);
if (null!=forward) saveToken(request);
} // end preProcess
/**
* Check outcome, if any; recurse if container for other outcomes.
*
* @param mapping The ActionMapping used to select this instance
* @param request The HTTP request we are processing
* @param result The ProcessResult we are handling
*/
protected void checkOutcome(
ActionMapping mapping,
HttpServletRequest request,
HttpServletResponse response,
ProcessResult result) throws Exception {
if (result!=null) {
servlet.log(Log.HELPER_OUTCOME,Log.DEBUG);
if (result.isAggregate()) {
// recurse for each ProcessResult in collection
Collection collection = (Collection)
result.getData();
Iterator iterator = collection.iterator();
while (iterator.hasNext()) {
ProcessResult nextResult =
(ProcessResult) iterator.next();
checkOutcome(mapping,request,response,nextResult);
}
}
else {
// call extension points for whatever is returned
if (result.isData())
checkData(mapping,request,response,result);
if (result.isMessages())
checkMessages(mapping,request,response,result);
if (result.isDispatch())
checkDispatch(mapping,request,response,result);
}
}
else {
throw new Exception(Log.PROCESS_RESULT_NULL);
}
} // end checkOutcome
/**
* Return the appropriate ActionForward for the nominal,
* non-error state.
* First checks for a SUCCESS ActionForward stored in the request.
* If an override is not found, returns the result of the
* superclass method.
*
* @param mapping The ActionMapping used to select this instance
* @param form The optional ActionForm bean for this request (if any)
* @param request The HTTP request we are processing
* @param response The response we are creating
* @return The ActionForward representing SUCCESS
* or null if a SUCCESS forward has not been specified.
*/
protected ActionForward findSuccess(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
// Did someone leave us a forward?
ActionForward forward = (ActionForward)
request.getAttribute(Tokens.SUCCESS);
if (null==forward) {
// No override, use default
forward = super.findSuccess(mapping,form,request,response);
}
else {
// Clear advice from the request
request.setAttribute(Tokens.SUCCESS,null);
}
return forward;
} // end findSuccess
/**
* Retrieve from session under known key
* (<code>ProcessBean.USER_PROFILE_KEY</code>).
* Override this approach to implement another method (e.g cookies).
* Also revise UpdateProfile action-mapping to store changes.
*
* @param mapping The ActionMapping used to select this instance
* @param form The ActionForm
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
*/
protected BaseForm getUserProfile(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
return(BaseForm)
request.getSession().getAttribute(ProcessBean.USER_PROFILE_KEY);
} // end getUserProfile
/**
* Assume that helpers are ProcessBeans, execute each, and
* process outcome.
*
* @param mapping The ActionMapping used to select this instance
* @param form The ActionForm
* @param request The HTTP request we are processing
* @param response The HTTP response we are creating
* @param helpers The object instantiated from type given as parameter.
* @exception IOException if an input/output error occurs
* @exception ServletException if a servlet exception occurs
*/
protected void executeLogic(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response,
Object[] helpers) throws Exception {
// Retrieve user profile, if any
BaseForm userBean =
getUserProfile(mapping,form,request,response);
servlet.log(Log.HELPER_PROCESSING,Log.DEBUG);
Map properties = null;
for (int i = 0; i < helpers.length; i++) {
// Get helper instantiated by ancestor
ProcessBean dataBean = (ProcessBean) helpers[i];
properties = null;
if (null!=form) {
if (form instanceof BaseForm) {
BaseForm formBean = (BaseForm) form;
// Merge user profile (if found)
// and our form into a single map
servlet.log(Log.HELPER_POPULATE,Log.DEBUG);
properties = formBean.merge(userBean);
// Pass up the Locale, RemoteNode, and RemoteServer (if any)
dataBean.setLocale(formBean.getSessionLocale());
dataBean.setRemoteNode(getRemoteNode(request));
dataBean.setRemoteServer(getRemoteServer());
}
else {
properties = PropertyUtils.describe(form);
}
} // end null form
else if (null!=userBean) {
// if no form, but is profile, still use profile
properties = PropertyUtils.describe(userBean);
}
// Execute business logic, using values from map
servlet.log(Log.HELPER_EXECUTING,Log.DEBUG);
ProcessResult result = (ProcessResult)
dataBean.execute(properties);
// Analyze result of business logic
checkOutcome(mapping,request,response,result);
} // end for
} // end executeLogic
} // end ProcessAction
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -