seoirse
asked on
Problem getting Java Tag working
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(Strin g newPageKey, String newPageTypeKey) throws JspException {
try {
pageKey = Integer.parseInt(newPageKe y);
} 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(newPageTy peKey);
} 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 (htmlStrin g);
}
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</tlibvers ion>
<jspversion>1.1</jspversio n>
<shortname>myTestTag</shor tname>
<info>My Tag Library</info>
<tag>
<name>dynamicPages</name>
<tagclass>com.projectTest. text.tags. DynamicPag esTag</tag class>
<bodycontent>JSP</bodycont ent>
<info>Simple example</info>
<attribute>
<name>pageKey</name>
<required>true</required>
<rtexprvalue>true</rtexprv alue>
</attribute>
<attribute>
<name>pageTypeKey</name>
<required>true</required>
<rtexprvalue>true</rtexprv alue>
</attribute>
</tag>
</taglib>
When I include the tag on a jsp page as follows:
<%@ taglib uri="/WEB-INF/customTags.t ld" prefix="rbsa" %>
I get an error as follows
Root Cause --------------- : allaire.jrun.jsp.NoSuchAtt ributeExce ption: The tag handler 'com.projectTest.text.tags .DynamicPa gesTag' 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?
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(Strin
try {
pageKey = Integer.parseInt(newPageKe
} 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(newPageTy
} 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
}else{
tfr.setFilePath(Page.TypeB
}
htmlString = tfr.getText();
}
public int doEndTag() throws JspTagException {
try {
pageContext.getOut().write
}
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",
};
}
}
My custom tld file
<?xml version="1.0"?>
<taglib>
<tlibversion>1.0</tlibvers
<jspversion>1.1</jspversio
<shortname>myTestTag</shor
<info>My Tag Library</info>
<tag>
<name>dynamicPages</name>
<tagclass>com.projectTest.
<bodycontent>JSP</bodycont
<info>Simple example</info>
<attribute>
<name>pageKey</name>
<required>true</required>
<rtexprvalue>true</rtexprv
</attribute>
<attribute>
<name>pageTypeKey</name>
<required>true</required>
<rtexprvalue>true</rtexprv
</attribute>
</tag>
</taglib>
When I include the tag on a jsp page as follows:
<%@ taglib uri="/WEB-INF/customTags.t
I get an error as follows
Root Cause --------------- : allaire.jrun.jsp.NoSuchAtt
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?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.