![](/img/trans.png)
[英]JSF PrimeFaces rowSelect for one datatable being called from another datatable
[英]Navigate to another page on rowselect of datatable in primefaces
我有一個顯示記錄數量的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( “?頁面重定向=真”);
因此他無法在此行之后打印任何日志。 為什么會這樣? 是因為我正在使用Liferay?
Pla指導我。
我認為onRowSelect永遠不會被執行,因為你定義錯了。
試試這個:
public void onRowSelect(SelectEvent event)
{
FacesContext.getCurrentInstance().getExternalContext().redirect("page.xhtml?id=" +pat.getId());
}
如果你正在使用FacesServlet,那么使用.jsf而不是.xhtml
public void onRowSelect(SelectEvent event)
{
FacesContext.getCurrentInstance().getExternalContext().redirect("page.jsf?id="+pat.getId());
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.