1

I've created a custom component that display some data to the page according to the bean. The problem is I cand't bind the bean to my component. I use ValueExpresion in UIComponentELTag class. I am receiving this error:

org.apache.jasper.JasperException: PWC6338: Cannot convert "#{helloBean.color}" for the attribute color of the bean javax.el.ValueExpression: PWC6348: Property editor not registered with the PropertyEditorManager

index.jsp

<d:hello name="Something"
    color="#{helloBean.color}" 
    welcome="#{helloBean.welcome}">
</d:hello>

hello.tld

<tag>
    <name>hello</name>
    <tag-class>custom.HelloTag</tag-class>
    <body-content>JSP</body-content>
    <attribute>
        <name>name</name>
        <type>java.lang.String</type>
    </attribute>
    <attribute>
        <name>color</name>
        <type>java.lang.String</type>
    </attribute>
</tag>

HelloTag.java`

public class HelloTag extends UIComponentELTag {
    ValueExpression color;
    ValueExpression welcome;
    String name;

    public ValueExpression getColor() {
        return color;
    }

    public void setColor(ValueExpression color) {
        this.color = color;
    }
    @Override
    protected void setProperties(UIComponent component) {System.out.println("IN");
        super.setProperties(component);
        UIHello componentCst = (UIHello) component;
        if (color.isLiteralText()) {
        componentCst.setValueExpression("color", color);
        } else {
        component.getAttributes().put("color", color.getExpressionString());
    }

        componentCst.getAttributes().put("color", "color:" + getColor() + ";");
        componentCst.getAttributes().put("name", getName());
    }
}

UIHello.java - extends UIOutput

public class UIHello extends UIOutput {
    ...
}

faces-config.xml

<faces-config
    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 http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"
    version="1.2">
    <component>
        <component-type>hello</component-type>
        <component-class>custom.UIHello</component-class>
    </component>
    <managed-bean>
        <managed-bean-name>helloBean</managed-bean-name>
        <managed-bean-class>dto.HelloBeanDTO</managed-bean-class>
        <managed-bean-scope>session</managed-bean-scope>
    <managed-property>
        <property-name>color</property-name>
        <property-class>java.lang.String</property-class>
        <value>green</value>
    </managed-property>
    <managed-property>
        <property-name>welcome</property-name>
        <property-class>java.lang.String</property-class>
        <value>Bine ai venit</value>
    </managed-property>
    </managed-bean>

    <render-kit>
        <display-name>Hello Render</display-name>
    <renderer>
        <display-name>Hello Render</display-name>
        <component-family>hello</component-family>
        <renderer-type>hello</renderer-type>
        <renderer-class>custom.HelloRender</renderer-class>
        </renderer>
    </render-kit>
</faces-config>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Emanuel
  • 6,622
  • 20
  • 58
  • 78

1 Answers1

1

You forgot to surround <type> of the color attribute with <deferred-value> in hello.tld.

<tag>
    <name>hello</name>
    <tag-class>custom.HelloTag</tag-class>
    <body-content>JSP</body-content>
    <attribute>
        <name>name</name>
        <type>java.lang.String</type>
    </attribute>
    <attribute>
        <name>color</name>
        <deferred-value>
            <type>java.lang.String</type>
        </deferred-value>
    </attribute>
</tag>

With the <deferred-value> you're basically specifying that the attribute accepts a deferred value expression and should be treated as such instead of as a plain vanilla string.

Note that your welcome attribute is missing. You might want to add it as well.

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • The error is gone, but now the attribute color = "#{helloBean.color}" text, instead of the value of the attribute color from helloBean. – Emanuel Jan 18 '12 at 20:48
  • SOLVED - I've used this code to get the value from the ValueExpression object: color.getValue( FacesContext.getCurrentInstance().getELContext() ) – Emanuel Jan 18 '12 at 21:55