1

I have a table in my jsf application with some data from the database. I have made the id values a link, and my goal is to pass the data from the selected row to another facelet. How can I do this? The href I have is:

 <td><a href="editOrDeletePage.xhtml?productid=#{product.id}">#{product.id}</a></td>

So the goal is that when the user clicks the link, the editOrDeletePage is displayed, and I want the editOrDeletePage to "ingest" the product id, so that it knows what data to display? How can I do this?

user1154644
  • 4,491
  • 16
  • 59
  • 102
  • possible duplicate of [How do I process URL parameters on page load using Primefaces?](http://stackoverflow.com/questions/10724428/how-do-i-process-url-parameters-on-page-load-using-primefaces) – BalusC Dec 15 '12 at 20:45

1 Answers1

2

If you definetely want to use static links, you may, of course, just read a request parameter from a target page using some kind of event listener

<f:event listener="#{bean.preRender}" type="preRenderView" />

And read the parameter from request:

FacesContext facesContext = FacesContext.getCurrentInstance();
String productId = (String) facesContext.getExternalContext().
                              getRequestParameterMap().get("productid");

But it's not really a JSF way to handle navigation, I belive. You may want to use commandLink or some other way of handling user actions. Or maybe, even better, think of using data table, where a user can choose a row, and you can process selection.

skegg99
  • 415
  • 2
  • 8
  • So the code that you posted in the 2nd block is the body of the preRender() method? – user1154644 Dec 15 '12 at 21:07
  • Yes, that's what I mean. You can set the productId to a variable and later use it while rendering a page. The acticle linked in BalusC answer has a more complete example – skegg99 Dec 15 '12 at 21:11