ajax 导航到primefaces中数据表的rowselect上的另一个页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10718192/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 10:45:51  来源:igfitidea点击:

Navigate to another page on rowselect of datatable in primefaces

ajaxjsf-2primefacesliferay-6

提问by Java

I have a primefaces datatable where number of records are displaying.

我有一个 primefaces 数据表,其中显示了记录数。

I want navigate to another page on the rowSelect event (to edit the selected entity for example).

I want navigate to another page on the rowSelect event (to edit the selected entity for example).

The closest sample/demo I could find was use the p:ajax tag to bind the rowSelect event to a listener method http://www.primefaces.org/showcase-labs/ui/datatableRowSelectionInstant.jsf

我能找到的最接近的示例/演示是使用 p:ajax 标记将 rowSelect 事件绑定到侦听器方法 http://www.primefaces.org/showcase-labs/ui/datatableRowSelectionInstant.jsf

I also got one article for the same http://forum.primefaces.org/viewtopic.php?f=3&t=14664

我也得到了一篇关于相同http://forum.primefaces.org/viewtopic.php?f=3&t=14664 的文章

, I tried to implement in same as they did.But it also didn't worked.

,我试着和他们一样实施。但它也没有奏效。

I am trying in this way and guide me If I missed anything.

我正在以这种方式尝试并指导我如果我错过了什么。

   <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>

   <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>

And Backing bean is :

支持 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");

    }

}

So how can I navigate to another page on rowselect event? and how can display its values after navigationg the form.

那么如何在 rowselect 事件上导航到另一个页面?以及如何在导航表单后显示其值。

I am able to go inside onRowSelect() method , actually problem is he is not able to get or understood that path :

我可以进入 onRowSelect() 方法,实际上问题是他无法获取或理解该路径:

configurableNavigationHandler.performNavigation("Page?faces-redirect=true");

configureNavigationHandler.performNavigation("Page?faces-redirect=true");

so he is not able to print any logs after this line. why is it so? is it because of I am using Liferay?

所以他不能在这行之后打印任何日志。为什么会这样?是因为我在使用 Liferay 吗?

Pla guide me.

解放军指导我。

回答by Tankhenk

Well i think the onRowSelect is never executed because you defined it wrong.

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

Try this:

尝试这个:

public void onRowSelect(SelectEvent event)
{


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


}

回答by Ashish

If u are using FacesServlet then use.jsf instead of .xhtml

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

public void onRowSelect(SelectEvent event)
{
  FacesContext.getCurrentInstance().getExternalContext().redirect("page.jsf?id="+pat.getId());
}