Building dynamic custom Tags

Discussions

Web tier: servlets, JSP, Web frameworks: Building dynamic custom Tags

  1. Building dynamic custom Tags (1 messages)

    Hello,
    I have built a custom tag, which has a parameter
    named "query".
    The custom tag makes a DB query according to the query passed.
    If I hardcode the query parameter it works correctly...

    <html>
    <head>
    <%@ taglib uri="http://myhost/taglib" prefix="examples" %>
    </head>
    <body>

    This is the list of companies <examples:size query="SELECT * FROM COMPANY" />.

    </body>
    </html>

    but I'd like rather to pass the query String as variable
    so it can be changed dynamically...

    <html>
    <head>
    <%@ taglib uri="http://myhost/taglib" prefix="examples" %>
    <% String sql = "SELECT * FROM COMPANY"; %>
    </head>

    <body>

    This is the list of companies <examples:size query="<%=sql%>" />.

    </body>
    </html>

    but this way it doesn't work..in fact it doesn't translate "<%=sql%>"
    into the SELECT I need. It just passes to the custom tag the String
    "<%=sql%>".
    Does anybody know how to do it?
    Thanks in advance
    Francesco


  2. Francesco, you need to modify your taglib descriptor for this particular tag. You'll need add the <rtexprvalue>
    (means: runtime expression value) element:

    <tag>
    ...
    <attribute>
       <name>query</name>
       <required>...</required>
       <rtexprvalue>true</rtexprvalue>
    </attribute>

    Gordon.