wood burning stoves
The moose likes JSP and the fly likes Custom tag lib help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Custom tag lib help" Watch "Custom tag lib help" New topic

Custom tag lib help

Sam Drake
Ranch Hand

Joined: Jun 05, 2003
Posts: 33
My doubt is: How do I obtain a reference to a variable in the JSP page, which I have defined in my tag. eg:
I have a tag of the following fromat -
<mytag:tmvalue name="TM" value="value1" id="test" output="true" />
which outputs the value inside the TreeMap TM that is set in pageContext and also stores its value inside the attribute 'test'.
some code to explain further -
In my JSP I have done the following -
TreeMap tm = new TreeMap();
tm.put("val1", "Hello");
tm.put("val2", "Hello World");
pageContext.getAttribute("TM", tm);
<mytag:tmvalue name="TM" value="val1" id="test" output="true" />
My question is how to access 'test' variable directly in JSP.
Something like this -
Is it possible and how?
I've tried to give pageContext.setAttribute("test", value); in my doStartTag() method of my TagHandler class but I'm still not getting it.
Error comes up as "test" is undefined.
Please help me to know how variables are stored in JSP and relationship with the pageContext object.
Kaustubh Patil
Ranch Hand

Joined: Aug 13, 2001
Posts: 164
If you want to access the variables and print on the page them using the taglib, I suggest you have a look at the code of JSTL. In JSTL there is a custom tag 'C'. You can use <C:0UT> to print the var. on the page. Or better way if you can use the JSTL for all your needs it will solve most og your display problems.
Let me know if I have understood your problem correctly or you need something else.
[ September 24, 2003: Message edited by: Kaustubh Patil ]

Kaustubh. Mumbai, India.
Sam Drake
Ranch Hand

Joined: Jun 05, 2003
Posts: 33
JSTL is a good option. I hadn't thouight about it. Guess I'll have to spend some time in learning the tags.
But the question is how are variables passed between tags and JSP if I want to pass them?
Engin Okucu
Ranch Hand

Joined: Feb 09, 2002
Posts: 174
Hi Sam,
You have to define a class wich will extend the TagExtraInfo class.
to understandf it, here is a example that i found for you :
See here : Scripting Variables in JSP Tags
I hope it will help you.
I agree. Here's the link: http://aspose.com/file-tools
subject: Custom tag lib help
It's not a secret anymore!