The Turbine 3 TemplateAction copies most of the code from the abstract
ActionEvent, however, it's missing a crucial exception handling
condition that didn't get copied from ActionEvent to TemplateAction that
causes errors in doXxx methods to not show up in the log. I submitted a
patch awhile ago that merely copied the extra exception handling from
ActionEvent to TemplateAction.
After looking at the code again, I refactored perform() out of
TemplateAction, thereby relying on ActionEvent's good exception
handling.
Instead of TemplateAction.perform() just being copied
ActionEvent.perform() code with the TemplateContext attribute added in,
I overrode the ActionEvent.doPerform(data) and
ActionEvent.executeEvents(data) in TemplateContext that then later get
the TemplateContext via getTemplateContext(data).
Overall, I think this is a lot cleaner, reduces the duplicated code, and
most importantly, fixes the original error I was having of not seeing
action exceptions in the logs.
- Stephen
Index: actions/TemplateAction.java
===================================================================
RCS file:
/home/cvspublic/jakarta-turbine-3/src/java/org/apache/turbine/modules/actions/TemplateAction.java,v
retrieving revision 1.2
diff -r1.2 TemplateAction.java
59a60
> import java.lang.reflect.InvocationTargetException;
61a63
> import org.apache.turbine.TurbineException;
83a86
>
87c90
< *
---
> *
89c92
< * @exception Exception a generic exception.
---
> * @throws Exception a generic exception.
91c94
< public void doPerform(RunData data)
---
> public void doPerform( RunData data )
93a97
> doPerform(data, getTemplateContext(data));
95,100c99
<
< public void doPerform(RunData data, TemplateContext context)
< throws Exception
< {
< }
<
---
>
102,105c101,103
< * This overrides the default Action.perform() to execute the
< * doEvent() method. If that fails, then it will execute the
< * doPerform() method instead.
< *
---
> * You can also implement this method instead to easily
> * get the TemplateContext object.
> *
107c105,106
< * @exception Exception a generic exception.
---
> * @param context A Turbine TemplateContext object.
> * @throws Exception a generic exception.
109c108
< protected void perform( RunData data )
---
> public void doPerform( RunData data, TemplateContext context )
112,119d110
< try
< {
< executeEvents(data, getTemplateContext(data));
< }
< catch (NoSuchMethodException e)
< {
< doPerform( data, getTemplateContext(data) );
< }
123c114,115
< * This method should be called to execute the event based system.
---
> * This method is called by the parent ActionEvent
> * to try and execute an event for this request.
126d117
< * @param context Velocity context information.
129c120
< public void executeEvents(RunData data, TemplateContext context)
---
> public void executeEvents(RunData data)
169,170c160,161
< args[1] = context;
< method.invoke(this, args );
---
> args[1] = getTemplateContext(data);
> method.invoke(this, args);
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>