views:

244

answers:

2

Hi,

I have two facelet-pages: customers.xhtml (with a list of customers) and customer.xhtml for detail-view of just one customer. I use a h:dataTable component inside the customers.xhtml:

<h:dataTable var="customer" value="#{customerBackingBean.customers}">...</h:dataTable>

Now I want to create a hyperlink for each customer in the table. The hyperlink should navigate to the customer.xhtml . Each customer has a property primaryKey, which should tell the customer.xhtml whish customer should be displayed.

How do I do this? How does it work, if I use two different backing-beans for each facelet-page?

Thanks in advance.

+1  A: 
<h:commandLink action="customer.xhtml" ..>
    <f:setPropertyActionListener 
         target="#{customerBackingBean.currentCustomer}" 
         value="#{customer}" />
</h:commandLink>
  • then create a property currentCustomer in the bean (with getter and setter)
  • reference #{customerBackingBean.currentCustomer} in the customer.xhtml.

Just be careful with the scopes - you might have to use session scope if you use redirection.

Bozho
A: 

Or with a regular hyperlink which creates a GET request.

<h:outputLink value="customer.jsf">
    <f:param name="id" value="#{customer.id}" />
    <h:outputText value="#{customer.name}" />
</h:outputLink>

JSF favors POST requests, but you can still use GET if you want -- it depends on your need and if the page needs to be bookmarkable. Then you need to get the current customer id from the URL when the customer page is rendered.

See http://stackoverflow.com/questions/138617/how-to-create-a-get-request-with-parameters-using-jsf-and-navigation-rules

ewernli