• Post Reply Bookmark Topic Watch Topic
  • New Topic

Appending JSTL tags to a StringBuffer inside a Java class  RSS feed

 
Bhavin B Parekh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am using JSTL and one of my JSP pages are being constructed inside a view helper Java class. Hence, the code within that class will look simila to this....

StringBuffer table = new StringBuffer();
table.append("<fieldset>");

table.append("<legend class='legendformat'>");
table.append("<fmt:message key=\"departing\"></fmt:message>");
table.append("</legend>");

.
.
.
.
.
.
table.append("</fieldset>");

Now, the challenge that I am facing is that the <fmt:message key> tag appended to the stringbuffer is not being recognized as a JSTL tag and thus it does not result in proper output.

Any help will be greatly appreciated.

Thanks,
Bhavin Parekh.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without calling the same code the tag calls it won't work like this: you're basically asking for double compilation/evaluation of a JSP page.
 
Bhavin B Parekh
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David,

Thanks for your reply.
Can you kindly elaborate on what are you trying to explain please?

And, if my way of doing it is wrong, then, it'd be great if you could tell me the right way of doing it.

Thanks in advance,
Bhavin.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Logic dictates you must be doing it wrong, because it doesn't work.

JSP is compiled/executed only once: you're basically asking the system to go back and evaluate what you just added to the JSP as JSP. You need to format your message using Java if you're going to add it as a string to the page's HTML.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!