Thanks Craig! You certainly confirmed my suspicions, although I would have guessed
that I could've gotten away with sharing the SimpleDateFormat variable since it
wouldn't depend on any values coming in from request objects. Could you perhaps shed
some light on why it wouldn't make sense to share it?
>> Should I move them into the
>> individual execute() methods of the subclasses of MainAction?
>>
>
>Or declare them in the base class's execute() method and pass them as
>parameters.
Since I figured the first attempt probably wouldn't work, I was thinking of another
approach, where I would define the execute() method in the base class to take care of
basic session validation and such and then call an abstract childExecute() method,
which would be inherited by the subclasses like this:
public abstract class MainAction extends TilesAction {
public abstract ActionForward childExecute(ActionMapping mapping, ActionForm
baseForm, HttpServletRequest request, HttpServletResponse response) throws
IOException, ServletException;
public ActionForward execute(ActionMapping mapping, ActionForm baseForm,
HttpServletRequest request, HttpServletResponse response) {
private DynaValidatorForm form = (DynaValidatorForm) baseForm;
private ActionErrors errors = new ActionErrors()
private ActionMessages messages = new ActionMessages();
if (!validLogon(request.getSession())) {
return (mapping.findForward("logon"));
}
return childExecute(mapping, form, request, response);
}
protected boolean validLogon(HttpSession session) {
//check session to ensure that it's not invalidated
}
protected void startSubTransaction(HttpSession session) {
session.setAttribute(Constants.SUB_TRANSACTION_IN_PROGRESS,
Constants.TRUE);
}
protected void endSubTransaction(HttpSession session) {
session.setAttribute(Constants.SUB_TRANSACTION_IN_PROGRESS,
Constants.FALSE);
}
}
public class ChildAction extends MainAction {
public ActionForward childExecute(ActionMapping mapping, DynaValidatorForm
form, HttpServletRequest request, HttpServletResponse response) throws IOException,
ServletException {
private SimpleDateFormat df=new
SimpleDateFormat("MM/dd/yyyy",Locale.US);
//Check for errors
if (!errors.isEmpty()) {
saveErrors(request, errors);
return (mapping.findForward("error"));
}
saveToken(request);
startSubTransaction(request.getSession());
return (mapping.findForward("success"));
}
}
Do you see any potential dangers with this approach? Thanks so much for your help!
Brent
____________________________________________________________
This message sent using iMail from I-Land Internet Services.
http://www.iland.net
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]