JSF - 自定义组件,属性表达式问题

时间:2010-03-10 18:37:22

标签: jsf custom-component

我想创建具有属性“title”的自定义组件,该组件可以有表达式,但是我收到此错误:

无法将字符串“#{myBean.text}”转换为属性“title”的类“javax.el.ValueExpression”:Property Editor未向PropertyEditorManager注册

引起: org.apache.jasper.JasperException - 无法将字符串“#{myBean.text}”转换为属性“title”的类“javax.el.ValueExpression”:Property Editor未向PropertyEditorManager注册

我的课程:

<d:ticker title="#{myBean.text}">
    <f:verbatim>Hello JSF Custom Component</f:verbatim>
</d:ticker>

MyBean.java

public class MyBean {

    private String text = "TITLE!!!!";

    public String getText() {
        return text;
    }
}

TickerTag.java

private ValueExpression title = null;
public void setTitle(ValueExpression title)
{
    this.title = title;
}

protected void setProperties(UIComponent component) {

        super.setProperties(component);
    if (title != null) {
        if (!title.isLiteralText()) {
            component.setValueExpression("title", title);
        } else {
    component.getAttributes().put("title",title.getExpressionString());
    }
}

taglib.tld

<taglib version="2.1" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee web-jsptaglibrary_2_1.xsd">
    <tlib-version>1.0</tlib-version>
    <jsp-version>1.2</jsp-version>
    <short-name>d</short-name>
    <uri>http://jsftutorials.com/</uri>
    <tag>
        <name>ticker</name>
        <tag-class>ticker.TickerTag</tag-class>
        <body-content>JSP</body-content>
        <attribute>
            <name>title</name>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
    </tag>
</taglib>

有人看到问题吗?

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,并且能够通过在我的taglib.tld文件中包含deferred-value标记来解决它。当组件具有可以使用EL表达式设置的属性时,它是必需的。 'type'标签是EL表达式应该评估的类型。

taglib.tld:

<tag>
  <name>CustomComponent</name>
  <tag-class>com.test.components.CustomComponent</tag-class>
  <attribute> 
     <name>someAttribute</name> 
     <description>The custom attribute</description>
     <deferred-value>
        <type>java.lang.String</type>
     </deferred-value>
  </attribute> 
</tag>
相关问题