You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Hunter Hillegas <li...@lastonepicked.com> on 2001/10/04 00:37:22 UTC

TagLibs: What Am I Doing Wrong? Totally Stumped...

Okay... In the last week I've started on my first taglib project... I have a
couple of books and I think I understand everything but my taglibs donĀ¹t
work...

They just do nothing... I'll post one here with the hope that someone will
point out what I am doing wrong... I don't have access to Catalina's logging
because I'm using the JBoss bundle and no one seems to know where the logs
go...

Anyway, any help is GREATLY appreciated...

All my tags inherit from GenericTag.java:

package com.guerrillabroadcasting.groundswell.tags;

import java.util.*;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class GenericTag extends TagSupport {
    
    public int doStartTag() throws JspException {
        return 0;
    }
    
    public void modifyResponse(String url) {
        try {
            pageContext.include(url);
        }
        catch (Exception e) {
            log("GenericTag: Error including Servlet request: " + url + "
Status: " + e);
        }
    }
    
    public void log(String text) {
        pageContext.getServletContext().log("TagLib Error: " + text);
    }
}

This next tag, newsTag:

package com.guerrillabroadcasting.groundswell.tags;

import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;

public class NewsTag extends GenericTag {
    
    String operation;
    String newsID;
    String returnLimit;
    
    public int doStartTag() throws JspException {
        //this is where everything happens
                
        if (operation.equalsIgnoreCase("getNewsItem") && newsID != null) {
            //get a specific news item by calling the servlet
            modifyResponse("front?action=tagGetNewsItem&rec_num=" + newsID);
        }
        else if (operation.equalsIgnoreCase("getNewsCollection")) {
            if (returnLimit != null) {
                modifyResponse("front?action=tagGetNewsCollection&limit=" +
returnLimit);
            }
            else {
                
modifyResponse("/groundswellController?action=tagGetNews&limit=none");
            }
        }
        else {
            HttpServletRequest request =
(HttpServletRequest)pageContext.getRequest(); //DEBUG
            request.setAttribute("operation", operation); //DEBUG
        
            log("No operation executed: operation: " + operation);
        }
        
        return SKIP_BODY;
    }
    
    public void setOperation(String _operation) {
        this.operation = operation;
    }
    
    public void setNewsID(String newsID) {
        this.newsID = newsID;
    }
    
    public void setReturnLimit(String returnLimit) {
        this.returnLimit = returnLimit;
    }
}


This is a tag that doesn't work... After calling this tag from a JSP like
this:

<%@ taglib uri="/WEB-INF/gs_tags.tld" prefix="gs" %>
<gs:news operation="getNewsCollection" returnLimit="10000" />
<html>
    <head>
    <title>Tag Test</title>
    </head>
    <body bgcolor="white">
Operation: <%= request.getAttribute("operation") %>

    </body>
</html>


Operation shows up as: null.

Now looking at the code, I would expect operation to be: getNewsCollection

But it isn't! Even if I explicitly set operation inside the NewsTag, it
still comes back as null...

What am I doing wrong????

Any help is greatly appreciated.

Hunter