Re: getInitParameter null in custom tag test
Kazuhito SUGURI <[email protected]> Thu, 23 Aug 2007 11:02:05 +0900 (JST)
| Newsgroups | gmane.comp.jakarta.cactus.user |
|---|---|
| Message-ID | <[email protected]> |
Hi David, In article <[email protected]>, Wed, 22 Aug 2007 19:41:24 +0900 (JST), Kazuhito SUGURI <[email protected]> wrote: suguri> I think I can provide a patch if you can build Cactus jars from code, suguri> although I don't have enough time to commit it to the code-base. Please find the patch attached. For your use case, you should write test case as follows: import org.apache.cactus.server.ServletContextWrapper; ... public void setUp() { tag = new HelloWorldTag(); ServletContextWrapper context = (ServletContextWrapper) pageContext.getServletContext(); cofntext.setInitParameter("test", "test-value at context"); tag.setPageContext(pageContext); } Hope this helps, ---- Kazuhito SUGURI --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
patch
(text/plain, 1.3 KB)
Index: framework/src/java/share-12-13-14/org/apache/cactus/server/AbstractPageContextWrapper.java
===================================================================
--- framework/src/java/share-12-13-14/org/apache/cactus/server/AbstractPageContextWrapper.java (revision 568555)
+++ framework/src/java/share-12-13-14/org/apache/cactus/server/AbstractPageContextWrapper.java (working copy)
@@ -56,6 +56,11 @@
protected ServletURL url;
/**
+ * The wrapped ServletContext for this PageContext.
+ */
+ private ServletContextWrapper servletContext = null;
+
+ /**
* Construct an <code>PageContext</code> instance that delegates
* it's method calls to the page context object passed as parameter and
* that uses the URL passed as parameter to simulate a URL from which
@@ -110,8 +115,12 @@
*/
public ServletContext getServletContext()
{
- return new ServletContextWrapper(
- this.originalPageContext.getServletContext());
+ if (this.servletContext == null)
+ {
+ this.servletContext = new ServletContextWrapper(
+ this.originalPageContext.getServletContext());
+ }
+ return this.servletContext;
}
// Unmodified overridden methods -----------------------------------------