我遇到的问题是h:commandLink放在p:dataTable的一列中。不调用action方法。我正在使用primefaces 2.21和jsf 2.0。 像这样的代码:
<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;
}
答案 0 :(得分:0)
使用action
代替actionListener
:
<h:commandLink value="#{msgs.delete}"
action="#{adminstratorBean.deleteUser(user)}">
</h:commandLink>
无法使用参数调用actionListener
,并且在业务逻辑执行之前(在您的操作方法中)使用。
答案 1 :(得分:0)