Using Struts tags inside a custom tag


Web tier: servlets, JSP, Web frameworks: Using Struts tags inside a custom tag

  1. Using Struts tags inside a custom tag (13 messages)

    Hi all,

    I'm developing a custom tag and want to use a struts tag inside my custom tag, so the struts tag is evaluated too.

    Can this be done? How?

  2. It's easy.

    In the Tag Library Definition for your custom tag, make the <bodycontent> "JSP". This means that the contents your tag will be evaluated as JSP logic. This includes evaluating any other tags inside of yours.
  3. make the <bodycontent> "JSP".

    I have it, but it doesn't work... I see the source (html:text) but it's not translated... any idea?
  4. Are you sure that you are importing the Struts taglib as well as your own taglib?
  5. WLW netui tabligs are extensions to struts taglibs and i included netui tablibs and my custom taglib both. It doesn't work, kindly suggest.
  6. Can you provide more information? What tags are you nesting inside others? What happens you view source on the rendered page?
  7. JAVA CODE ---------------

    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;

    public class DateControl extends javax.servlet.jsp.tagext.TagSupport
        private String title = "";
        private String dataSource = "";
        private String styleClass = "";

        public void setTitle(String title)
    this.title = title;
        public void setDataSource(String dataSource)
    this.dataSource = dataSource;
        public void setStyleClass(String styleClass)
            this.styleClass = styleClass;
        public int doStartTag() throws JspException
                pageContext.getOut().print("<netui:textBox tagId='" + title + "' styleClass='" + styleClass + "' dataSource='" + dataSource + "' />");
    catch (Exception e)
    throw new JspTagException(e.getMessage());

            return EVAL_BODY_INCLUDE;

    public int doEndTag() throws JspException
    catch (Exception e)
    throw new JspTagException(e.getMessage());

    return EVAL_PAGE;

    Part of the JSP Code where i am invoking this custom tag
    <%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
    <!-- including the taglib where the path of the particular taghandler is defined-->
    <%@ taglib uri="taglib.tld" prefix="crq-custom"%>
    <crq-custom:DateControl title="effectiveFromDate" styleClass="textBoxStyle" dataSource="{actionForm.effectiveFromDate}"/>

    HTML that is getting rendered
    <netui:textBox tagId='effectiveFromDate' styleClass='textBoxStyle' dataSource='{actionForm.effectiveFromDate}' />
  8. Here is your problem:
    pageContext.getOut().print("<netui:textBox tagId='" + title + "' styleClass='" + styleClass + "' dataSource='" + dataSource + "' />");
    A custom tag must be embedded in the JSP page itself, so that the JSP compiler can convert it to the appropriate calls to the tag handler class.

    Your DateControl logic is completely broken. You will be better off using the <netui:textBox> tag directly.
  9. That's fine Paul, I got your point. But problem is I want to use netui tags inside my custom tags, not only one but 2-3 netui tags so that instead of adding three netui tags on the JSP page I can add just invoke my custom tag. Please suggest if there is any way out.
  10. Custom tags can only be invoked from a JSP.

    I suggest you use some kind of JSP include if you want to set up common invocations of several tags, and re-use the include.

    The only other alternative that I can think of is to get at the source code of the netui tags, and extract the Java logic into your own custom tag.
  11. At last, what i've done is to use the Struts tag as a class in my Tag class. For example, if i want to use a form, what i do is:

    FormTag myForm = new FormTag();

    Perhaps you can do something like this too
  12. Hi Eneko,

    I'm facing a similar problem. I'm developing a custom tag and want to use a struts tag inside my custom tag, so the struts tag is evaluated too. Can you give me a example how you solved it?
  13. I am having the same problem.
    i created a custom tag as such..

    <contactPerson:displayName uniqueIdentifier="<bean:write name='calendarEvent' property='desContactPerson'/>"/>
    when I load the jsp page it does not evaluate the inner tag?!

    However when I do this..

    <contactPerson:displayName uniqueIdentifier=<bean:write name='calendarEvent' property='desContactPerson'/>/>
    It evaluates the inner tag but it does evaluate my custom tag?!

    also when i do this

    <contactPerson:displayName uniqueIdentifier='<bean:write name='calendarEvent' property='desContactPerson'/>'/>
     Same as only evaluates my inner tag but not my custom tag :( finish off when i do
    <contactPerson:displayName uniqueIdentifier="<bean:write name="calendarEvent" property="desContactPerson"/>"/>
    It only evaluates the inner tag but not my custom tag... >:(

    This is a section of the tld file for my custom tag...

    <name>displayName</name> <tagclass></tagclass>
    <info>Display User info tag base on uniqueIdentifier from phonebook</info>

    Is it possible at all to do it...or must we rely on using scriptlet?!
  14. Look at how Expresso does it[ Go to top ]

    The Expresso web framework is largely an extension of Struts including their tags. It is opensource so you can go download it and check it out.