2010-03-10 91 views
1

我想創建一個屬性「稱號」,可以有表達的自定義組件,但問題我得到這個錯誤:JSF - 自定義組件,以表達對屬性

無法轉換字符串「#{} myBean.text」上課「javax.el.ValueExpression」爲屬性的「標題」:屬性編輯器無法與PropertyEditorManager

所致註冊: org.apache.jasper.JasperException - 無法轉換字符串「#{} myBean.text」屬性「title」的類「javax.el.ValueExpression」:屬性編輯器未向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

我遇到了同樣的問題,並能通過在我的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> 
+0

它示出了用於'<延遲值>'錯誤。我使用的* doctype *是<!DOCTYPE taglib PUBLIC「 - // Sun Microsystems,Inc. //DTD JSP Tag Library 1.2 // EN」「http://java.sun.com/dtd/web-jsptaglibrary_1_2。 DTD「>' – 2016-06-06 06:19:31