my dog learned polymorphism*
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 Android Security Essentials Live Lessons this week in the Android 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.
It is sorta covered in the JavaRanch Style Guide.
subject: Use Struts2 Tag inside custom tag
Similar Threads
problem with display tag
How to pass attribute to a custom tag only if it evaluates to a non null value
Struts 2 checkboxlist error - list key could not be resolved
label and style sheet in struts 2
Struts 2 newbie problem