Solved

Problem getting Java Tag working

Posted on 2002-04-04
1
202 Views
Last Modified: 2010-03-31
Hi,
  I have updated a java tag class and it's associated tld file. My tag worked fine before, but now does not.
Here is my code


package com.projectTest.text.tags;

import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;
import com.projectTest.text.*;
import com.projectTest.page.*;
import com.projectTest.*;
import com.projectTest.exceptions.*;


public class DynamicPagesTag extends TagSupport{

  private JspWriter jspWriter = null;
  private int pageKey = 0;
  private int pageTypeKey = 0;
  private String htmlString = null;

  /*
  * Setting of tag attribute
  */
  public void setPageKeyAttributes(String newPageKey, String newPageTypeKey) throws JspException {
 
    try {
      pageKey = Integer.parseInt(newPageKey);
    } catch (NumberFormatException nfe) {
      throw new JspException("Please set the pageKey as a positive integer value greater than or equal to one");
    }
    try {
      pageTypeKey = Integer.parseInt(newPageTypeKey);
    } catch (NumberFormatException nfe) {
      throw new JspException("Please set the pageTypeKey as a positive integer value greater than or equal to one");
    }  


  }


  public int doStartTag() throws JspTagException, JspException {

    getPageContentHTML();

    return EVAL_BODY_INCLUDE;
  }

  private void getPageContentHTML() throws JspException{
    TextFileReader tfr = new TextFileReader();
   
    if (pageTypeKey == Page.TypeA) {
      tfr.setFilePath(Page.TypeA + pageKey + ".txt");
    }else{
      tfr.setFilePath(Page.TypeB + pageKey + ".txt");
    }
   
    htmlString = tfr.getText();
  }

  public int doEndTag() throws JspTagException {
    try {
      pageContext.getOut().write(htmlString);

    }
    catch(IOException io) {
      throw new JspTagException("Could not write to JSP");
    }

    return EVAL_PAGE;
  }


}

My TEI Class as follows


package com.projectTest.text.tags;

import javax.servlet.jsp.tagext.*;

public class DynamicPagesTagTEI extends TagExtraInfo{
  public VariableInfo[] getVariableInfo(TagData data){
    return new VariableInfo[] {
        new VariableInfo("htmlString", "java.lang.String", true, VariableInfo.NESTED)
        };
  }
}


My custom tld file

<?xml version="1.0"?>
<taglib>
  <tlibversion>1.0</tlibversion>
  <jspversion>1.1</jspversion>
  <shortname>myTestTag</shortname>
  <info>My Tag Library</info>

<tag>
    <name>dynamicPages</name>
    <tagclass>com.projectTest.text.tags.DynamicPagesTag</tagclass>
    <bodycontent>JSP</bodycontent>
    <info>Simple example</info>
    <attribute>
      <name>pageKey</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
    <attribute>
      <name>pageTypeKey</name>
      <required>true</required>
      <rtexprvalue>true</rtexprvalue>
    </attribute>
</tag>

</taglib>


When I include the tag on a jsp page as follows:

<%@ taglib uri="/WEB-INF/customTags.tld" prefix="rbsa" %>

I get an error as follows

Root Cause --------------- : allaire.jrun.jsp.NoSuchAttributeException: The tag handler 'com.projectTest.text.tags.DynamicPagesTag' does not have a setter for the attribute 'pageKey' specified in the tld.


The only difference between this and my previous DynamicPagesTag was that there was no attribute called pageTypeKey. This iwas something I then added in. Since then the error is occuring. Do you see where I am going wrong?



0
Comment
Question by:seoirse
1 Comment
 
LVL 3

Accepted Solution

by:
saxaboo earned 200 total points
ID: 6917740
Rather than

public void setPageKeyAttributes(String,String)

use

public void setPageKey(String){...}
and
public void setPageTypeKey(String){...}

Hope this helps,

-S
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java string replace 11 61
How to convert from xls to xlsx using java 7 84
java example issue 5 42
Eclipse for Java EE development 2 43
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question