You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by mr...@apache.org on 2005/04/27 07:56:53 UTC
svn commit: r164950 - in
/struts/tiles/trunk/src/java/org/apache/struts/tiles: TilesUtil.java
TilesUtilImpl.java taglib/InsertTag.java
Author: mrdon
Date: Tue Apr 26 22:56:52 2005
New Revision: 164950
URL: http://svn.apache.org/viewcvs?rev=164950&view=rev
Log:
Added ability to pass flush attribute of insert tag down to the JSP
include, using reflection to call the JSP 2.0 method if found.
PR: 21972
Modified:
struts/tiles/trunk/src/java/org/apache/struts/tiles/TilesUtil.java
struts/tiles/trunk/src/java/org/apache/struts/tiles/TilesUtilImpl.java
struts/tiles/trunk/src/java/org/apache/struts/tiles/taglib/InsertTag.java
Modified: struts/tiles/trunk/src/java/org/apache/struts/tiles/TilesUtil.java
URL: http://svn.apache.org/viewcvs/struts/tiles/trunk/src/java/org/apache/struts/tiles/TilesUtil.java?rev=164950&r1=164949&r2=164950&view=diff
==============================================================================
--- struts/tiles/trunk/src/java/org/apache/struts/tiles/TilesUtil.java (original)
+++ struts/tiles/trunk/src/java/org/apache/struts/tiles/TilesUtil.java Tue Apr 26 22:56:52 2005
@@ -132,7 +132,21 @@
*/
public static void doInclude(String uri, PageContext pageContext)
throws IOException, ServletException {
- tilesUtilImpl.doInclude(uri, pageContext);
+ doInclude(uri, pageContext, true);
+ }
+
+ /**
+ * Do an include using PageContext.include().
+ *
+ * This method is used by the Tiles package when an include is required.
+ * The Tiles package can use indifferently any form of this method.
+ * @param uri Uri or Definition name to forward.
+ * @param flush If the writer should be flushed before the include
+ * @param pageContext Current page context.
+ */
+ public static void doInclude(String uri, PageContext pageContext, boolean flush)
+ throws IOException, ServletException {
+ tilesUtilImpl.doInclude(uri, pageContext, flush);
}
/**
Modified: struts/tiles/trunk/src/java/org/apache/struts/tiles/TilesUtilImpl.java
URL: http://svn.apache.org/viewcvs/struts/tiles/trunk/src/java/org/apache/struts/tiles/TilesUtilImpl.java?rev=164950&r1=164949&r2=164950&view=diff
==============================================================================
--- struts/tiles/trunk/src/java/org/apache/struts/tiles/TilesUtilImpl.java (original)
+++ struts/tiles/trunk/src/java/org/apache/struts/tiles/TilesUtilImpl.java Tue Apr 26 22:56:52 2005
@@ -21,6 +21,9 @@
import java.io.IOException;
import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
@@ -41,11 +44,32 @@
public class TilesUtilImpl implements Serializable {
/** Commons Logging instance.*/
- protected Log log = LogFactory.getLog(TilesUtil.class);
+ protected static final Log log = LogFactory.getLog(TilesUtil.class);
/** Constant name used to store factory in servlet context */
public static final String DEFINITIONS_FACTORY =
"org.apache.struts.tiles.DEFINITIONS_FACTORY";
+
+ /**
+ * JSP 2.0 include method to use which supports configurable flushing.
+ */
+ private static Method include = null;
+
+ /**
+ * Initialize the include variable with the
+ * JSP 2.0 method if available.
+ */
+ static {
+
+ try {
+ // get version of include method with flush argument
+ Class[] args = new Class[]{String.class, boolean.class};
+ include = PageContext.class.getMethod("include", args);
+ } catch (NoSuchMethodException e) {
+ log.debug("Could not find JSP 2.0 include method. Using old one that doesn't support " +
+ "configurable flushing.", e);
+ }
+ }
/**
* Do a forward using request dispatcher.
@@ -92,9 +116,21 @@
* The Tiles package can use indifferently any form of this method.
* @param uri Uri or Definition name to forward.
* @param pageContext Current page context.
+ * @param flush If the writer should be flushed before the include
*/
- public void doInclude(String uri, PageContext pageContext)
+ public void doInclude(String uri, PageContext pageContext, boolean flush)
throws IOException, ServletException {
+ try {
+ // perform include with new JSP 2.0 method that supports flushing
+ if (include != null) {
+ include.invoke(pageContext, new Object[]{uri, Boolean.valueOf(flush)});
+ return;
+ }
+ } catch (IllegalAccessException e) {
+ log.debug("Could not find JSP 2.0 include method. Using old one.", e);
+ } catch (InvocationTargetException e) {
+ log.debug("Unable to execute JSP 2.0 include method. Trying old one.", e);
+ }
pageContext.include(uri);
}
Modified: struts/tiles/trunk/src/java/org/apache/struts/tiles/taglib/InsertTag.java
URL: http://svn.apache.org/viewcvs/struts/tiles/trunk/src/java/org/apache/struts/tiles/taglib/InsertTag.java?rev=164950&r1=164949&r2=164950&view=diff
==============================================================================
--- struts/tiles/trunk/src/java/org/apache/struts/tiles/taglib/InsertTag.java (original)
+++ struts/tiles/trunk/src/java/org/apache/struts/tiles/taglib/InsertTag.java Tue Apr 26 22:56:52 2005
@@ -748,12 +748,13 @@
* This method is used internally to do all includes from this class. It delegates
* the include call to the TilesUtil.doInclude().
* @param page The page that will be included
+ * @param flush If the writer should be flushed before the include
* @throws ServletException - Thrown by call to pageContext.include()
* @throws IOException - Thrown by call to pageContext.include()
*/
- protected void doInclude(String page)
+ protected void doInclude(String page, boolean flush)
throws ServletException, IOException {
- TilesUtil.doInclude(page, pageContext);
+ TilesUtil.doInclude(page, pageContext, flush);
}
/////////////////////////////////////////////////////////////////////////////
@@ -885,7 +886,7 @@
pageContext.getOut().flush();
}
- doInclude(page);
+ doInclude(page, flush);
} catch (IOException e) {
String msg =
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org