Navigate to another page on rowselect of datatable in primefaces

Java picture Java · May 23, 2012 · Viewed 23.1k times · Source

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

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

I also got one article for the same 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>

And Backing bean is :

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

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

configurableNavigationHandler.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?

Pla guide me.

Answer

Tankhenk picture Tankhenk · May 29, 2012

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

Try this:

public void onRowSelect(SelectEvent event)
{


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


}