我正在学习使用JSF2.0的复合组件,我希望我的组件能够通过支持bean触发方法,所以我创建了一个简单的示例,但有些地方不对劲。
--这是我创建的组件:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:composite="http://java.sun.com/jsf/composite">
<composite:interface>
<composite:attribute name="attribute1"/>
<composite:attribute name="attribute2"/>
<composite:attribute name="actionBtnText"/>
<composite:attribute name="actionMethod" method-signature="java.lang.String action()"/>
</composite:interface>
<composite:implementation>
<h:form>
<h:inputText value="#{cc.attrs.attribute1}"/>
<br/>
<h:inputText value="#{cc.attrs.attribute2}"/>
<br/>
<h:commandButton action="#{cc.attrs.actionMethod}" value="#{cc.attrs.actionBtnText}"/>
</h:form>
</composite:implementation>
</html>--这是我在JSF页面中使用它的方式
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:custom="http://java.sun.com/jsf/composite/custom">
...
<h:body>
<custom:demoCustomComponent attribute1="#{demoBB.value1 }" attribute2="#{demoBB.value2 }" actionBtnText="Button text!" actionBtn="#{demoBB.act}"/>
</h:body>,这是向组件为的页面提供支持的后台bean
@Named("demoBB")
@RequestScoped
public class DemoBB {
private String value1;
private String value2;
public String getValue1() {
return value1;
}
public String act() {
System.out.println("Input 1: " + value1 + "\nInput 2: " + value2);
return null;
}
//Getters and setters
public void setValue1(String value1) {
this.value1 = value1;
}
public String getValue2() {
return value2;
}
public void setValue2(String value2) {
this.value2 = value2;
}
}组件似乎呈现得很好,但是当我按下按钮时,会得到一个异常,即:
javax.faces.FacesException:无法使用EL表达式#{cc.attrs.actionMethod}使用页面解析复合组件
在组件的接口或实现上有什么错误吗?为什么不工作?
发布于 2011-10-18 12:36:29
您使用属性名actionBtn定义了操作方法
<custom:demoCustomComponent ... actionBtn="#{demoBB.act}"/>但您希望它是属性名actionMethod
<composite:attribute name="actionMethod" method-signature="java.lang.String action()"/>对齐它。应该是一样的。
https://stackoverflow.com/questions/7806831
复制相似问题