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
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
Related Q & A:
- Can I estimate the row count of a large mysql table using the disk space?Best solution by Database Administrators
- When i do a search and click on a result a get a page addressed rc10 overture what do i do?Best solution by Yahoo! Answers
- How do I delete my old Yahoo page after I made a new page?Best solution by answers.yahoo.com
- How do I change my page back to the new page after I changed it to the classic can?Best solution by Yahoo! Answers
- Where can I find a under table job in Plainfield New Jersey?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.