Custom Tag Implementation seems inefficient

I've been playing around a bit (alright, so maybe not all that much)
          with custom tags, and it seems like the actual implementation of custom
          tags (tag handler object(s) per tag) is much more resource-intensive
          than would be justified. With Weblogic 5.1 SP6, has anyone had the
          opportunity to compare performance of a typical JSP page w/ and w/out
          custom tags?
          My first impression of custom tags was that you could define tags
          and behaviors that the JSP compiler would then compile into your JSP
          class; there would be no performance hit during page execution. The Java
          code used to write these tags would either be included inline in the JSP
          page code, or else act essentially as static (threadsafe) classes into
          which threads executing JSP pages would call into. This approach means
          less resources consumed and less setup/teardown time in exchange for
          fatter JSPC'd code.
          Instead (and correct me if I am wrong), it appears that each
          distinct custom tag has a pool of instantiated handler objects lying
          around in memory, and each time a custom tag is used, there is a
          little performance hit in the setup & teardown of each handler object's
          pageContext, etc...
          Now admittedly, as another poster (I believe Mr. Purdy) pointed out,
          a "little" ain't all that much... unless there are thousands of those
          "little" hits.
          Moreover, I don't see much benefit in having instantiated objects do
          the heavy lifting. I'd rather have my auto-compiled JSP classes be a
          little more bloated than suffer any performance hit. (I do, however,
          like the fact that custom tags allows for cleaner JSP code, not to
          mention makes for a cleaner break between the creative and coding work.)
          For those of you who've had more extensive experience with custom
          tags, am I missing the target? Is the performance hit negligible for
          heavily-used or complex pages? And/or is the performance hit outweighed
          by code and development cleanliness?
          Thanks for any input.
          Jack
          

Hi Sri
          Looks like you've found an inefficiency in WebLogic's JSP compiler - it
          should be reusing tag instances within the same page. BEA should fix this
          hopefully.
          > So even if a page has 4 tags and 100 users, we have 400 objects just
          > because we use tags.
          Sure, assuming you have 100 concurrent users (and 100 threads in the servlet
          engine). Though creating 400 objects is not a big deal in Java; most non
          trivial Java applications / services create millions of objects.
          Its also worth noting that having a seperate object instance per tag per
          calling thread means that you don't have to do any synchronisation in the
          custom tag (since you're guarenteed to be called by one thread only) so you
          get maximum thread throughput at the expense of some object allocation.
          If you really don't like the idea of creating a few java objects per request
          you could use XSLT to post process JSP files to replace tag occurencies with
          Java scriptlets - though I'm not sure the extra complexity and restrictions
          that this mechanism imposes is worth it at all. Custom tags rock! ;-)
          J.
          James Strachan
          =============
          email: [email protected]
          web: http://www.metastuff.com
          "Sri" <[email protected]> wrote in message
          news:[email protected]...
          > This post had some interesting aspects about custom tags that contradict
          > what I see in the generated java code by the JSP container. I am using
          > weblogic 5.1 sp6 and I have a jsp file that uses a custom tag "xyz:for" a
          > couple of times. the tags are not nested.
          > The java code indicates that two separate instances for the "xyz:for" tag
          > were created.
          >
          > try
          >
          > calicothunder_presentation_tags_ForTag_0 = new
          > calico.thunder.presentation.tags.ForTag();
          >
          > ..............
          >
          > } finally
          >
          > if (_calico_thunder_presentation_tags_ForTag_0 != null)
          > calicothunder_presentation_tags_ForTag_0.release();
          > }
          >
          > Further down
          >
          > try {
          > calicothunder_presentation_tags_ForTag_1 = new
          > calico.thunder.presentation.tags.ForTag();
          > ...............
          >
          > } finally
          >
          > if (_calico_thunder_presentation_tags_ForTag_1 != null)
          > calicothunder_presentation_tags_ForTag_1.release();
          > }
          >
          > The code is creating two different objects for every request. It is not
          > reusing the same object.
          > The release is just cleaning up the current instance, which may be garbage
          > collected at some later stage.
          > So even if a page has 4 tags and 100 users, we have 400 objects just
          > because we use tags.
          >
          > Just trying to understand this better..
          > thanks - Sri
          >
          >
          >
          > "James Strachan" <[email protected]> wrote in message
          > news:[email protected]...
          > > Hi Jack
          > >
          > > I think you're right to be concerned and it is a valid concern.
          > >
          > > In the scheme of things in my experience the cost of using custom tags
          is
          > > quite minimal. Tag instances are reused on the same page so if I have
          > > several non-nested <foo:bar> tags on a page the single FooBarTag
          instance
          > > will be reused for each tag occurance.
          > >
          > > Consider other Java code, say, string concatenation. Consider the
          > following
          > > expression.
          > >
          > > String c = a + b;
          > >
          > > Fairly minimal code you might think. However this line actually involves
          > the
          > > creation of a StringBuffer instance, the call of 2 methods and the
          > creation
          > > of a second String object instance (never mind the internal char[]
          object
          > > instance that is created inside the new Strings constructor).
          > >
          > > A typical use of a custom tag involves one object construction, N
          > > setProperty() method calls (one for each attribute of the tag) and the
          > > startTag / endTag method calls.
          > >
          > > So on balance I'd say the custom tags mechanism is quite small and
          > > efficient.
          > >
          > > Though note that if you use large numbers (say hundreds) of different
          > kinds
          > > of tags then you'll have a much greater object allocation overhead.
          > >
          > > --
          > > J.
          > >
          > > James Strachan
          > > =============
          > > email: [email protected]
          > > web: http://www.metastuff.com
          > > "Jack Lin" <[email protected]> wrote in message
          > > news:[email protected]...
          > > > I've been playing around a bit (alright, so maybe not all that much)
          > > > with custom tags, and it seems like the actual implementation of
          custom
          > > > tags (tag handler object(s) per tag) is much more resource-intensive
          > > > than would be justified. With Weblogic 5.1 SP6, has anyone had the
          > > > opportunity to compare performance of a typical JSP page w/ and w/out
          > > > custom tags?
          > > >
          > > > My first impression of custom tags was that you could define tags
          > > > and behaviors that the JSP compiler would then compile into your JSP
          > > > class; there would be no performance hit during page execution. The
          Java
          > > > code used to write these tags would either be included inline in the
          JSP
          > > > page code, or else act essentially as static (threadsafe) classes into
          > > > which threads executing JSP pages would call into. This approach means
          > > > less resources consumed and less setup/teardown time in exchange for
          > > > fatter JSPC'd code.
          > > > Instead (and correct me if I am wrong), it appears that each
          > > > distinct custom tag has a pool of instantiated handler objects lying
          > > > around in memory, and each time a custom tag is used, there is a
          > > > little performance hit in the setup & teardown of each handler
          object's
          > > > pageContext, etc...
          > > > Now admittedly, as another poster (I believe Mr. Purdy) pointed
          out,
          > > > a "little" ain't all that much... unless there are thousands of those
          > > > "little" hits.
          > > > Moreover, I don't see much benefit in having instantiated objects
          do
          > > > the heavy lifting. I'd rather have my auto-compiled JSP classes be a
          > > > little more bloated than suffer any performance hit. (I do, however,
          > > > like the fact that custom tags allows for cleaner JSP code, not to
          > > > mention makes for a cleaner break between the creative and coding
          work.)
          > > >
          > > > For those of you who've had more extensive experience with custom
          > > > tags, am I missing the target? Is the performance hit negligible for
          > > > heavily-used or complex pages? And/or is the performance hit
          outweighed
          > > > by code and development cleanliness?
          > > >
          > > > Thanks for any input.
          > > > Jack
          > > >
          > > >
          > >
          > >
          >
          >
          

