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

发布于 2024-08-24 05:51:25 字数 1819 浏览 3 评论 0原文

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

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

原因如下: org.apache.jasper.JasperException - 无法将属性“title”的字符串“#{myBean.text}”转换为类“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>

有人看到这个问题吗?

I want to create custom component with attribute "title" that can have expression but I get this error:

Unable to convert string "#{myBean.text}" to class "javax.el.ValueExpression" for attribute "title": Property Editor not registered with the PropertyEditorManager

Caused by:
org.apache.jasper.JasperException - Unable to convert string "#{myBean.text}" to class "javax.el.ValueExpression" for attribute "title": Property Editor not registered with the PropertyEditorManager

My classes:

<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>

anybody see the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

愁杀 2024-08-31 05:51:25

我遇到了同样的问题,并且能够通过在我的 taglib.tld 文件中包含延迟值标记来解决它。当组件具有可以使用 EL 表达式设置的属性时,这是必需的。 “type”标签是 EL 表达式应计算的类型。

标签库.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>

I encountered the same problem, and was able to solve it by including the deferred-value tag in my taglib.tld file. It's required when the component has an attribute that can be set with an EL expression. The 'type' tag is the type that the EL expression should evaluate to.

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文