Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Struts and the fly likes Use Struts2 Tag inside custom tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Use Struts2 Tag inside custom tag" Watch "Use Struts2 Tag inside custom tag" New topic

Use Struts2 Tag inside custom tag

joel mathew

Joined: Dec 05, 2008
Posts: 1
Hi all
I have a custom tag and in its TagHandler class if i use
String data= "<h2>Test</h2>";
JspWriter out=pageContext.getOut();
This will render the html. But in my case i want to render a struts or Jsf tag.
String data= "<s:text name=empname>Test</s:text>";
It will not render the tag!!!How can i render the tag.
In the jsp I have included <%@ taglib prefix="s" uri="/struts-tags" %>
Can somebody point me in the right direction?
Any help will be greatly appreciated!!!
David Newton

Joined: Sep 29, 2008
Posts: 12617

No, that won't render the tag; that shouldn't be surprising: *you're* creating the output for the page--it's not going to be run through the JSP processor *again*.

In your case I would go about it differently, from one of two different angles, depending your requirements. First, if you're going to be embedding custom tags, why not just use JSP 2.0 JSP-based custom tags? Then you can use whatever custom tags you want, and it's usually quite a bit easier.

Second, if that isn't an option (although it's probably the cleanest), use the getText() call within the action itself, set a scoped variable with either the results of the resource lookup or the default text, and render that inside the Java-based custom tag.
I agree. Here's the link:
subject: Use Struts2 Tag inside custom tag
It's not a secret anymore!