Creating Custom tags

When I attempt to use my custom tag (my:setcolor) in BEA workshop I get the following error:
ERROR: No type with this name could be found at this location
The error message appears when I mouse over my tag.
I attached is my JSP file, TLD file and JAVA class file.
JSP Page
================================
<%@ page language="java" contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="netui-tags-databinding.tld" prefix="netui-data"%>
<%@ taglib uri="netui-tags-html.tld" prefix="netui"%>
<%@ taglib uri="netui-tags-template.tld" prefix="netui-template"%>
<%@ taglib uri="my.tld" prefix="my" %>
<netui:html>
<head>
<title>
Simple tag library
</title>
</head>
<body>
<my:setcolor colname='READY' rating='1'/>
</body>
</netui:html>
Tag TLD file
=================================
<?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>Derricks first custom tag</short-name>
<tag>
<name>setcolor</name>
<tag-class>SetColor</tag-class>
<body-content>empty</body-content>
<description>
     Sets the color for the measured area fields
</description>
<attribute>
<name>colname</name>
<required>true</required>
</attribute>
<attribute>
<name>rating</name>
<required>true</required>
</attribute>
</tag>
</taglib>
JAVA Class
================
import java.io.*;
import javax.servlet.ServletRequest;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class SetColor extends TagSupport
private String colName;
private String dataColor;
private int rating;
public void setColname(String colName) {
this.colName = colName;
public void setRating(String rating) {
this.rating = Integer.parseInt(rating);
public void setRating(int rating) {
this.rating = rating;
private boolean IsColumn() {
return (this.colName == "READY" ||
this.colName == "PRRAT" ||
this.colName == "ERRAT" ||
this.colName == "ESRAT" ||
this.colName == "TRRAT");
public int doStartTag() throws JspException
if (IsColumn()) {
if (rating == 1)
dataColor = "#00CC00";
else if (rating == 2)
dataColor = "#00FF00";
else if (rating == 3)
dataColor = "#FFFF00";
else if (rating == 4)
dataColor = "FF0000";
else
dataColor = "#CC3366";
else
dataColor = "";
System.out.println(dataColor);
return SKIP_BODY;
}

Can't say I know much about property editors and even less about BEA
but, a few things
1 Your string comparisions in the IsColumn() method need to use .equals() rather than ==
2 You might consider adding 'get' methods to your Tag. The Property editor would probably like them :-)
3 To print out something from your tag you want the line:
try {
  pageContext.getOut().println("RATING is " + rating + " colour is " + dataColor );
  pageContext.getOut().println(dataColor);
catch (IOException e) {
  throw new JspException(e);
}You should probably be putting your tag class in a package. Java classes without packages can potentially cause problems further down the line.

Similar Messages

  • Problem creating custom tag

    I tried to create a simple custom tag using apache webserver. my jsp file is HelloWorld.jsp (for presentation, codes listed below), my HelloWorld.java class (listed below) ,a and my TLD file is called WoaTagLibDesc (also listed below). I ran this and I got this error message below:
    HTTP status 404
    type status report
    message:
    description The requested resource () is not available.
    Apache Tomcat/6.0.18
    Can anybody advise me on what to do please
    (1) HelloWorld.jsp
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <%@taglib uri="/WEB-INF/woatags/WoaTagLibDesc.tld" prefix="mt" %>
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
        </head>
        <body>
            <mt:helloWorld/>
        </body>
    </html>
    (2) WoaTagLibDesc.tld<?xml version="1.0" encoding="UTF-8"?>
    <taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
    <tlib-version>1.0</tlib-version>
    <short-name>woataglibdesc</short-name>
    <uri>/WEB-INF/woatags/WoaTagLibDesc</uri>
    <tag>
    <name>helloWorld</name>
    <tag-class>woatag.HelloWorldTag</tag-class>
    <body-content>empty</body-content>
    </tag>
    </taglib>
    (3) HelloWorldTag.java
    import java.io.IOException;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    public class HelloWorldTag implements Tag {
        private PageContext pageContext;
        private Tag parent;
        public HelloWorldTag() {
            super();
        public void setPageContext(final PageContext pageContext) {
            this.pageContext = pageContext;
        public void setParent(final Tag parent) {
            this.parent = parent;
        public javax.servlet.jsp.tagext.Tag getParent() {
            return parent;
        public int doStartTag() throws JspException {
            return SKIP_BODY;
        public int doEndTag() throws JspException {
            try {
                pageContext.getOut().write("Hello World!");
            } catch (IOException e) {
                throw new JspTagException("IO Error: " + e.getMessage());
            return EVAL_PAGE;
        public void release() {
    }

    Your class (according to what is posted) is in the package mytag.
    So in your tld: <tagclass>tag.Hello</tagclass>should be<tagclass>mytag.Hello</tagclass>cheers,
    evnafets

  • Trying to create custom tag library

    I'm a novice trying to create a simple custom tag library application. As such I need a couple import statements like
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext;
    This statements will not compile. I'm using Java 2 1.4_03 and WSDP 1.3. My CLASSPATH currently holds
    c:\jwsdp\common\lib\servlet-api.jar
    and
    c:\j2sdk\lib\mysql-connector-java-3.0.11-stable-bin.jar.
    I've got JAVA_HOME set to c:\j2sdk and JWSDP_HOME set to c:\jwsdp.
    Thank you very much for any assistance you are able to render.

    Thanks for your reply. I'm using the TextPad editor, which uses CLASSPATH.
    I've figured out the answer. I needed to add
    c:\jwsdp\common\lib\jsp-api.jar
    to my CLASSPATH.
    Again, thanks.

  • Problem creating custom tags for site that has no outside internet connecti

    I've created a set of custom tags that work fine until we install our app at the customer site. The customer site has no outside Internet access, and so the DOCTYPE is failing since it references the web-jsptaglibrary_1_1.dtd located on Sun's site.
    I tried copying the dtd locally and got it to work, but the solution sucks because this web-jsptaglibrary_1_1.dtd file is referenced in both my taglib.tld file AND the web-jsptaglibrary_1_1.dtd itself. Soooo....I can put in a URL that references it on the local machine, e.g.,
    In the taglib.tld file:
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.// DTD JSP Tag Library 1.1//EN"
    "http://ClientAAA/web-jsptaglibrary_1_1.dtd">
    In the web-jsptaglibrary_1_1.dtd file:
    <!ATTLIST taglib id ID #IMPLIED
    xmlns CDATA #FIXED
    "http://ClientAAA/AdProduction/web-jsptaglibrary_1_1.dtd"
    >
    but that means for every client that uses this app (and we have several) I have to change that URL inside both these files.
    I tried simply changing it to the relative "web-jsptaglibrary_1_1.dtd", e.g.,
    taglib.tld:
    <!DOCTYPE taglib PUBLIC "-//Sun Microsystems, Inc.// DTD JSP Tag Library 1.1//EN"
    "web-jsptaglibrary_1_1.dtd">
    web-jsptaglibrary_1_1.dtd:
    <!ATTLIST taglib id ID #IMPLIED
    xmlns CDATA #FIXED
    "web-jsptaglibrary_1_1.dtd"
    >
    but then it is requiring me to put the dtd in both my web app root directory AND my jakarta/bin directory. I get the following error:
    XML parsing error on file ../vtaglib.tld: java.io.FileNotFoundException: D:\jakarta\jakarta-tomcat-4.1.29\bin\web-jsptaglibrary_1_1.dtd (The system cannot find the file specified)
    It seems like I must be missing something here. This shouldn't be this hard. And it seems funny that to use custom tags, you have to have Internet access in the first place.
    Help!!! :)
    Thanks.

    Yeah, I think it's a bit ridiculous that in order to make all the tag library examples and instructions work, you have to have access to the Internet. I haven't seen a single example on how to make it work if there is no Internet access. That's very limiting. And I've tried all sorts of other ways of doing it, such as
    <!DOCTYPE taglib SYSTEM "web-jsptaglibrary_1_1.dtd">
    but even then it won't work because I get an error message saying:
    XML parsing error on file /assets/../vtaglib.tld: java.io.FileNotFoundException: D:\jakarta\jakarta-tomcat-4.1.29\bin\web-jsptaglibrary_1_1.dtd (The system cannot find the file specified)
    I just don't think I should have to place this file in the bin directory. There has to be another way. Do I need to modify the dtd somehow? Cuz the dtd has the following line...is this messing it up??
    <!ATTLIST taglib id ID #IMPLIED xmlns CDATA #FIXED "web-jsptaglibrary_1_1.dtd">
    I sure could use some help.

  • How to create custom tags in my own folder..(It is very important to know)

    Hi developers,
    I am try to develop custom tags, But i am fail. I take support of internet. I read some documentations to develop custom tags. I can understand everything to develop custom tags . My problem is where to place taghandler,tld and jsp files in tomcat. Could you please guide me how develop custom tags in tomcat. I try to wax. Please guide me.
    Thanking you.
    with regards
    sure...:)-

    You'll have something like
    tomcat/webapps/mysite
    where 'mysite' is the webapp root.
    Then
    mysite/* - holds JSP (in root directory or any subdirectory except WEB-INF)
    mysite/WEB-INF - holds TLDs
    mysite/WEB-INF/classes - holds non-jar class files
    mysite/WEB-INF/lib - holds the jar file containing the custom tag java code
    You can put java classes in either WEB-INF/classes (for *.class files) or WEB-INF/lib (for *.jar files), doesn't matter which.

  • Weblogic 10.3.6 - Custom Tag Issue

    We have created custom tag in our application. It is working fine with Tomcat and Jetty Server but on Weblogic 10.3.6 we are getting below issue:
    securities.jsp:301:5: The tag handler class was not found "jsp_servlet._tags.__money_tag".
      <neutrino:money placeHolderKey="label.security.faceValue" labelKey="label.security.faceValue"
                             ^------------^
    securities.jsp:301:20: This attribute is not recognized.
      <neutrino:money placeHolderKey="label.security.faceValue" labelKey="label.security.faceValue"
                                            ^------------^
    securities.jsp:301:62: This attribute is not recognized.
      <neutrino:money placeHolderKey="label.security.faceValue" labelKey="label.security.faceValue"
                                                                                      ^------^
    securities.jsp:302:4: This attribute is not recognized.
      mandatory="true" moneyBoxColSpan="4" colSpan="6" validators="amount" errorPath="faceValue"
                            ^-------^
    securities.jsp:302:21: This attribute is not recognized.
      mandatory="true" moneyBoxColSpan="4" colSpan="6" validators="amount" errorPath="faceValue"
                                             ^-------------^
    securities.jsp:302:41: This attribute is not recognized.
      mandatory="true" moneyBoxColSpan="4" colSpan="6" validators="amount" errorPath="faceValue"
                                                                 ^-----^
    securities.jsp:302:53: This attribute is not recognized.
      mandatory="true" moneyBoxColSpan="4" colSpan="6" validators="amount" errorPath="faceValue"
                                                                             ^--------^
    securities.jsp:302:73: This attribute is not recognized.
      mandatory="true" moneyBoxColSpan="4" colSpan="6" validators="amount" errorPath="faceValue"
                                                                                                 ^-------^
    securities.jsp:303:4: This attribute is not recognized.
      id="faceValue" path="faceValue" tabindex="13" viewMode="${view}" maxLength="16" />
                            ^^
    securities.jsp:303:19: This attribute is not recognized.
      id="faceValue" path="faceValue" tabindex="13" viewMode="${view}" maxLength="16" />
                                           ^--^
    securities.jsp:303:36: This attribute is not recognized.
      id="faceValue" path="faceValue" tabindex="13" viewMode="${view}" maxLength="16" />
                                                            ^------^
    securities.jsp:303:50: This attribute is not recognized.
      id="faceValue" path="faceValue" tabindex="13" viewMode="${view}" maxLength="16" />
                                                                          ^------^
    securities.jsp:303:69: This attribute is not recognized.
      id="faceValue" path="faceValue" tabindex="13" viewMode="${view}" maxLength="16" />
                                                                                             ^-------^
    securities.jsp:308:5: The tag handler class was not found "jsp_servlet._tags.__money_tag".
      <neutrino:money placeHolderKey="label.security.price" labelKey="label.security.price"
                             ^------------^
    securities.jsp:308:5: The tag handler class was not found "jsp_servlet._tags.__money_tag".
      <neutrino:money placeHolderKey="label.security.price" labelKey="label.security.price"
                             ^------------^
    securities.jsp:308:20: This attribute is not recognized.
      <neutrino:money placeHolderKey="label.security.price" labelKey="label.security.price"
                                            ^------------^
    securities.jsp:308:58: This attribute is not recognized.
      <neutrino:money placeHolderKey="label.security.price" labelKey="label.security.price"
                                                                                  ^------^
    securities.jsp:309:4: This attribute is not recognized.
      mandatory="true" moneyBoxColSpan="4" colSpan="6" validators="amount" errorPath="price"
                            ^-------^
    securities.jsp:309:21: This attribute is not recognized.
      mandatory="true" moneyBoxColSpan="4" colSpan="6" validators="amount" errorPath="price"
                                             ^-------------^
    securities.jsp:309:41: This attribute is not recognized.
      mandatory="true" moneyBoxColSpan="4" colSpan="6" validators="amount" errorPath="price"
                                                                 ^-----^
    securities.jsp:309:53: This attribute is not recognized.
      mandatory="true" moneyBoxColSpan="4" colSpan="6" validators="amount" errorPath="price"
                                                                             ^--------^
    securities.jsp:309:73: This attribute is not recognized.
      mandatory="true" moneyBoxColSpan="4" colSpan="6" validators="amount" errorPath="price"
                                                                                                 ^-------^
    securities.jsp:310:4: This attribute is not recognized.
      id="price" path="price" tabindex="14" viewMode="${view}" maxLength="16" />
                            ^^
    securities.jsp:310:15: This attribute is not recognized.
      id="price" path="price" tabindex="14" viewMode="${view}" maxLength="16" />
                                       ^--^
    securities.jsp:310:28: This attribute is not recognized.
      id="price" path="price" tabindex="14" viewMode="${view}" maxLength="16" />
                                                    ^------^
    securities.jsp:310:42: This attribute is not recognized.
      id="price" path="price" tabindex="14" viewMode="${view}" maxLength="16" />
                                                                  ^------^
    securities.jsp:310:61: This attribute is not recognized.
      id="price" path="price" tabindex="14" viewMode="${view}" maxLength="16" />
                                                                                     ^-------^
    money.tag:2:25: The encoding specified on the page cannot be different than detected encoding for the file.
    <%@ tag language="java" pageEncoding="UTF-8"%>
                            ^----------^
    money.tag:2:25: The encoding specified on the page cannot be different than detected encoding for the file.
    <%@ tag language="java" pageEncoding="UTF-8"%>
                            ^----------^
    >

    Hi.
    I had similar problems with appc.
    Try to remove the line "<%@ tag language="java" pageEncoding="UTF-8"%>" or at least the pageEncoding attribute from the *.tag files.
    In my case, I had no idea why the compiler complained about encoding. No UTF-8 specific characters were used and both, *.jsp and *.tag set the same encoding by directive.
    If you get rid of the "The encoding specified on the page cannot be different than detected encoding for the file.", you will also get rid of the "The tag handler class was not found" and the resulting errors.

  • Custom Tag Problem With iPlanet

    Hi,
    I've followed the instructions for creating Custom Tags located at: http://docs.iplanet.com/docs/manuals/enterprise/41/rn41sp9.html#18776. I'm using the examples provided and am still getting the:
    org.apache.jasper.JasperException: Unable to open taglibrary /jsps/test-tags.jar : com.sun.xml.tree.TextNode
    error. I've followed the instructions "Make sure you have the DOCTYPE in your taglib.tld..." but I still get the error.
    iPlanet 4.1 Enterprise on Windows 2000
    Any ideas?
    Thanks in advance.

    Hey i am also getting the same error, please let me know if u had solved this problem. i have copied the error message below
    [25/Feb/2002:15:00:46] info ( 260): JSP: JSP1x compiler threw exception
    org.apache.jasper.JasperException: Unable to open taglibrary /jsps/test-tags1.jar : in is null
         at org.apache.jasper.compiler.JspParseEventListener.handleDirective(JspParseEventListener.java:708)
         at org.apache.jasper.compiler.DelegatingListener.handleDirective(DelegatingListener.java:119)
         at org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:190)
         at org.apache.jasper.compiler.Parser.parse(Parser.java:1048)
         at org.apache.jasper.compiler.Parser.parse(Parser.java:1022)
         at org.apache.jasper.compiler.Parser.parse(Parser.java:1018)
         at org.apache.jasper.compiler.Compiler.compile(Compiler.java:173)
         at com.netscape.server.http.servlet.NSServletEntity.load(NSServletEntity.java:230)
         at com.netscape.server.http.servlet.NSServletEntity.update(NSServletEntity.java:149)
         at com.netscape.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:453)
    [25/Feb/2002:15:00:46] warning ( 260): Internal error: Failed to get GenericServlet. (uri=/web/jsps/test-tags.jsp,SCRIPT_NAME=/web/jsps/test-tags.jsp)

  • Custom tag attribute values..

              hi,
              I have created custom tags from my EJB using ejb2jsp tool. I tried the following,
              1 works and the other doesn't,
              a) This works.
              <mytag:foo param1="<%="test"%>" />
              b) this gives me a "ClassCastException" <% String value = "test"; %> <mytag:foo param1="<%=value%>"
              />
              ----++++++ java.lang.ClassCastException: java.lang.Object at javax.servlet.jsp.tagext.TagData.getAttributeString(TagData.java:165)
              at com.niteo.projects.intelXML.xbrl.ejb.jsp_tags._XBRLContentProvider_se tIdTagTEI.isValid(_XBRLContentProvider_setIdTagTEI.java:37)
              at weblogic.servlet.jsp.StandardTagLib.verifyAttributes(StandardTagLib.j ava:443)
              ----++++++
              I have tried all possible tricks, but this doesn't work. Is there something that
              I missed while creating the custom tag Or is it the way I am using the tag..?
              any help pls...
              thx in advance -jay
              

    It seems like you want to be able to clear the default attribute and set an empty attribute in you custom tag. One way around this would be to pass a blank character in. That would force the default to be cleared with the blank. You could take it a step further and trim the attribute value before storing it. Alternatively you could set an overriding attribute such as:
    <slasher:foo name="slasher" ignorewhatever="true" />
    protected String whatever = "some default Value";
    public void setWhatever(String whatever)
         this.whatever = whatever;
    public void setIgnorewhatever(String ignore)
         if(ignore.equals("true"))
              this.whatever = "";
    }Cliff

  • 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 !

  • Sub components problem in custom tag

    Hi!
    Im writing custom tag that do nothing but can contains other components.
    So first I create custom tag with hendler that extends UIComponentTag and component class that extends UIComponentBase
    now tag work but i dont see sub components on the page
    Second i override encodeChildren and getFamily methods with:
    public String getFamily() {       
            return "MyCaller";
    public void encodeChildren(FacesContext context) throws IOException {
            Iterator ch=this.getChildren().iterator();
            while(ch.hasNext()){
                 UIComponent oKid = (UIComponent)ch.next();
                 if(oKid.isRendered()){
                    oKid.encodeBegin(context);
                    oKid.encodeChildren(context);
                    oKid.encodeEnd(context);
            super.encodeChildren(context);
        }But subcomponents not rendered on page.
    So are you know whats wrong

    the problem was in wrong getComponentType() that return wrong value

  • Custom tag names in Awesome WM?

    How do I create custom tag names in the Awesome WM?

    Hi!
    You did not specify which version you are running... So I just thought it might help if I posted the relevant part of my config. I think there is other ways to do it, but this works for me, in both the version in AUR, which is a snapshot of 3.3 development version, and the newest 3.3-rc4. Perhaps it might work in earlier versions too! Enjoy:
    -- {{{ Tags
    -- Define tags table.
    tags = {}
    tags.settings = {
    { name = "urxvt", layout = layouts[1], },
    { name = "www", layout = layouts[1], },
    { name = "media", layout = layouts[7] },
    { name = "mail", layout = layouts[7], },
    { name = "other", layout = layouts[10], setslave = true },
    -- Initialize tags
    for s = 1, screen.count() do
    tags[s] = {}
    for i, v in ipairs(tags.settings) do
    tags[s][i] = tag(v.name)
    tags[s][i].screen = s
    awful.tag.setproperty(tags[s][i], "layout", v.layout)
    awful.tag.setproperty(tags[s][i], "setslave", v.setslave)
    awful.tag.setproperty(tags[s][i], "mwfact", v.mwfact)
    end
    tags[s][1].selected = true
    end
    You can find my entire config at: http://dotfiles.org/~KlavKalashj
    Last edited by KlavKalashj (2009-05-30 17:36:12)

  • Custom tag help

    Hi there,
    I was wondering if someone might help me construct a custom tag handler class that either allows or denies access to a given JSP page? I'll start by showing the code I want to replace in all my JSP pages:
    <%
      String companyID = (String)session.getAttribute("companyID");
      String administratorID = (String)session.getAttribute("administratorID"); 
      if(companyID == null || administratorID == null)
         out.println(ServletUtilities.headWithTitle("ACCESS DENIED") +
        <body><h1>ACCESS DENIED</h1><a href=\"/scholastic/Login.jsp\">Return to Login Page</a></body></html>");
         return;
      else
    %>What this code is doing is extracting from the session object the companyID and administratorID. Both of these were placed into the session object when the user logged into the system. As we know, when a session times out, these IDs no longer exist, thus I test for null. If either value is null, then I create HTML markup that instructs the user to login again.
    So, what would be better is a custom tag that I can call just once, like so:
    <%@ taglib uri="stlib-taglib.tld" prifix="stlib" %>
    <stlib:allow_admin_access />
    The behaviour I want is to prevent the rest of the JSP from loading if the custom tag is unable to obtain the companyID and administratorID from the session object.
    I've not create custom tags before and would like some guidance on the tag handler class. Perhaps declare it:
    public class AllowAdminAccess extends TagSupport
      public int doStartTag(){...}
      public int doEndTag(){...}
    }Please advise,
    Alan

    Ok, I obtained a tutorial I found on the net and am trying to make it work on my application. So far, this is what I have:
    <!-- web.xml -->
    <filter>
          <filter-name>AccessFilter</filter-name>
          <filter-class>mvcs.AccessFilter</filter-class>
          <description>This filter attempts of obtain a User object from the HttpSession.  The User object would have been placed their identifying the user when he/she logged in.  If it doesn't exist, the session has probably timed out, or this is an unauthorized user.  If the User object is null the person is redirected to the Login.jsp page.</description>
          <init-param>
            <param-name>login_page</param-name>
            <param-value>/scholastic/Login.jsp</param-value>
          </init-param>
        </filter>
        <filter-mapping>
             <filter-name>AccessFilter</filter-name>
             <url-pattern>/*</url-pattern>
        </filter-mapping>
    <!-- AccessFilter class -->
    import java.io.IOException;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class AccessFilter implements Filter {
      protected FilterConfig filterConfig;
      private final static String FILTER_APPLIED = "_filter_applied"; 
      public void init(FilterConfig config) throws ServletException {
        this.filterConfig = config;   
      public void doFilter(ServletRequest request, ServletResponse response,
                       FilterChain chain) throws IOException, ServletException
        boolean authorized = false;
        // Ensure that filter is only applied once per request.
        if (request.getAttribute(FILTER_APPLIED) == null)
          request.setAttribute(FILTER_APPLIED, Boolean.TRUE);
          if(request instanceof HttpServletRequest)
            HttpSession session = ((HttpServletRequest)request).getSession(false);
            if(session != null)
              User user = (User)session.getAttribute("scholastic.tracks.user");
              if(user != null)
                 authorized = true;
        if(authorized)
          chain.doFilter(request, response);
          return;
        else if(filterConfig != null)
          String login_page = filterConfig.getInitParameter("login_page");
          System.out.println("login_page: " + login_page);
          if(login_page != null && !login_page.equals(""))
            System.out.println("Step1");
            filterConfig.getServletContext().getRequestDispatcher(login_page).forward(request, response);
            System.out.println("Step2");
            return;
        throw new ServletException("Unauthorized access, unable to forward to login page");
      public void destroy() { }
    }The directory structure for my application goes like this:
    webapps/scholastic/Login.jsp
    webapps/scholastic/*.jsp
    webapps/scholastic/admin/*.jsp
    webapps/scholastic/WEB-INF/classes/servlets.class
    Now, when I launch the browser and try to go to http://localhost:8080/scholastic/Login.jsp AccessFilter kicks in and since there is no User object in the session object yet, authorized will remain false. The logic continues to the line:
    filterConfig.getServletContext().getRequestDispatcher(login_page).forward(request, response);
    But in the end I wind up with a Page Not Found 404 error.
    I tried changing the <param-value>/scholastic/Login.jsp</param-value> to just <param-value>/Login.jsp</param-value> but this resulted in an endless loop condition with the Tomcat container. "/scholastic/Login.jsp" is the correct relative URL. So I'm stuck at this point.
    Please advise,
    Alan

  • Select Option Custom Tag JQUERY

    I have multiple select options on many of my pages, I just just added a jquery filter plugin to one of the select options i.e As User types on an input box the values in the select options gets filtered. This works very well now. How can I make it this into a custom Tag where it can be resused by all the select options on the site. That is the id of the select option and the input box has to be passed to the jquery to automtically filter the content of the Select Option. below is my jquery script.
    <div>Filter<br>
        <input id="txtcomm" type="text" name="">       
    </div>
    <div>
        <select id="slctcomm" multiple style="width:220px">
            <cfloop query="qryobjComm">
                <option value="#Comm#">#Comm#</option>
            </cfloop>
        </select>   
    </div> 
    <script>
        jQuery.fn.filterByText = function(txtcomm, selectSingleMatch) {
          return this.each(function() {
            var slctcomm = this;
            var options = [];
            $(slctcomm).find('option').each(function() {
              options.push({value: $(this).val(), text: $(this).text()});
            $(slctcomm).data('options', options);
            $(txtcomm).bind('change keyup', function() {
              var options = $(slctcomm).empty().data('options');
              var search = $.trim($(this).val());
              var regex = new RegExp(search,'gi');
              $.each(options, function(i) {
                var option = options[i];
                if(option.text.match(regex) !== null) {
                  $(slctcomm).append(
                     $('<option>').text(option.text).val(option.value)
              if (selectSingleMatch === true &&
                  $(slctcomm).children().length === 1) {
                $(slctcomm).children().get(0).selected = true;
        $(function() {
          $('#slctcomm').filterByText($('#txtcomm'), true);
    </script>

    Hi umuayo,
    I guess you want pass the jquery selector for textbox and selectbox. I have created a file named filterByText.cfm which will act as customtag for me.
    for more information regarding custom tag follow this link http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec0b2e1 -7fff.html
    In this example i have created custom tag in the same directory where I will use it. You can create it in different place also. Let us get into the main topic. I will pass the jquery selector for textbox and selectbox to the custom tag by "FilterId" and "slctcomm" attribute and inside customtag I will convert coldfusion valiable to javascript variable and use them to call your function.
    dynamicselectbox.cfm
    CODE:
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <cfquery name="getEmps" datasource="cfdocexamples">
        SELECT * FROM EMPLOYEE
    </cfquery>
    <div>Filter<br>
        <input id="txtcomm" type="text" name="">      
    </div>
    <div>
        <select id="slctcomm" multiple style="width:220px" class="selclass">
            <cfoutput query="getEmps">
                <option value="#Emp_ID#">#FirstName#</option>
            </cfoutput>
        </select>
              <select id="slctcomm2" multiple style="width:220px" class="selclass">
            <cfoutput query="getEmps">
                <option value="#Emp_ID#">#FirstName#</option>
            </cfoutput>
        </select>  
    </div>
    <cf_filterByText FilterId="##txtcomm" slctcomm=".selclass">
    filterByText.cfm
    Code:
    <script type="text/javascript">
    //get the jquery selector from attribute scope
              var filterId="<cfoutput>#Attributes.FilterId#</cfoutput>";
              var selectBoxId="<cfoutput>#Attributes.slctcomm#</cfoutput>";
        jQuery.fn.filterByText = function(txtcomm, selectSingleMatch) {
                        console.log(this);
                        var retvar;
            retvar = this.each(function() {
            var slctcomm = this;
            var options = [];
            $(slctcomm).find('option').each(function() {
              options.push({value: $(this).val(), text: $(this).text()});
            $(slctcomm).data('options', options);
            $(txtcomm).bind('change keyup', function() {
              var options = $(slctcomm).empty().data('options');
              var search = $.trim($(this).val());
              var regex = new RegExp(search,'gi');
              $.each(options, function(i) {
                var option = options[i];
                if(option.text.match(regex) !== null) {
                  $(slctcomm).append(
                     $('<option>').text(option.text).val(option.value)
              if (selectSingleMatch === true &&
                  $(slctcomm).children().length === 1) {
                $(slctcomm).children().get(0).selected = true;
                return retvar;
    //call the function with the selector passed by user.
        $(function() {
          $(selectBoxId).filterByText($(filterId), true);
    </script>
    Thanks
    Saurav

  • Custom tag parameters

              hi,
              I have created custom tags from my EJB using ejb2jsp tool. I tried the following,
              1 works and the other doesn't,
              a) This works.
              <mytag:foo param1="<%="test"%>" />
              b) this gives me a "ClassCastException"
              <% String value="test"; %>
              <mytag:foo param1="<%=value%>" />
              What am I missing here..? Any help pls...
              thx
              -jay
              

    Well, I'm pretty much at a loss here (and I've been trying to figure this out for a few days now!). I've tried setting the attribute value multiple ways including:
    <first:sample atty="<%=strVariable%>"/>
    <first:sample atty="<![CDATA[<%=strVariable%>]]>"/>
    <first:sample atty="<jsp:expression>strVariable</jsp:expression>"/>
    <first:sample>
    <first:parameter name="atty"><jsp:expression>strVariable</jsp:expression></first:parameter>
    </first:sample>
    <first:sample>
    <first:attribute name="atty"><jsp:expression>strVariable</jsp:expression></first:attribute>
    </first:sample>
    <first:sample>
    <jsp:attribute name="atty"><jsp:expression>strVariable</jsp:expression></jsp:attribute>
    </first:sample>
    and none of them seem to work.
    Anyone have any ideas???

  • Problem with custom tags

    Hello..
    I have created custom tags and she gives an error me.
    The code is:
    <%@ taglib uri="mitaglib.tld" prefix="ejemplos" %>
    <HTML>
    <HEAD>
    <TITLE>Tag Hola Mundo</TITLE>
    </HEAD>
    <ejemplos:holamundo/><br>
    <ejemplos:SumaTag num1="2" num2="6" />
    </BODY>
    </HTML>
    The class:
    package helperClasses;
    import java.io.*;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    public class hm extends TagSupport{
    public int doStartTag() throws JspException
    try
    pageContext.getOut().print("Hola Mundo");
    catch (IOException e)
    throw new JspException("Error: IOException" + e.getMessage());
    return SKIP_BODY;
    public int doEndTag() throws JspException
    return EVAL_PAGE;
    package helperClasses;
    import java.io.*;
    import javax.servlet.jsp.*;
    import javax.servlet.jsp.tagext.*;
    public class SumaTag extends TagSupport{
    private int num1,num2;
    public void setNum1(int num1){
    this.num1 = num1;
    public void setNum2(int num2){
    this.num2 = num2;
    public int doStartTag() throws JspException {
    try{
    pageContext.getOut().print("Suma: " + (num1+num2));
    } catch (IOException e) {
    throw new JspException ("Error: IOException" +
    e.getMessage());
    return SKIP_BODY;
    public int doEndTag() throws JspException {
    return SKIP_PAGE;
    The file mitaglib.tld is:
    <?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.1</jspversion>
    <shortname>ejemplos</shortname>
    <uri></uri>
    <info>Etiquetas de ejemplo</info>
         <tag>
         <name>holamundo</name>
         <tagclass>helperClasses.hm</tagclass>
         <bodycontent>empty</bodycontent>
         <info>Saludo</info>
         </tag>
         <tag>
         <name>suma</name>
         <tagclass>helperClasses.SumaTag</tagclass>
         <bodycontent>empty</bodycontent>
         <info>Saludo</info>
         <attribute>
         <name>num1</name>
         <required>true</required>
         <rtexprvalue>false</rtexprvalue>
         </attribute>
         <attribute>
              <name>num2</name>
         <required>true</required>
         <rtexprvalue>false</rtexprvalue>
         </attribute>
         </tag>
    </taglib>

    [22/Dec/2003:09:43:47] failure (11848): Internal error: Unexpected error condition thrown (unknown exception,no description), stack: java.lang.NoSuchMethodError: javax.servlet.jsp.tagext.TagAttributeInfo.<init>(Ljava/lang/String;ZLjava/lang/String;Z)V
         at org.apache.jasper.compiler.TagLibraryInfoImpl.createAttribute(TagLibraryInfoImpl.java:518)
         at org.apache.jasper.compiler.TagLibraryInfoImpl.createTagInfo(TagLibraryInfoImpl.java:426)
         at org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:379)
         at org.apache.jasper.compiler.TagLibraryInfoImpl.<init>(TagLibraryInfoImpl.java:227)
         at org.apache.jasper.compiler.JspParseEventListener.handleDirective(JspParseEventListener.java:701)
         at org.apache.jasper.compiler.DelegatingListener.handleDirective(DelegatingListener.java:110)
         at org.apache.jasper.compiler.Parser$Directive.accept(Parser.java:215)
         at org.apache.jasper.compiler.Parser.parse(Parser.java:1077)
         at org.apache.jasper.compiler.Parser.parse(Parser.java:1042)
         at org.apache.jasper.compiler.Parser.parse(Parser.java:1038)
         at org.apache.jasper.compiler.Compiler.compile(Compiler.java:218)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadJSP(JspServlet.java:193)
         at org.apache.jasper.servlet.JspServlet$JspServletWrapper.access$4(JspServlet.java:167)
         at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:477)
         at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:589)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:865)
         at com.iplanet.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:897)
         at com.iplanet.server.http.servlet.WebApplication.service(WebApplication.java:1065)
         at com.iplanet.server.http.servlet.NSServletRunner.ServiceWebApp(NSServletRunner.java:959)

Maybe you are looking for

  • Stuck in Recovery Mode

    Hi! I downloaded iOS7 via a Wi-Fi network earlier today, and I've been waiting to install it until recently. However, I was having a couple errors when I tried installing it, so I turned it off and back on again, and it started installing just fine.

  • Oracle Streaming in same database - 10g

    Oracle Streaming in 10g database Posted: Sep 21, 2006 4:25 AM Reply Hello, I am trying do streaming at table level for all dml changes from one schema(source) to another schema (target) controlled by admin schema (stream_admin). I have all these sche

  • All my finders colors turned like a film roll "negative"- HELP!!!!!

    my whole appearance turned negative: white turned black, blue is yellow and so on. for no apparent reason!!! help is highly appreciated. and how can something like this happen????? how do i post a screenshot on this forum? iMac 1.8 GHz PPC G5   Mac O

  • How can I store photos on an external hard drive and still manage w IPhoto?

    The hard drive on my MacBook is almost full and I want to move my photos to an external hard drive.  Can I do this and still manage and organize the photos using I Photo?   I can export the photos, but when I do I lose the organization (Events, Album

  • Why does Application Manager show that Lightroom 4.1 is installed when in fact it isn't?

    I attempted to install Lightroom 4.1 three times and it stopped on 99% installed each time.  Restarted Windows 7 and had the following results when I logged into the Application Manager.  I had installed Photoshop CS6 earlier than Lightroom and Muse