f:在p:dataTable中未调用setPropertyActionListener

时间:2015-03-14 08:31:52

标签: jsf jsf-2 primefaces datatable

我按照Primefaces DataGrid展示来做我的数据表。我想为每行数据表创建一个编辑图像按钮,然后在onclick上我想显示一个编辑对话框表单。

问题是setSelectedChannel方法没有在commandlink上触发,因此当对话框尝试访问selecteChannel字段时出现此错误:

javax.el.PropertyNotFoundException: /WEB-INF/includes/channels.xhtml @54,91 value="#{channelBean.selectedChannel.name}": Target Unreachable, 'selectedChannel' returned null

所以这是我的xhtml包含页面:

<ui:composition 
xmlns="http://www.w3.org/1999/xhtml"
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">
<h:form id="channelForm">    
    <p:dataTable var="channel" value="#{channelBean.channels}">
        <p:column headerText="Name">
            <h:outputText value="#{channel.name}" />
        </p:column>

        <p:column headerText="Field 1">
            <h:outputText value="#{channel.field1}" />
        </p:column>

        <p:column headerText="Field 2">
            <h:outputText value="#{channel.field2}" />
        </p:column>

        <p:column headerText="ApiWriteKey">
            <h:outputText value="#{channel.apiWriteKey}" />
        </p:column>

        <p:column headerText="Edit">
            <p:commandLink update=":channelForm:panelEditCh" oncomplete="PF('dlg2').show();" title="Edit">
                <h:outputText styleClass="ui-icon ui-icon-search" style="margin:0 auto;" />
                <f:setPropertyActionListener value="#{channel}" target="#{channelBean.selectedChannel}" />
            </p:commandLink>
        </p:column>
    </p:dataTable>
    <p:dialog  id="dialogNewChannel" header="New Channel" widgetVar="dlg1" modal="false"  >
        <h:panelGrid columns="2" style="margin-bottom:10px" cellpadding="5">
            <p:outputLabel for="channelName" value="Channel name:" />
            <p:inputText id="channelName" value="#{channelBean.name}" />

            <p:outputLabel for="channelDesc" value="Channel description:" />
            <p:inputText id="channelDesc" value="#{channelBean.description}" />

            <p:outputLabel for="channelField1" value="Channel field 1:" />
            <p:inputText id="channelField1" value="#{channelBean.field1}" />
            <p:outputLabel for="channelField2" value="Channel field 2:" />
            <p:inputText id="channelField2" value="#{channelBean.field2}"  />
        </h:panelGrid>
        <p:commandButton id="saveButton" value="Save" action="#{channelBean.saveChannel}" update="channelForm" ajax="true" />
        <p:commandButton value="Cancel" type="button" action="#{channelBean.resetForm}" onclick="PF('dlg1').hide();" />

    </p:dialog>   
    <p:dialog  id="dialogEditChannel" header="Edit Channel" widgetVar="dlg2" modal="false"  >
        <h:panelGrid id="panelEditCh" columns="2" style="margin-bottom:10px" cellpadding="5">
            <p:outputLabel for="channelNameEdit" value="Channel name:" />
            <p:inputText id="channelNameEdit" value="#{channelBean.selectedChannel.name}" />

            <p:outputLabel for="channelDescEdit" value="Channel description:" />
            <p:inputText id="channelDescEdit" value="#{channelBean.selectedChannel.description}" />

            <p:outputLabel for="channelField1Edit" value="Channel field 1:" />
            <p:inputText id="channelField1Edit" value="#{channelBean.selectedChannel.field1}" />
            <p:outputLabel for="channelField2Edit" value="Channel field 2:" />
            <p:inputText id="channelField2Edit" value="#{channelBean.selectedChannel.field2}"  />
        </h:panelGrid>
        <p:commandButton id="saveButtonEdit" value="Save" action="#{channelBean.saveChannel}" update="channelForm" ajax="true" />
        <p:commandButton value="Cancel" type="button" action="#{channelBean.resetForm}" onclick="PF('dlg2').hide();" />

    </p:dialog>  
    <p:spacer></p:spacer>
    <p:spacer></p:spacer>
    <p:commandButton value="New Channel" type="button" onclick="PF('dlg1').show();" />
     <!--  <p:blockUI block="dialogNewChannel" trigger="saveButton">  

            <p:graphicImage name="images/ajax-loader-large.gif"/>  
    </p:blockUI>
    -->
</h:form> 

和ManagedBean:

@ManagedBean
@ViewScoped
public class ChannelBean implements Serializable {
/**
 * 
 */
private static final long serialVersionUID = -1668407926998690759L;
private String idChannel;
private String apiWriteKey;
private String name;
private String description;
private String userId;
private String field1;
private String field2;

private Channel selectedChannel;


private List<Channel> channels= new ArrayList<Channel>() ;

@PostConstruct
public void populateChannelList(){
    refreshList();
}
public void refreshList(){
    HttpSession session = Util.getSession();
    int idUser=-1;
    if(session!=null &&session.getAttribute("idUser")!=null){
        idUser=(int) session.getAttribute("idUser");
    }
    channels=ChannelDAO.getChannels(idUser);

}


public void saveChannel(){
    ....
}
public void resetForm(){
    idChannel="";
    apiWriteKey="";
    name="";
    description="";
    userId="";
    field1="";
    field2="";
}

public String getIdChannel() {
    return idChannel;
}
public void setIdChannel(String idChannel) {
    this.idChannel = idChannel;
}
public String getApiWriteKey() {
    return apiWriteKey;
}
public void setApiWriteKey(String apiWriteKey) {
    this.apiWriteKey = apiWriteKey;
}
public String getName() {
    return name;
}
public void setName(String name) {
    this.name = name;
}
public String getDescription() {
    return description;
}
public void setDescription(String description) {
    this.description = description;
}
public String getUserId() {
    return userId;
}
public void setUserId(String userId) {
    this.userId = userId;
}
public String getField1() {
    return field1;
}
public void setField1(String field1) {
    this.field1 = field1;
}
public String getField2() {
    return field2;
}
public void setField2(String field2) {
    this.field2 = field2;
}

public List<Channel> getChannels() {
    return channels;
}
public void setChannels(List<Channel> channels) {
    this.channels = channels;
}

public Channel getSelectedChannel() {
    return selectedChannel;
}
public void setSelectedChannel(Channel selectedChannel) {
    this.selectedChannel = selectedChannel;
}

}

0 个答案:

没有答案