I have a problem with a h:commandLink placed in a column in p:dataTable. The action method is not called. I'm using primefaces 2.21 and jsf 2.0. the code like this:
<ui:define name="center">
<h:form id="form1">
<p:dataTable id="userDataTable"
value="#{adminstratorBean.periodicalUsers}" var="user"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<f:facet name="header">
Ajax Pagination
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Id" />
</f:facet>
<h:outputText value="#{user.id}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{user.name}"></h:outputText>
开发者_开发知识库 </p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Password" />
</f:facet>
<h:outputText value="#{user.password}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Sex" />
</f:facet>
<h:outputText value="#{user.sex}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Email" />
</f:facet>
<h:outputText value="#{user.mail}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Phone" />
</f:facet>
<h:outputText value="#{user.phone}"></h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Birthday" />
</f:facet>
<h:outputText value="#{user.birthday}">
<f:convertDateTime type="date"></f:convertDateTime>
</h:outputText>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Delete" />
</f:facet>
<h:commandLink value="#{msgs.delete}"
actionListener="#{adminstratorBean.deleteUser(user)}">
</h:commandLink>
</p:column>
</p:dataTable>
</h:form>
</ui:define>
package wls.bean;
import java.io.Serializable;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
import org.primefaces.component.datatable.DataTable;
import wls.entity.*;
import wls.myEJB.*;
@ManagedBean
@SessionScoped
public class AdminstratorBean implements Serializable{
@EJB
CommonEJBLocal commonEJB;
@EJB
AdminstratorEJBLocal adminstratorEJB;
List<PeriodicalUser> periodicalUsers;
//Logic Method
public List<PeriodicalUser> getPeriodicalUsers() {
periodicalUsers = adminstratorEJB.listPeriodicalUser();
return periodicalUsers;
}
public String deleteUser(PeriodicalUser selectedUser) {
System.out.println("DEledsfkjsdlkfjldkfjldsk");
System.out.println(selectedUser.getName());
adminstratorEJB.deletePeriodicalUser(selectedUser.getId());
return null;
}
Use action
instead of actionListener
:
<h:commandLink value="#{msgs.delete}"
action="#{adminstratorBean.deleteUser(user)}">
</h:commandLink>
The actionListener
can't be invoked with an argument and is intended to use before business logic gets executed (in your action method).
you should use < p:commandLink> instead of < h:commandLink> when inside < p:dataTable>.
精彩评论