aspose file tools*
The moose likes JSP and the fly likes Unable to find setter method -exception with custom tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Unable to find setter method -exception with custom tag" Watch "Unable to find setter method -exception with custom tag" New topic
Author

Unable to find setter method -exception with custom tag

Mike Halford
Ranch Hand

Joined: Jul 13, 2005
Posts: 31
Ok, I'm having trouble with a custom tag:-

The TLD (the relevant bits):-
<?xml version="1.0" encoding="ISO-8859-1"?>
<!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>1.2</jsp-version>
<short-name>sf</short-name>
<uri>http://stuff.com/tag</uri> <name>myTag</name>
<tag-class>com.stuff.MyTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>yCoord</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>double</type>
</attribute>
<attribute>
<name>xCoord</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>double</type>
</attribute>
</taglib> The Tag class...
public class MyTag extends TagSupport
{
private double xCoord;
private double yCoord;
... other stuff in here including doStartTag() ....

public double getXCoord()
{
return xCoord;
}
/**
* @param coord the xCoord to set
*/
public void setXCoord(double val)
{
this.xCoord = val;
}

/**
* @return the yCoord
*/
public double getYCoord()
{
return yCoord;
}
/**
* @param coord the yCoord to set
*/
public void setYCoord(double val)
{
this.yCoord = val;
}
}

The jsp...
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://stuff.com/tag" prefix="atag" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<atag:myTag
xCoord="1.0"
yCoord="0.0"
/>

</body>
</html>

The problem is that I'm continually getting a runtime exception--org.apache.jasper.JasperException: "Unable to find setter method for attribute: xCoord"

Things I have tried already:-
  • setting the attrbute type to String, eg omitting the <type> in the tld and having the setter method take a String and convertingto double using Double.parseDouble();
  • I have checked that the code is recompiled and deployed correctly etc etc....
  • removing the <rtexprvalue> property
  • with <rtexprvalue>true</rtexprvalue> using xCoord='<%= 5.5 %>'


  • I'm using Tomcat 5.5, Java1.5.0_11 and Eclipse Version: 3.2.2
    Build id: M20070212-1330

    So, the question is , why can't it find the setter method???
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60992
        
      65

    When posting code please remember to use UBB code tags to preserve the formatting and help readability. Please read this for more info.


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 60992
        
      65

    I have a vague recollection of there being a problem with Javabeans properties that start with double capitals -- but that may just be a brain fart.

    In any case, to elimimate that possibility I'd try renaming the mutator setXcoord and using xcoord as the property name. If that works, then we'll know that that was the problem. If not, then we'll know to dig deeper.
    [ February 28, 2007: Message edited by: Bear Bibeault ]
    Mike Halford
    Ranch Hand

    Joined: Jul 13, 2005
    Posts: 31
    Nope that didn't do the trick Here's the stacktrace..

    Mike Halford
    Ranch Hand

    Joined: Jul 13, 2005
    Posts: 31
    Yo ;)!!! You were half way there. I changed the attributes to be xcoord, ycoord. Which didn't quite solve it so I then tweaked the tld to specify the type eg


    and the setter to


    It would seem that if you let the attribute type default to String and convert it to a double in the setter then 'it' still doesn't like it if the member variable type doesn't match. Thanks for the clue
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Unable to find setter method -exception with custom tag