• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to process the body content of Tag?

 
Manish Shah
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

In simple tags we perform getJspBody.invoke(null) to pass the body of the tag to the reponse and we get the result.
But what if i want to know the contents of body.

I tried with the following line of code that appear inside doTag().

1>writer=getJspContext().getOut();//Initialise Writer object
2>getJspBody().invoke(write); //invoke the JSPFragment
3>writer.toString(); //use the writer object to process the body

But result page is coming like below. It Prints the writer object.

org.apache.jsp.index_jsp$index_jspHelper@a86d12

I want to display the body contents that i have passed inside the tags.
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
declare a writer in the normal way.. not the writer you get fromt he response....then pass that in to the getJspBody().invode(..);
 
Manish Shah
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Created PrintWriter object at class level and passed it to the invoke() method but i am not able get the result.

Can you please tell me where i am going wrong?
 
Dinuka Arsakularatne
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this. this should work. if not please tell me what error msgs are displyed.

public void doTag() throws JspException, IOException {
StringWriter sw = new StringWriter();
getJspBody().invoke(sw);
getJspContex().getOut().write(sw.toString());
}
 
Manish Shah
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works.
Thanks Dinuka.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic