【发布时间】:2012-05-29 21:33:07
【问题描述】:
我有一个 primefaces 数据表,其中显示了记录数。
I want navigate to another page on the rowSelect event (to edit the selected entity for example).
我能找到的最接近的示例/演示是使用 p:ajax 标记将 rowSelect 事件绑定到侦听器方法 http://www.primefaces.org/showcase-labs/ui/datatableRowSelectionInstant.jsf
我也有一篇同样的文章http://forum.primefaces.org/viewtopic.php?f=3&t=14664
,我尝试和他们一样实现。但它也没有奏效。
我正在尝试这种方式,如果我错过了什么,请指导我。
<p:dataTable var="product" value="#{addPatientBB.patientAddList}" paginator="true" rows="10" selection="#{addPatientBB.pat}" selectionMode="single"> <p:ajax event="rowSelect" listener="#{addPatientBB.onRowSelect}" /> <p:column> <f:facet name="header"> <h:outputText value="FirstName" /> </f:facet> <h:outputText value="#{product.firstName}" /> </p:column> <p:column> <f:facet name="header"> <h:outputText value="Email" /> </f:facet> <h:outputText value="#{product.email}" /> </p:column> <p:column> <f:facet name="header"> <h:outputText value="Gender" /> </f:facet> <h:outputText value="#{product.gender}" /> </p:column> </p:dataTable>
Backing bean 是:
@ManagedBean
@ViewScoped
public class AddPatientBB implements Serializable
{
private Patient pat;
public Patient getPat()
{
System.out.println("tried to get pat");
return pat;
}
public void setPat(Patient pat)
{
this.pat = pat;
System.out.println("tried to set pat");
}
public void onRowSelect()
{
System.out.println("inside onRow select Method");
ConfigurableNavigationHandler configurableNavigationHandler = (ConfigurableNavigationHandler) FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
System.out.println("navigation objt created");
configurableNavigationHandler.performNavigation("Page?faces-redirect=true");
// Page is my navigation page where I wish to navigate named as
// "Page.xhtml"
System.out.println("Navigation executed");
}
}
那么如何在 rowselect 事件中导航到另一个页面?以及如何在导航表单后显示其值。
我能够进入 onRowSelect() 方法,实际上问题是他无法获取或理解该路径:
configurableNavigationHandler.performNavigation("Page?faces-redirect=true");
因此他无法在此行之后打印任何日志。 为什么会这样?是因为我在使用 Liferay 吗?
请指导我。
【问题讨论】:
-
你的代码会发生什么?是否执行了 onRowSelect() 方法? bean 中是否设置了选定的 Patient?
-
不,bean中甚至没有选择患者,也没有执行onrowselect方法
-
是h:form包围的dataTable吗?
-
是的,它被 h:form 包围了,我也尝试删除它,但仍然没有得到任何日志,为什么?
-
它必须被 h:form 包围,所以不要删除它们。尝试将 rowKey 属性添加到数据表中:rowKey="{product.id}"(将 id 替换为类的实际 id 属性)。
标签: ajax jsf-2 primefaces liferay-6