4
votes

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.

2
what happens with your code? is onRowSelect() method executed? is the selected Patient set in the bean?damian
no, not even patient selected in the bean, nor onrowselect method is executedJava
is the dataTable surronded by h:form?damian
yes, it is surrounded by h:form, i tried by removing it also, but still not getting any logs, why?Java
it has to be surrounded by h:form, so don't remove them. try adding the rowKey attribute to the datable: rowKey="{product.id}" (replace id for the actual id attribute of the class).damian

2 Answers

11
votes

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());


}
-3
votes

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

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