Similar Messages

  • EL expressions not evaluated in custom tag attribute

    I'm writing a custom tag implementation where I need to have some attribute values
    dynamically evaluated using EL, such that I can write:
    <mytaglib:mytag id="${somevar}"/>
    I cannot seem to accomplish this, however. My taglib tag definition looks like this:
         <tag>
              <name>mytag</name>
              <tag-class>myclass</tag-class>
              <body-content>empty</body-content>
              <description>
    Foo
              </description>
              <attribute>
                   <name>articleId</name>
                   <required>true</required>
                   <rtexprvalue>true</rtexprvalue>
                   <type>java.lang.String</type>
              </attribute>
         </tag>
    The implementation of myclass extends TagSupport (since I need to get at the PageContext). The setArticleId() method looks like this:
    public void setArticleId(String idStr) throws JspException {
    if (logger.isDebugEnabled()) {
    logger.debug("idStr = " + idStr);
    try {
    /* XXX: Somehow, the evaluation should happen automagically, but
    * I can't figure out why that doesn't happen!
    String articleIdStr = (String)pageContext.getExpressionEvaluator().evaluate(
    idStr,
    java.lang.String.class, pageContext.getVariableResolver(), null);
    this.articleId = Integer.parseInt(articleIdStr);
    } catch (ELException e) {
    throw new JspException("Failed to parse article id expression");
    Why does it not work automagically?

    Make sure you are working with a JSP 2 container (like Tomcat 5). Also, you should make sure that your web.xml is configured to use the newest Servlet Spec. Read reply #6 on: http://forum.java.sun.com/thread.jspa?threadID=629437 to make sure it is set up properly.
    If you are not using a JSP 2.0 container, then you will not be able to use EL in your custom tag. See: http://forum.java.sun.com/thread.jspa?forumID=45&threadID=725503 for alternatives.

  • JWSDP Custom Tags (finding tag handler class)

    Hi,
    ive been using the Java Web Services Development Pack
    ive tried several examples of creating custom tags all seem to have different directory structures and none seem to work. Heres my setup...
    rootdir -> index.jsp
    rootdir -> WEB-INF -> web.xml
    rootdir -> WEB-INF -> tlds -> demo.tld (the tag library descriptor)
    rootdir -> WEB-INF -> classes -> demo -> tags -> Greeter.java (the tag handler class)
    there are some other folders created by deploytool but they are empty.
    heres demo.tld...
    <taglib>
    <tlib-version>1.0</tlib-version>
    <jsp-version>2.0</jsp-version>
    <short-name>demo</short-name>
    <uri>DemoTags</uri>
    <tag>
    <name>greeter</name>
    <tag-class>demo.tags.Greeter</tag-class>
    <body-content>empty</body-content>
    </tag>
    </taglib>
    here is the tag handler class Greeter.java...
    package demo.tags;
    import javax.servlet.jsp.tagext.*;
    import javax.servlet.jsp.*;
    public class Greeter extends SimpleTagSupport {
    public void doTag() throws JspException {
    PageContext pageContext = (PageContext) getJspContext();
    JspWriter out = pageContext.getOut();
    try {
    out.println("Hello World");
    } catch (Exception e) {
    // Ignore.
    and heres the code in index.jsp...
    <%@taglib prefix="t" uri="DemoTags" %>
    <t:greeter />
    Id love to know if these directory structures are fixed and where they are specified - its confusing the way so many examples show differences.
    this is the exception i get when trying to run index.jsp through the admin page (localhost:4848)
    org.apache.jasper.JasperException: /index.jsp(11,0) Unable to load tag handler class "demo.tags.Greeter" for tag "t:greeter"
    ----

    Sincere Apologies - It might be a good idea to compile my java files so i actually have classes in my classes directory !!
    i think a build.xml file is needed for ant to compile everything that is needed now.
    and the beat goes on !

  • Make new custom tag in A2

    Good evening,
    I'm trying to add a custom tag to an image in Aperture 2.0. I've looked all over the internet and find no examples what so ever of AS and Aperture 2.0.
    I have a few guesses that produce one of two different errors - but no idea how to actually make this work. Any ideas ?
    tell application "Aperture"
    copy selection to theSel
    repeat with curImg in theSel
    class of curImg
    --image version
    -- make new custom tag at curImg with properties {name:"NewTag", value:"New Tag's Value"}
    -- set aNewTag to make new custom tag with properties {name:"NewTag", value:"New Tag's Value"}
    -- Aperture got an error: Can’t make or move that element into that container.
    -- make new custom tag at end of curImg with properties {name:"NewTag", value:"New Tag's Value"}
    -- make new custom tag at end of (curImg) with properties {name:"NewTag", value:"New Tag's Value"}
    -- make new custom tag at end of custom tags of curImg with properties {name:"NewTag", value:"New Tag's Value"}
    -- make new custom tag at end of curImg's custom tags with properties {name:"NewTag", value:"New Tag's Value"}
    --Aperture got an error: Can’t make application "Aperture" into type specifier.
    end repeat
    end tell

    If I recall, it was done because how tags were to be handled in 1.2 was very different from 1.1 and it was felt that developers shouldn't rely on implementation specific classes (unless they were SPI) for several other reasons (application portability being the big one here).
    If it's felt that this was the wrong decision, please feel free to log an issue [1] against the RI (to date, no one has).
    As to the 'borked' dependency URLs, please log an issue [1] if you find these. We have nightly builds going that work from a clean workspace and checking today's result, it seems ok.
    [1] https://javaserverfaces.dev.java.net/issues

  • How to create a custom tag for a custom converter

    In Jdeveloper 11g, I have a project where I have created a custom converter class that impements the javax.faces.convert.Converter class. I have registered the converter with an id in the faces-config.xml file of the project, and the converter works fine by using the <f:converter type="myconverter"> tag. However, the custom converter has a field which I would like to set from the tag itself. Hence, I would like to add an attribute to <f:converter> tag if possible or create a custom tag that has the attribute.
    I have done some reserach and I found that a custom tag can be implemented: I need to create a class which extends from the ConverterTag class or javax.faces.webapp.ConverterElTag class, which I did, but I also need to create ".tld" (tag library) file which defines the tag itself.
    The part about creating the ".tld" file and registring the new tag is what I'm not sure how to do.
    Does someone know how to do this?
    thank you

    Hi frank,
    that's a good document, and it explains how to make a custom converter. I already created the custom converter, it converts a number to any currency pattern. I know java already has a currency converter, but it doesn't support Rupee currency format, and I need that format.
    My converter works, but I would like to pass the pattern of the format through an attribute in a tag. Since f:converter doesn't seem to support that, I created a custom tag which uses my converter, and it enables me to pass a pattern to the converter.
    All of that works, but I need to be able to pass the pattern as an EL expression, and it's not evaluating the expression before passing it to the converter. It just passes the whole expression as a string. I'm thinking It may be something I'm doing wrong.
    this is the tag library definition file:
    <!DOCTYPE taglib
    PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
    "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
    <tlib-version>1.2</tlib-version>
    <jsp-version>2.1</jsp-version>
    <short-name>custom</short-name>
    <uri>custom-currency-converter</uri>
    <description>
    custom currency custom tag library
    </description>
    <tag>
    <name>CurrencyConverter</name>
    <tag-class>
    converter.Tag.CurrencyConverterTag
    </tag-class>
    <body-content>JSP</body-content>
    <attribute>
    <name>pattern</name>
    <type>java.util.String</type>
    <required>true</required>
    <rtexprvalue>true</rtexprvalue>
    </attribute>
    </tag>
    </taglib>
    Edited by: Abraham Ciokler on Feb 4, 2011 11:20 AM

  • Custom Tag not evaluating expression in attribute

    I have a custom tag that needs to take dynamic values in the attributes, but I can't seem to get the values "interpreted" correctly. I have the <rtexprvalue> tag set to "true" in my .tld file, which I thought was the only thing that was needed in order to accomplish what I am trying to do. However, that does not seem to be the case.
    I am using WebLogic (8.1.4) and their <netui> tags, along with JSTL tags (1.0).
    An example of what my code looks like is the following:
    <test:myTag id="1" idx="<netui:content value='{container.index}' />">
        <netui:select ... />
    </test:myTag>and
    <c:set var="myIdx" value="<netui:content value='{container.index}' />" />
    <test:myTag id="1" idx="<c:out value='${myIdx}' />">
        <netui:select ... />
    </test:myTag>Neither of the above approaches has worked. In my code for my Tag.java file, I get the literal string values of <netui:content value='{container.index}' /> and <c:out value='${myIdx}' />, respectively, in my idx property.
    Can someone give me any hints as to what I may be doing wrong?
    Thanks.

    Shouldnt that be
    <netui:content value='${container.index}' />Actually, weblogic does not use the '$' prefix before
    their expressions. Fine. Which in turn means weblogic has some custom expression evaluator.
    Note weblogic 8.1
    as a container doesnt implicitly supportexpressions
    and you have to build in that feature into yourtag
    library.Are you referring to the 'isELIgnored' attribute when
    you mentioned the above statement? If not, can you
    explain what you meant by "build that feature into
    your tag library"?
    It's like this - expression language is supported by default in all containers that implement the j2ee 1.4 spec (servlet 2.4/jsp 2.0). Additionally you should also declare your web application to adhere to the 2.4 standards (through the schema definition in web.xml). In applications that refer to the 2.3 dtd but are run on a 2.4 compliant container you can set the 'isELIgnored' attribute to false and use EL. This works because your container anyways supports it.
    If your container doesnt provide support for EL (outside the jstl tags) as is the case with weblogic 8.1, then you can still use expressions by using something like the [url http://jakarta.apache.org/commons/el/]apache common evaluator  package. The difference being that you will have to call the evaluator classes to evaluate the attribute.
    Are there any alternatives that I could use to
    accomplish what I am trying to do?Did the above answer your question?
    ram.

  • Custom Tag Error with Weblogic SP9

              Hi
              I seem to be having a problem with a custom tag that I wrote. When I run the JSP
              on WLS (without a service pack), the generated java code uses the weblogic.utils.StringUtils
              class to interprete jsp expressions that are passed into the custom tag's attribute
              (on the JSP). The method called on this StringUtils class is valueOf(). This method
              in essence makes sure that the result of the expression is not null and then subsequently
              calls a toString() on the value. Note that if the value is null it simply returns
              an empty string.
              The problem is that when we go to service pack 9, this method is not called (StringUtils.valueOf()).
              Now the problem arises if first of all the result of the expression statement
              in the custom tag definintion (on the JSP) is null. Secondly, it will also error
              out when the setter method is called within the custom tag, if the object returned
              from the expression does not match the one that is expected by the tag... in our
              case a String.
              Here's a sample usage of the tag:
              <wescombop:selectTag
              selectName="buildingNumber"
              selectedItem="<%= buildingJB.getBuildingNumber()%>"
              trimSelectedItem="true"
              selectTagDataName="buildingNumberDataAttribute" />
              Note: buildingJB.getBuildingNumber() returns BigDecimal
              Here's a snipett of the line generated java:
              * Without the service pack
              comwestfieldgrp_wescom_bop_view_tag_SelectTag_1.setSelectedItem(weblogic.utils.StringUtils.valueOf(buildingJB.getBuildingNumber()));
              *With Service Pack 9
              comwestfieldgrp_wescom_bop_view_tag_SelectTag_1.setSelectedItem(buildingJB.getBuildingNumber());
              Note: The setSelectedItem() method expects a String object as a parameter, so
              the code with service pack 9 will result in a compilation error, since buildingJB.getBuildingNumber()
              returns a BigDecimal.
              Let me know if you need more explanation.
              Has anyone experience this problem before... Any help would be deeply appreciated.
              Thanks all.
              Niran
              

              Modify the <cewolf:param> tag.
              <cewolf:chart id="confchart" title="Reports" type="bar3d" yaxislabel="Time"> <cewolf:data>
              <cewolf:producer id="report"> <cewolf:param name="type" value="all" > </cewolf:param>
              </cewolf:producer> </cewolf:data> </cewolf:chart>
              "Balakrishnan" <[email protected]> wrote:
              >
              >We are using cewolf charting library in weblogic 7.0. The charting library
              >is implemented
              >as custom jsp tag library module.
              >
              >However, when the use the tag for displaying the chart, weblogic is producing
              >this compiler error.
              >
              >/reports/reportsView.jsp(108): no corresponding open tag for tag extension
              >close:
              >//[ null; Line: 108]
              >
              >Here's the corresponding source of the jsp file:
              >
              > <cewolf:chart id="confchart" title="Reports" type="bar3d" yaxislabel="Time">
              > <cewolf:data>
              > <cewolf:producer id="report">
              > <cewolf:param name="type" value="all" /> (<-- Error occurs
              >here.
              >Line no: 108)
              > </cewolf:producer>
              > </cewolf:data>
              > </cewolf:chart>
              >
              >I've also checked the corresponding tld file and it is in place.
              >
              >The same code without any modifications is working fine in tomcat. Can
              >you please
              >let me know what needs to be corrected to make this work?
              

  • How to create a new custom tag in JSF 1.2

    Hi there,
    In JSF 1.2, all the classes (CommandButtonTag, CommandLinkTag, DataTableTag,...) in package com.sun.faces.taglib.html_basic are defined as final class. In JSF 1.1, we can create a custom tag that extends the tag in JSF taglib; it save us lots of time.
    Could anybody know how to create a new custom tag in JSF 1.2?
    Many thanks,
    Emily

    If I recall, it was done because how tags were to be handled in 1.2 was very different from 1.1 and it was felt that developers shouldn't rely on implementation specific classes (unless they were SPI) for several other reasons (application portability being the big one here).
    If it's felt that this was the wrong decision, please feel free to log an issue [1] against the RI (to date, no one has).
    As to the 'borked' dependency URLs, please log an issue [1] if you find these. We have nightly builds going that work from a clean workspace and checking today's result, it seems ok.
    [1] https://javaserverfaces.dev.java.net/issues

  • JSP in custom tag attributes...

    Sirs,
              A very nice feature from a development perspective, would be the ability
              to use JSP code within custom tags. Say I have a page on which I wish
              to give all the information on a widget. Say further that I have
              implemented a tag that writes out all the info of a widget as HTML
              table. I would like to write something like this:
              <mytaglib:widgetTag widgetID="<%=request.getParameter("widget_id")%>"
              />
              As far as I know, in the current implementation of custom taglibs this
              does not seem to be possible. Instead you end up writing something like
              this:
              <mytaglib:widgetTag>
              <mytaglib:getWidget><%=request.getParameter("widget_id")%>"</mytaglib:getWidget>
              <mytaglib:displayWidget />
              </mytaglib:widgetTag>
              Which is much more like a scripting language than a heirarchical XML .
              Now, I could always just use the request object within the tag helper
              classes, but this gives up flexibility and can introduce security
              issues, and it also makes the tags much more difficult to work with...
              In short, we should push for JSP evaluation of tag attributes. Weblogic
              could leap ahead of other app servers in this area (making up for the
              custom tag performance issues, to be solve in sp6) and Sun would, once
              again, follow Weblogic's lead and rewrite the standard to include this
              functionality.
              Regards,
              Carson Gross
              

    Carson,
              Perhaps the problem is that you are treating custom tags like one would
              construct an imperative language. I have never had to put Java or use beans
              or %= or even parameters to tags into a JSP because of custom tags.
              The real problem is writing/packaging/maintaining all those tags; sure could
              use a tool that did just that ;-)
              Peace,
              Cameron Purdy
              [email protected]
              http://www.tangosol.com
              WebLogic Consulting Available
              "Carson Gross" <[email protected]> wrote in message
              news:[email protected]...
              > Sirs,
              >
              > A very nice feature from a development perspective, would be the ability
              > to use JSP code within custom tags. Say I have a page on which I wish
              > to give all the information on a widget. Say further that I have
              > implemented a tag that writes out all the info of a widget as HTML
              > table. I would like to write something like this:
              >
              > <mytaglib:widgetTag widgetID="<%=request.getParameter("widget_id")%>"
              > />
              >
              > As far as I know, in the current implementation of custom taglibs this
              > does not seem to be possible. Instead you end up writing something like
              > this:
              >
              > <mytaglib:widgetTag>
              >
              >
              <mytaglib:getWidget><%=request.getParameter("widget_id")%>"</mytaglib:getWid
              get>
              >
              > <mytaglib:displayWidget />
              > </mytaglib:widgetTag>
              >
              > Which is much more like a scripting language than a heirarchical XML .
              > Now, I could always just use the request object within the tag helper
              > classes, but this gives up flexibility and can introduce security
              > issues, and it also makes the tags much more difficult to work with...
              >
              > In short, we should push for JSP evaluation of tag attributes. Weblogic
              > could leap ahead of other app servers in this area (making up for the
              > custom tag performance issues, to be solve in sp6) and Sun would, once
              > again, follow Weblogic's lead and rewrite the standard to include this
              > functionality.
              >
              > Regards,
              > Carson Gross
              >
              

  • Custom Tag Problem

    I have implemented what I thought was a simple custom tag to handle if
              conditions. In the page that I am using to test this new tag, I have
              two instances of this tag - one right after another - the second of
              which is giving me an error in parsing the page saying that there is a
              close tag for which there is no start. The page looks like this:
              <prefix:if expr="<%=expr here%>" >
                   <p>some text</p>
              </prefix:if>
              <prefix:if expr="<%=expr here%>" >
                   <p>some more text</p>
              </prefix:if>
              Where prefix is really the prefix I identified in my taglib directive
              and "expr here" are two different boolean expressions.
              I have search the page for an errant closing tag - but they are all
              matched up just fine. At first I had these tags nested - and thinking
              that was the problem - I unrolled the nesting so that the start and
              end pairs were always matched up - i.e. an end for this tag always
              came after the start without an intervening start for the same tag.
              But doing that unrolling had no effect - and I always seem to get the
              error on the second close tag being encountered by the parser.
              My tld file specifies the body content for this tab as JSP and the
              expr attribute as a run-time evaluated attribute which is required. My
              tag class file extends TagSupport and implements the doStartTag and
              setExpr() methods.
              This problem occurrs for me running both WLS 5.1 SP5 and SP6.
              Is there something simple that I am missing here? Note also that I
              have two other custom tags which work just fine in the same page -
              however both of those tags specify an empty bodycontent.
              

    I found my problem - as I had thought I had a typo - I was missing the
              '=' between expr and the quoted expression in the second tag. I sure
              wish my eyes would quit filling in those missing pieces! :)
              On Wed, 08 Nov 2000 13:21:47 GMT, [email protected] (Scott Jacobs)
              wrote:
              >I have implemented what I thought was a simple custom tag to handle if
              >conditions. In the page that I am using to test this new tag, I have
              >two instances of this tag - one right after another - the second of
              >which is giving me an error in parsing the page saying that there is a
              >close tag for which there is no start. The page looks like this:
              >
              ><prefix:if expr="<%=expr here%>" >
              >     <p>some text</p>
              ></prefix:if>
              ><prefix:if expr="<%=expr here%>" >
              >     <p>some more text</p>
              ></prefix:if>
              >
              >Where prefix is really the prefix I identified in my taglib directive
              >and "expr here" are two different boolean expressions.
              >
              >I have search the page for an errant closing tag - but they are all
              >matched up just fine. At first I had these tags nested - and thinking
              >that was the problem - I unrolled the nesting so that the start and
              >end pairs were always matched up - i.e. an end for this tag always
              >came after the start without an intervening start for the same tag.
              >But doing that unrolling had no effect - and I always seem to get the
              >error on the second close tag being encountered by the parser.
              >
              >My tld file specifies the body content for this tab as JSP and the
              >expr attribute as a run-time evaluated attribute which is required. My
              >tag class file extends TagSupport and implements the doStartTag and
              >setExpr() methods.
              >
              >This problem occurrs for me running both WLS 5.1 SP5 and SP6.
              >
              >Is there something simple that I am missing here? Note also that I
              >have two other custom tags which work just fine in the same page -
              >however both of those tags specify an empty bodycontent.
              

  • Scripting variables and custom tags

    Hello,
    I wonder how I could use a scripting variable in a custom tag? I have written a tag that formats number and dates, and would like to be able to do somethin like
    <% double x = 12,345; %>
    <x:write name="x" format="xyz" />
    Also I wonder how best to implement tags with parameters? I don't suppose it's possible to nest tags or scriplets in a way like <x:bla name="test" value="<%= 12345 %>" />? It seems tedious having to create an Object just to pass a Parameter.
    Many thanks in advance for any help!
    Bjoern

    I think I found the solution,
    pageContext.setAttribute(...,...)

  • Why doesn't my custom tag work?

    First, my backend database is MS Access. Nothing I can do about that, unfortunately.
    I have defined three custom tags (no body, no attributes) to display report information from my project tracking/metrics Access database:
    <prefix:showProjectInfo />
    <prefix:showProjectTeam />
    <prefix:showProjectHistory />
    In my JSP, the first tag I use, <prefix:showProjectInfo />, works perfectly. However, <prefix:showProjectTeam /> gives no output.
    First, here is the tld file that defines the tags (report.tld):
    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE taglib
            PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN"
            "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd">
    <taglib>
        <tlib-version>1.0</tlib-version>
        <jsp-version>1.2</jsp-version>
        <short-name>report</short-name>
        <uri>/report</uri>   
        <!-- Forte4J_TLDX:  This comment contains code generation information. Do not delete.
        <tldx>
            <tagHandlerGenerationRoot>classes</tagHandlerGenerationRoot>
        </tldx>
        -->
        <!-- A validator verifies that the tags are used correctly at JSP
             translation time. Validator entries look like this:
          <validator>
              <validator-class>com.mycompany.TagLibValidator</validator-class>
              <init-param>
                 <param-name>parameter</param-name>
                 <param-value>value</param-value>
           </init-param>
          </validator>
       -->
       <!-- A tag library can register Servlet Context event listeners in
            case it needs to react to such events. Listener entries look
            like this:
         <listener>
             <listener-class>com.mycompany.TagLibListener</listener-class>
         </listener>
       -->
       <tag>
            <name>showProjectInfo</name>
            <tag-class>mil.usaf.rad.metrics.report.showProjectInfoTag</tag-class>
            <body-content>empty</body-content>
            <description>Shows the basic project information</description>       
       </tag>
       <tag>
            <name>showProjectTeam</name>
            <tag-class>mil.usaf.rad.metrics.report.showProjectTeamTag</tag-class>
            <body-content>empty</body-content>
       </tag>
       <tag>
            <name>showProjectHistory</name>
            <tag-class>mil.usaf.rad.metrics.report.showProjectHistoryTag</tag-class>
            <body-content>empty</body-content>
       </tag>
    </taglib>Next, here is the relevant section of web.xml that defines this taglib:
      <taglib>
            <taglib-uri>/WEB-INF/report.tld</taglib-uri>
            <taglib-location>/WEB-INF/report.tld</taglib-location>
      </taglib>Next, the code for showProjectTeamTag.java:
    * showProjectTeam.java
    * Created on March 9, 2005, 10:46 AM
    package mil.usaf.rad.metrics.report;
    import java.io.*;
    import java.sql.*;
    import java.lang.Integer;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    * @author  jason.ferguson
    public class showProjectTeamTag extends TagSupport
        public showProjectTeamTag()
            super();
        public int doAfterBody() throws JspException
            HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
            int pr_id = Integer.parseInt(req.getParameter("pr_id"));
            JspWriter out = pageContext.getOut();
            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;
            try
               out.print("test");
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
               conn = DriverManager.getConnection("jdbc:odbc:Metrics");
            catch (Exception e)
                throw new JspException(e.getMessage());
            String queryGetTeam = "SELECT Projects.pr_id, Accounts.name AS Name, Sum(Schedule.hours) AS SumOfhours FROM tblTAAccounts AS Accounts INNER JOIN ((tblTAScheduleEntries AS Schedule INNER JOIN tblProjectRelease AS ProjectRelease ON Schedule.projectID = ProjectRelease.tblFKTimeAccntProject) INNER JOIN tblPMProjects AS Projects ON ProjectRelease.Release_ID = Projects.pr_id) ON Accounts.accountID = Schedule.accountID WHERE Projects.pr_id=" + pr_id + " GROUP BY Projects.pr_id, Accounts.name, ProjectRelease.Release_number, Projects.Project_name";
            try
                out.print(queryGetTeam);
                stmt = conn.createStatement();
                rs = stmt.executeQuery(queryGetTeam);
                if (rs == null)
                    out.print("No Results!");
                out.print("<table>\n");
                out.print("<tr>\n");
                out.print("<th>Name</th>\n");
                out.print("<th>Total Hours</th>\n");
                out.print("</tr>\n");
                while(rs.next())
                    out.print("<tr>\n");
                    out.print("<td>" + rs.getString("Name") + "</td>\n");
                    out.print("<td>" + rs.getInt("SumOfhours") + "</td>\n");
                    out.print("</tr>\n");
                out.print("</table>\n");
                rs.close();
                stmt.close();
                conn.close();
            catch (Exception e)
                throw new JspException(e.getMessage());
            return SKIP_BODY;
    }Finally, projectdetail.jsp, where the tag is called:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page import="java.sql.*" %>
    <%@page import="java.lang.Integer" %>
    <%@taglib uri="/WEB-INF/report.tld" prefix="report" %>
    <html>
    <head><title>Project Detail</title></head>
    <body>
    <h1 align="center">Project Status</h1>
    <h3>Project Description</h3>
    <report:showProjectInfo />
    <h3>Team Members</h3>
    <report:showProjectTeam />
    </body>
    </html>The first tag, <report:showProjectInfo />, works fine. However, I get no output whatsoever when the system encounters <report:showProjectTeam />. I am a relative newbie at this, so any help is appreciated.
    Jason

    It doesnt seem to matter if the code is in doStartTag(), doEndTag(), orr any of the other functions.
    I also put, as the first item in the function:
    System.out.println("TEST");Nothing.
    Just as an aside, here is the code for the <prefix:showProjectInfo />. Maybe I made a mistake in it? I closed the resultset and connection...
    import java.io.*;
    import java.sql.*;
    import java.lang.Integer;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    * @author  jason.ferguson
    public class showProjectInfoTag extends BodyTagSupport
        public int doEndTag() throws JspException
            HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
            int pr_id = Integer.parseInt(req.getParameter("pr_id"));
            JspWriter out = pageContext.getOut();
            Connection conn = null;
            Statement stmt = null;
            ResultSet rs = null;
            try
               Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                conn = DriverManager.getConnection("jdbc:odbc:Metrics");
            catch (Exception e)
                throw new JspException(e.getMessage());
            String queryProjectInfo = "SELECT * FROM tblPMProjects WHERE pr_id=" + pr_id;
            try
                stmt = conn.createStatement();
                rs = stmt.executeQuery(queryProjectInfo);
                while (rs.next())
                    out.print("<table border=\"1\" style=\"border-collapse:collapse\">\n");
                    out.print("<tr>\n");
                    out.print("<td><b>Project Name:</b>" + rs.getString("Project_name") + "</td>\n");
                    out.print("<td align=\"right\"><b>RAD Number:</b>" + rs.getString("tblProjectNumber") + "</td>\n");
                    out.print("</tr>\n");
                    out.print("<tr>\n");
                    out.print("<td>Project description: " + rs.getString("Project_description") + "</td>\n");
                    out.print("</tr>\n");
                    out.print("<tr>\n");
                    out.print("<td>Customer: " + rs.getString("Customer_POC") + "</td>");
                    out.print("<tr>\n");
                    out.print("<tr>\n");
                    out.print("<td>Customer Unit: " + rs.getString("Customer_OFC") + "</td>\n");
                    out.print("</tr>\n");
                    out.print("<tr>\n");
                    out.print("<td>Customer Phone: " + rs.getString("Customer_phone") + "</td>\n");
                    out.print("</tr>\n");
                    out.print("</table>\n");
                    rs.close();
                    stmt.close();
                    conn.close();
            catch (Exception e)
                throw new JspException(e.getMessage());
            finally
                //conn.close();
            return SKIP_BODY;

  • Question about custom tags

    Hi All,
    Please tell me what is differnce between javabean and custom tags.
    thank you.

    Javabean is a data object (or a data holder) whose properties can be accessed using getters, setters - ex getName() and setName()
    JSP custom tags are merely Java classes that implement special interfaces (Tag interface). Once they are developed and deployed, their actions can be called from your HTML using XML syntax. Refer the article http://java.sun.com/developer/technicalArticles/xml/WebAppDev3/
    Cheers,
    Janesh

  • Error in running custom tag

    Hi
    I am new in jsp?s custom tag development and trying to run it's example with jakarta-tomcat-4.1.30. I have hello.jsp
    <%@ taglib uri="/WEB-INF/mytaglib.tld" prefix="first" %>
    <HTML>
    <HEAD> <TITLE>hELLO tAG</TITLE></HEAD>
    <BODY bgcolor="#ffffcc"><B>My first tag prints</B>
    <first:hello/></HTML>
    and mytaglib.tld as
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE taglib PUBLIC "-//Sun MicroSystems, Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
    <taglib>
    <tlibversion>1.0</tlibversion>
    <jspversion>1.2</jspversion>
    <shortname></shortname>
    <uri></uri>
    <info>A simple tag library for the example</info>
    <tag>
    <name>hello</name>
    <tagclass>HelloTag</tagclass>
    <bodycontent>empty</bodycontent>
    <info></info>
    </tag>
    </taglib>
    and HelloTag.java as
    import javax.servlet.jsp.JspException;
    import javax.servlet.jsp.PageContext;
    import javax.servlet.jsp.tagext.Tag;
    public class HelloTag implements Tag {
         private PageContext pageContext;
         private Tag parent;
         public HelloTag() {
              super();     }
         public void setPageContext(PageContext arg0) {
              this.pageContext = arg0;}
         public void setParent(Tag arg0) {
              this.parent = arg0;}
         public Tag getParent() {
              return parent;}
         public int doStartTag() throws JspException {
              try{
                   pageContext.getOut().print("This is my first Tag");
              }catch(Exception e){throw new JspException("Error);}
              return SKIP_PAGE;     }
         public int doEndTag() throws JspException {
              return SKIP_PAGE;}
         public void release() {     }
    I am getting following error
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    org.apache.jasper.JasperException: /hello.jsp(7,0) Unable to load class hello
         at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:94)
         at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:428)
         at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:219)
         at org.apache.jasper.compiler.Parser.parseCustomTag(Parser.java:712)
         at org.apache.jasper.compiler.Parser.parseElements(Parser.java:804)
         at org.apache.jasper.compiler.Parser.parse(Parser.java:122)
         at org.apache.jasper.compiler.ParserController.parse(ParserController.java:199)
         at org.apache.jasper.compiler.ParserController.parse(ParserController.java:153)
         at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:227)
         at org.apache.jasper.compiler.Compiler.compile(Compiler.java:369)
         at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:473)
         at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:190)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
    Can anyone help me in running this example.

    an uri is not an url,
    in your web.xml you should have something like
    <taglib>
    <taglib-uri>http://yourtaglib/taglib</taglib-uri>
    <taglib-location>/WEB-INF/yourtaglibtld</taglib-location>
    </taglib>
    that uri should be same as in the tld.file and same as in the <%@ taglib tag

  • How to access variables passed in custom tag body

    I am developing custom tags in my application. I need to pass some variables from the .jsp file into tag file. I want these to be passed as body of the tag rather than as tag parameter. It seems the correct syntax for this is:
    <myTags:display> someVariable </myTags:display>
    Question 1: Can I not use this as: <myTags:display someVariable /> Since this tag will be used at many places in the jsp, I dont want to write myTags:display twice for every usage.
    Question 2:
    I want to call the tags from main.jsp like:
    <% String var1 = "Display Me Please"; %>
    <myTags:display var1 />I want the tag file to do some processing on the value stored in var1. I've written the following code in tag file, display.tag:
    <jsp:doBody var="theBody" />
    <% Object obj = (Object) request.getAttribute ("theBody"); %>This code snippet gives me access to obj which has the value "var1". Now how do I access the value that is contained in "var1".
    Edited by: coolkomal on Jun 3, 2009 7:45 AM

    coolkomal wrote:
    I am developing custom tags in my application. I need to pass some variables from the .jsp file into tag file. I want these to be passed as body of the tag rather than as tag parameter. It seems the correct syntax for this is:
    <myTags:display> someVariable </myTags:display>
    Question 1: Can I not use this as: <myTags:display someVariable /> Since this tag will be used at many places in the jsp, I dont want to write myTags:display twice for every usage.
    <myTags:display var="<%=someVariable>"/> is a valid syntax for performing respective action of that variable. You can also use EL to pass the variable ${someVariable} provided the custom tag provide support for EL.
    >
    Question 2:
    I want to call the tags from main.jsp like:
    <% String var1 = "Display Me Please"; %>
    <myTags:display var1 />
    Just ensure that you declare all the related variables in Main.jsp and statically include Main.jsp in your jsp such that you do the checking
    [http://java.sun.com/products/jsp/tags/11/syntaxref117.html]
    >
    I want the tag file to do some processing on the value stored in var1. I've written the following code in tag file, display.tag:
    <jsp:doBody var="theBody" />
    <% Object obj = (Object) request.getAttribute ("theBody"); %>This code snippet gives me access to obj which has the value "var1". Now how do I access the value that is contained in "var1".Can be done provided you code it the right way. Start learning basics of how to create custom taglibraries to gain more knowledge on how things can be managed.
    [http://java.sun.com/javaee/5/docs/tutorial/doc/bnalj.html]

Maybe you are looking for

  • Boot device not found, hard disk not exist.... does that mean my computer is dead?

    Suspecting that Im in a world of hurt here. I tried turning on my computer and it says "boot device not found" - run in test failed... when I hit F4 and run a hard disk test it says "hard disk not exist". The memory test passes, but under the boot de

  • Can't download PDF through IronPort (result:corrupted pdf)

    Hi, Users can't download  PDF through IronPort web proxy(7.3.1) The result is always the same: corrupted pdf. Who can help me ?

  • Spellcheck in Oracle Web Access Client

    need the spellcheck in the Email Oracle Web Access Client. The question is: are this functionality in this Java version of email??? Because I find this functionality (spellcheck) in the HTML version of Oracle Mail but I cant find the spellcheck in th

  • Color corection not showing up in output

    I am a bit of a newbie on this one but I am adding a bit of contrast and reducing brightness. Show up great in Premiere, just like I like it but after output, it looks jus tlike the original. What am i doing wrong. The original was shot at HD on a Ca

  • Why can't I "skip selection" in multitrack-mode

    I have just startet testing AA3.0 for the purpose of editing radio stories. One important feature I have used a lot in other programs, is playing preroll / postroll (skip selection) before I do the actual cut. According to the AA3.0 User Guide (p.61)