Revision: 399
http://svn.sourceforge.net/stripes/?rev=399&view=rev
Author: tfenne
Date: 2006-09-02 05:54:13 -0700 (Sat, 02 Sep 2006)
Log Message:
-----------
Fix for STS-259: use TryCatchFinally to ensure that the internal tag stack is
always in sync when exceptions happen
Modified Paths:
--------------
trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
trunk/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
trunk/stripes/src/net/sourceforge/stripes/tag/WizardFieldsTag.java
Modified: trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java 2006-09-01
19:19:52 UTC (rev 398)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/FormTag.java 2006-09-02
12:54:13 UTC (rev 399)
@@ -30,6 +30,7 @@
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTag;
+import javax.servlet.jsp.tagext.TryCatchFinally;
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
@@ -44,7 +45,7 @@
*
* @author Tim Fennell
*/
-public class FormTag extends HtmlTagSupport implements BodyTag {
+public class FormTag extends HtmlTagSupport implements BodyTag,
TryCatchFinally {
/** Log used to log error and debugging information for this class. */
private static Log log = Log.getInstance(FormTag.class);
@@ -227,14 +228,25 @@
catch (IOException ioe) {
throw new StripesJspException("IOException in
FormTag.doEndTag().", ioe);
}
- finally {
- getTagStack().pop();
- }
return EVAL_PAGE;
}
+ /** Rethrows the passed in throwable in all cases. */
+ public void doCatch(Throwable throwable) throws Throwable { throw
throwable; }
+
/**
+ * Used to ensure that the form is always removed from the tag stack so
that there is
+ * never any confusion about tag-parent hierarchies.
+ */
+ public void doFinally() {
+ try { getTagStack().pop(); }
+ catch (Throwable t) {
+ /* Supress anything, because otherwise this might mask any causal
exception. */
+ }
+ }
+
+ /**
* <p>In general writes out a hidden field notifying the server exactly
what fields were
* present on the page. Exact behaviour depends upon whether or not the
current form
* is a wizard or not. When the current form is <b>not</b> a wizard this
method examines
Modified:
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
===================================================================
---
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
2006-09-01 19:19:52 UTC (rev 398)
+++
trunk/stripes/src/net/sourceforge/stripes/tag/InputOptionsCollectionTag.java
2006-09-02 12:54:13 UTC (rev 399)
@@ -239,12 +239,26 @@
tag.getAttributes().putAll(getAttributes());
for (Entry entry : sortedEntries) {
- tag.setLabel(entry.label.toString());
- tag.setValue(entry.value);
- tag.doStartTag();
- tag.doInitBody();
- tag.doAfterBody();
- tag.doEndTag();
+ tag.setLabel(entry.label.toString());
+ tag.setValue(entry.value);
+ try {
+ tag.doStartTag();
+ tag.doInitBody();
+ tag.doAfterBody();
+ tag.doEndTag();
+ }
+ catch (Throwable t) {
+ /** Catch whatever comes back out of the doCatch() method and
deal with it */
+ try { tag.doCatch(t); }
+ catch (Throwable t2) {
+ if (t2 instanceof JspException) throw (JspException) t2;
+ if (t2 instanceof RuntimeException) throw
(RuntimeException) t2;
+ else throw new StripesJspException(t2);
+ }
+ }
+ finally {
+ tag.doFinally();
+ }
}
// Clean up any temporary state
Modified: trunk/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
2006-09-01 19:19:52 UTC (rev 398)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/InputTagSupport.java
2006-09-02 12:54:13 UTC (rev 399)
@@ -26,6 +26,7 @@
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
+import javax.servlet.jsp.tagext.TryCatchFinally;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
@@ -40,7 +41,7 @@
*
* @author Tim Fennell
*/
-public abstract class InputTagSupport extends HtmlTagSupport {
+public abstract class InputTagSupport extends HtmlTagSupport implements
TryCatchFinally {
private String formatType;
private String formatPattern;
private boolean focus;
@@ -337,27 +338,36 @@
* @return int the value returned by the child class from doStartInputTag()
*/
public final int doEndTag() throws JspException {
- try {
- int result = doEndInputTag();
+ int result = doEndInputTag();
- if (getFieldErrors() != null) {
- this.errorRenderer.doAfterEndTag();
- }
+ if (getFieldErrors() != null) {
+ this.errorRenderer.doAfterEndTag();
+ }
- if (this.focus) {
- makeFocused();
- }
+ if (this.focus) {
+ makeFocused();
+ }
- this.errorRenderer = null;
- this.fieldErrors = null;
- this.fieldErrorsLoaded = false;
- this.focus = false;
+ this.errorRenderer = null;
+ this.fieldErrors = null;
+ this.fieldErrorsLoaded = false;
+ this.focus = false;
- return result;
+ return result;
+ }
+
+ /** Rethrows the passed in throwable in all cases. */
+ public void doCatch(Throwable throwable) throws Throwable { throw
throwable; }
+
+ /**
+ * Used to ensure that the input tag is always removed from the tag stack
so that there is
+ * never any confusion about tag-parent hierarchies.
+ */
+ public void doFinally() {
+ try { getTagStack().pop(); }
+ catch (Throwable t) {
+ /* Supress anything, because otherwise this might mask any causal
exception. */
}
- finally {
- getTagStack().pop();
- }
}
/**
Modified: trunk/stripes/src/net/sourceforge/stripes/tag/WizardFieldsTag.java
===================================================================
--- trunk/stripes/src/net/sourceforge/stripes/tag/WizardFieldsTag.java
2006-09-01 19:19:52 UTC (rev 398)
+++ trunk/stripes/src/net/sourceforge/stripes/tag/WizardFieldsTag.java
2006-09-02 12:54:13 UTC (rev 399)
@@ -16,6 +16,7 @@
import net.sourceforge.stripes.controller.StripesConstants;
import net.sourceforge.stripes.action.ActionBean;
+import net.sourceforge.stripes.exception.StripesJspException;
import javax.servlet.jsp.JspException;
import java.util.Set;
@@ -95,9 +96,23 @@
if ( !excludes.contains(name) ) {
hidden.setName(name);
- hidden.doStartTag();
- hidden.doAfterBody();
- hidden.doEndTag();
+ try {
+ hidden.doStartTag();
+ hidden.doAfterBody();
+ hidden.doEndTag();
+ }
+ catch (Throwable t) {
+ /** Catch whatever comes back out of the doCatch()
method and deal with it */
+ try { hidden.doCatch(t); }
+ catch (Throwable t2) {
+ if (t2 instanceof JspException) throw
(JspException) t2;
+ if (t2 instanceof RuntimeException) throw
(RuntimeException) t2;
+ else throw new StripesJspException(t2);
+ }
+ }
+ finally {
+ hidden.doFinally();
+ }
}
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development