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,
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?
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...