You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by davids_k <da...@gmail.com> on 2007/08/16 18:48:13 UTC
getInitParameter null in custom tag test
Hi,
I try to set init parameter in custom tag test. However, in the custom tag
class, I get null from getInitParameter.
Here is the example:
In test class:
public void setUp(){
tag=new HelloWorldTag();
config.setInitParameter("initTest", "Test Init");
tag.setPageContext(this.pageContext);
}
In HelloWorldTag class:
public int doStartTag(){
String
initTest=this.pageContext.getServletContext().getInitParameter("initTest");
System.out.println(initTest); //This is null.
}
Any help is greatly appreciated.
David
--
View this message in context: http://www.nabble.com/getInitParameter-null-in-custom-tag-test-tf4280792.html#a12185070
Sent from the Cactus - User mailing list archive at Nabble.com.
Re: getInitParameter null in custom tag test
Posted by David Liu <da...@gmail.com>.
That would be great. Looking forward to receiving your patch.
Thank you very much.
David
--
View this message in context: http://www.nabble.com/getInitParameter-null-in-custom-tag-test-tf4280792.html#a12273260
Sent from the Cactus - User mailing list archive at Nabble.com.
Re: getInitParameter null in custom tag test
Posted by David Liu <da...@gmail.com>.
Thanks. It works very well now.
--
View this message in context: http://www.nabble.com/getInitParameter-null-in-custom-tag-test-tf4280792.html#a12366587
Sent from the Cactus - User mailing list archive at Nabble.com.
Re: getInitParameter null in custom tag test
Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi David,
In article <20...@lab.ntt.co.jp>,
Wed, 22 Aug 2007 19:41:24 +0900 (JST),
Kazuhito SUGURI <su...@lab.ntt.co.jp> 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
Re: getInitParameter null in custom tag test
Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi David,
In article <12...@talk.nabble.com>,
Thu, 16 Aug 2007 09:48:13 -0700 (PDT),
davids_k <da...@gmail.com> wrote:
david> I try to set init parameter in custom tag test. However, in the custom tag
david> class, I get null from getInitParameter.
david>
david> Here is the example:
david>
david> In test class:
david> public void setUp(){
david> tag=new HelloWorldTag();
david> config.setInitParameter("initTest", "Test Init");
david> tag.setPageContext(this.pageContext);
david> }
david>
david> In HelloWorldTag class:
david>
david> public int doStartTag(){
david> String
david> initTest=this.pageContext.getServletContext().getInitParameter("initTest");
david> System.out.println(initTest); //This is null.
david> }
As far as I can see from Cactus code, it doesn't support your use case.
I think I can provide a patch if you can build Cactus jars from code,
although I don't have enough time to commit it to the code-base.
Regards,
----
Kazuhito SUGURI