Forums Register Login

Tag Handler - how to capture body of a tag?

+Pie Number of slices to send: Send
Hi all,

I am a newbie to Tag Handling. I want to capture the body of a tag and then process it and then display it.

Suppose I have following in my code

<my:tahBody>
Display
</my:tahBody>

Now I want to get "Display ABC" and then process it to "yalpsiD" and then it shpuld be displayed...

I am really not sure how to do it.
somebody Please Help.

Thanks in advance,

Sushma
[ June 21, 2005: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
Depends on the type of tag handler. And JSP 1.x or JSP 2.0?
+Pie Number of slices to send: Send
I want to know both the way... with Simple tag, I don't know a single thing about body capturing.
I tried with the BodyTagSupport but even that is not working.

I overrided the doInitBody() method.
----------------------------------------------------------------
public void doInitBody() throws JspException{
try{
out.println("<BR>\t the bodyContent initially is " + bodyContent.getString());
StringBuffer bodyBuffer = new StringBuffer(bodyContent.getString());
bodyBuffer.reverse();
bodyContent.print(bodyBuffer.toString());
out.println("<BR>\t the bodyContent is now "+bodyContent.getString());
}catch(IOException ex){
throw new JspException("<BR> IOException = "+ex.toString());
}
}
-----------------------------------------------------

I returned EVAL_BODY_BUFFERED from toStartTag() method. Now I am calling it from my jsp.

<%@ taglib prefix="classic" uri="ClassicTags" %>
<html<body>
<Br> <Br> <Br>
<classic:classicBody>I have a Body</classic:classicBody>
<Br> <Br> <Br>
</body></html>

when I run this jsp, I get the following results :
--------------------------------------------------------
the bodyContent initially is
the bodyContent is now
------------------------------------------------------------
I don't know why it is not showing the body content in the result.
Please Help,

Thanks,

Sushma
+Pie Number of slices to send: Send
SimpleTagSupport.getJspBody()
+Pie Number of slices to send: Send
SimpleTagSupport.getJspBody() returns JspFragment.... which has only two methods getJspContext() and invoke(Writer) ... how would I get the body content from this?
Suppose I call my tag like this

<myTag:body>ABC</myTag:body>

I want to get ABC and do some processing with this content, like reversing or using it as key to a resourseBundle, how can I do that?

Regards,

Sushma
+Pie Number of slices to send: Send
getJspContext() returns the JspContext that is bound to this JspFragment.
we can get the writer from that, but first I need to read the content....
+Pie Number of slices to send: Send
Here's the clue:

invoke(Writer)



read the javadoc for the above method.
+Pie Number of slices to send: Send
I did read the documentation for invoke(Write).
--------------------------------------------------------------
<code>
public abstract void invoke(Writer out)
throws JspException, IOException

Executes the fragment and directs all output to the given Writer, or the JspWriter returned by the getOut() method of the JspContext associated with the fragment if out is null.

Parameters:
out - The Writer to output the fragment to, or null if output should be sent to JspContext.getOut().
</code>
------------------------------------------------------------------

I have used getJspBody().invoke(null) before, but that is useful when I am not modifying the body.
I do understand that if I make changes to the body and write that to a writer and pass that write to invoke(), my problem would be solved. But I don't know the first step of the sequence....
Please help, I am desperate...
+Pie Number of slices to send: Send
 

invoke(Writer out)



Did you try providing a StringWriter to this method so that you could capture the body?
[ June 22, 2005: Message edited by: Bear Bibeault ]
+Pie Number of slices to send: Send
Bear,
Thanks A lot for the solution... I was able to capture the body with StringWriter....
I am really very very thankful to you,

Regards,

Sushma
A feeble attempt to tell you about our stuff that makes us money
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1406 times.
Similar Threads
tag files and body content
Accessing tag body inside a tagHandler?
Tag Handler - how to capture body of a tag???
Tiles and image preloading
About jsp:doBody and body-content of tag directive
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 19, 2024 04:47:18.