commanLink 在 p:dataTable 中不起作用
我对 ah:commandLink 放置在 p:dataTable 的列中遇到问题。未调用操作方法。我正在使用 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;
}
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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
action
而不是actionListener
:actionListener
不能使用参数调用,并且应在之前使用业务逻辑被执行(在您的操作方法中)。Use
action
instead ofactionListener
:The
actionListener
can't be invoked with an argument and is intended to use before business logic gets executed (in your action method).你应该使用
< p:命令链接>
而不是
< h:命令链接>
当在里面时
< p:数据表>。
you should use
< p:commandLink>
instead of
< h:commandLink>
when inside
< p:dataTable>.