我想创建一个自定义标签库,但在处理程序类中我想拥有整数属性。
在 tld 文件中,我有以下代码:
<tag>
<name>circle</name>
<tag-class>draw.Circle</tag-class>
<body-content>jsp</body-content>
<attribute>
<name>x</name>
<required>true</required>
</attribute>
</tag>
还有其他整数属性,但此示例与其他属性相关。
处理程序类,目前看起来是这样的:
public class Circle extends TagSupport{
private Integer x;
public Integer getX() {
return x;
}
public void setX(String x) {
this.x = Integer.parseInt(x);
System.out.println("Set x");
}
}
我没有在tld文件中指定属性类型,默认应该是String。虽然我收到这样的错误:
Unable to find setter method for attribute: x
我还尝试将属性类型修改为:<type>java.lang.Integer</type>
并将 setter 方法修改为:
public void setX(int x) {
}
我得到同样的错误。
我应该如何定义 tld 文件中的属性和处理程序类中的设置器,以便我不会收到设置器错误?