我已经创建了一个自定义组件,根据bean向页面显示一些数据。问题是我无法将bean绑定到我的组件。我在ValueExpresion
课程中使用UIComponentELTag
。我收到此错误:
org.apache.jasper.JasperException:PWC6338:无法转换“#{helloBean.color}”作为bean的属性颜色javax.el.ValueExpression:PWC6348:属性编辑器未向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>
答案 0 :(得分:1)
您忘记<type>
color
<deferred-value>
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>
<deferred-value>
。{/}
welcome
使用{{1}},您基本上指定该属性接受延迟值表达式,并且应该将其视为而不是普通的香草字符串。
请注意,您的{{1}}属性已丢失。您可能也想添加它。