Open a new page (go to a new site) when selecting the dataTable line

There are several related questions on this topic about SO and elsewhere , but I could not find a definitive answer to this specific question.

I have p:dataTable, and I want to click on the line and open the details page (a new page, not a dialog or window).

I solved it this way (that I have from the perffaces website, for some reason it no longer exists: http://web.archive.org/web/20101001223235/http://www.primefaces.org/showcase/ui /datatableRowSelectionInstant.jsf ):

<p:dataTable var="order" value="#{orderBean.orders}" selection="#{orderBean.selectedOrder}" selectionMode="single" rowKey="#{order.number}">
  <p:ajax event="rowSelect" listener="#{orderBean.orderSelect}"/>
  <p:column ... />
</p:dataTable>

Navigation is then done in a bean:

public void orderSelect(SelectEvent event) {  
  ConfigurableNavigationHandler nh = (ConfigurableNavigationHandler)FacesContext.getCurrentInstance().getApplication().getNavigationHandler();
  nh.performNavigation("orderDetail?faces-redirect=true");
}

My question is: is there a way to do this only inside JSF without bean support?

, exmaple perffaces, , - .

+5
3

, .

"",

@Component
public class Navigator {
  public void nav(String page) {
    UIHelper.navigateTo(page);
  }
}

ajax:

<p:ajax event="rowSelect" listener="#{navigator.nav('orderDetail')}"/>

, , , bean. (, Navigator, .)

+1

<h:link>.

<p:column>
    <h:link outcome="orderDetail">
        ...
    </h:link>
</p:column>

, , CSS display:block , . <f:param>.

+8

since this is an ajax request, usually a request / response is used to reprocess some components on a web page. What you can do is

<p:ajax event="someventofintrest" onsuccess="javascript:myjsmethod();"></p:ajax>

and

<p:remotecommand name="myjsmethod" action="#{mybean.mybeanmethod}" />

and in the backing bean

public String mybeanmethod(){
  return "mynewpage";  // Navigate away to mynewpage.xhtml
}

NTN.

+1
source

All Articles