4
我正在嘗試創建自定義JSF組件並向其添加方法表達式。這是我的自定義組件的代碼:如何將方法表達式添加到自定義JSF組件
@FacesComponent(AjaxCommand2.COMPONENT_TYPE)
public class AjaxCommand2 extends UIComponentBase {
public static final String COMPONENT_TYPE = "local.test.component.AjaxCommand2";
public static final String COMPONENT_FAMILY = "local.test.component.AjaxCommand2";
private MethodExpression listener;
public MethodExpression getListener() {
return listener;
}
public void setListener(MethodExpression listener) {
this.listener = listener;
}
@Override
public String getRendererType() {
return null;
}
@Override
public String getFamily() {
return COMPONENT_FAMILY;
}
}
這是我的標記庫文件:
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib id="test"
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-facelettaglibrary_2_0.xsd" version="2.0">
<namespace>http://local.test/ui</namespace>
<tag>
<tag-name>ajaxCommand2</tag-name>
<component>
<component-type>local.test.component.AjaxCommand2</component-type>
</component>
<attribute>
<name>listener</name>
<required>false</required>
<type>javax.el.MethodExpression</type>
</attribute>
</tag>
</facelet-taglib>
而且這是在JSF頁面相關代碼:
<test:ajaxCommand2 listener="#{testSessionBean.testActionAjax}" />
我的問題是監聽器的setter永遠不會在我的自定義組件中被調用,並且總是在監聽器屬性中獲得null。
我看不清楚是什麼問題。 任何想法?,我想設置偵聽器屬性指向一個背景bean的特定方法。