【发布时间】:2013-12-13 18:51:18
【问题描述】:
JSP 标签的属性是否可以有不同的值类型?
<tag>
<name>init</name>
<tag-class>com.example.InitTag</tag-class>
<body-content>empty</body-content>
<attribute>
<name>locale</name>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
public class InitTag extends SimpleTagSupport {
private Locale locale;
public InitTag() {
setLocale(Locale.getDefault());
}
public void setLocale(String locale) {
setLocale(SetLocaleSupport.parseLocale(locale));
}
public void setLocale(Locale locale) {
this.locale = locale;
}
}
现在我希望能够使用 Locale 对象以及 String 对象作为属性值:
<mytag:init locale="en" />
or
<mytag:init locale="${anyLocaleObject}" />
但是得到这个异常:org.apache.jasper.JasperException: Unable to convert string "en" to class "java.util.Locale" for attribute "locale": Property Editor not registered with the PropertyEditorManager
我必须使用上面提到的“属性编辑器”吗?那怎么用呢?
【问题讨论】: