How to show a table on another page?

JSF2 Click on table row -> show new page

  • I'm using JSF2 and I have a table which contains one row per item in a list. The details of the item are quite complex and are displayed within an inner table on each row. I want the user to be able to click anywhere within the inner table and for the browser to then display the new page, eg. details.jsf?id=123 I have created a form for each item in the list at the bottom of the page, which is not visible, and I use JQuery to add a click listener to all table rows. The handler recurses up the DOM tree until it finds the table row in the outer table, which contains an id which is the unique name of item in that row. I then call a function which uses JQuery to locate the relevant form, and submit it. Eg: table tr id='1' first inner table... /tr tr id='2' second inner table... /tr /table form id='item1' action='details.jsf?id=1' form id='item2' action='details.jsf?id=2' So, clicking on the second inner table causes a handler to be called which recurses up the DOM until it finds id 2, and then it looks up the form with id "item2", and submits it. It's all rather complicated. Is there an easier way?

  • Answer:

    Your solution in quite complicated. First of all You should get rid of all this forms in my opinion. According to Your explanation You do not have to send POST request (forms send POST requests). GET request is sufficient in this situation. The last thing to do now is some kind of link to the item details in every table row. I suggest You to do it in standard way so add somewhere inside table row something like this: <a href='details.jsf?id=#{item.id}'>#{item.id}</a> You can always replace text with some cool icon. It is quite readable. User will see that there is something to click (or to do) with this icon. If You really want to be able to click anywhere inside the table row, You can insert appropriate div's in every table data: <div onclick='window.location=details.jsf?id=#{item.id}'>//content//</div>

John Smith at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

As you are using Jsf2, I believe there are easier ways to do this. For example, you can use one of the component libraries like primefaces Check this out. http://www.primefaces.org/showcase/ui/datatableHome.jsf Similar datatable component is available in Richfaces,Icefaces etc. Makes job little easier. Primefaces also basically uses the JQuery themeroller in background.

Hirak

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.