我正在重构我的代码以使用自定义facelets taglibs来" DRY"我的代码。
一切正常,但是当我需要参数化一个ajax监听器动作时,我得到了一个异常:
Target Unreachable, identifier 'backingBean' resolved to null: javax.el.PropertyNotFoundException: Target Unreachable, identifier 'backingBean' resolved to null
这是我的代码:
的index.xhtml :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:test="http://ericsantanna.com/faceletsTest/jsf/facelets"
>
<h:head>
<h:outputStylesheet name="tema.css" library="css" />
</h:head>
<h:body>
<h:form id="testForm">
<test:faceletsTest
id="testPickList"
values="#{controller.pickListData}"
backingBean="${controller}"
transferHandle="handleTranferEvent"
/>
</h:form>
</h:body>
</html>
faceletsTest.xhtml :
<ui:composition
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:pickList
id="#{id}"
value="#{values}"
var="s"
itemValue="#{s}"
itemLabel="#{s}">
<p:ajax event="transfer" listener="#{backingBean[transferHandle]}" />
</p:pickList>
</ui:composition>
Controller.java :
package com.ericsantanna.faceletEventTest;
import java.util.Arrays;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import org.jboss.logging.Logger;
import org.primefaces.event.TransferEvent;
import org.primefaces.model.DualListModel;
/**
* @author Eric Sant'Anna
*
*/
@RequestScoped
@ManagedBean
public class Controller {
private DualListModel<String> pickListData = new DualListModel<String>();
@PostConstruct
public void init() {
pickListData.getSource().addAll(Arrays.asList("A", "B", "C"));
}
// Show message if uncommented:
// public void handleTranferEvent() {
// Logger.getLogger(getClass()).info("Sem argumentos...");
// }
public void handleTranferEvent(TransferEvent event) {
Logger.getLogger(getClass()).info("Você escolheu: " + formatItems(event.getItems()));
}
public String formatItems(List<?> list) {
String result = "";
for(Object s : list) result += s;
return result;
}
public DualListModel<String> getPickListData() {
return pickListData;
}
public void setPickListData(DualListModel<String> pickListData) {
this.pickListData = pickListData;
}
}
faceletsTest.taglib.xml :
<?xml version="1.0" encoding="UTF-8"?>
<facelet-taglib
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://ericsantanna.com/faceletsTest/jsf/facelets</namespace>
<tag>
<tag-name>faceletsTest</tag-name>
<source>tags/test/faceletsTest.xhtml</source>
</tag>
</facelet-taglib>
为什么p:ajax没有将TransferEvent添加到动作中? 怎么解决?