4

我有一个 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>

支持 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() 方法,实际上问题是他无法获得或理解该路径:

可配置的NavigationHandler.performNavigation("Page?faces-redirect=true");

因此他无法在此行之后打印任何日志。为什么会这样?是因为我在使用 Liferay 吗?

解放军指导我。

4

2 回答 2

11

好吧,我认为 onRowSelect 永远不会执行,因为您定义错误。

尝试这个:

public void onRowSelect(SelectEvent event)
{


  FacesContext.getCurrentInstance().getExternalContext().redirect("page.xhtml?id=" +pat.getId());


}
于 2012-05-29T07:38:04.387 回答
-3

如果您使用 FacesServlet,则使用 .jsf 而不是 .xhtml

public void onRowSelect(SelectEvent event)
{
  FacesContext.getCurrentInstance().getExternalContext().redirect("page.jsf?id="+pat.getId());
}
于 2012-06-08T07:24:31.450 回答