This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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 - <%=test%> 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. regards, Sam.
Kaustubh Patil
Ranch Hand
Joined: Aug 13, 2001
Posts: 164
posted
0
Hi, 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. -Kaustubh [ September 24, 2003: Message edited by: Kaustubh Patil ]
Kaustubh. Mumbai, India.
Sam Drake
Ranch Hand
Joined: Jun 05, 2003
Posts: 33
posted
0
Hi, 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? regards, Sam.
Engin Okucu
Ranch Hand
Joined: Feb 09, 2002
Posts: 174
posted
0
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.