aspose file tools*
The moose likes JSF and the fly likes Confused. How do I add links to each item in a list, how to get JSF to know which link was clicked? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Confused. How do I add links to each item in a list, how to get JSF to know which link was clicked?" Watch "Confused. How do I add links to each item in a list, how to get JSF to know which link was clicked?" New topic
Author

Confused. How do I add links to each item in a list, how to get JSF to know which link was clicked?

Jonny Devine
Greenhorn

Joined: Feb 08, 2012
Posts: 6
I have a page listing books. How do I go about adding a link to each one? When one of them is clicked how do I get it to go to a separate page "book.xhtml" showing details of that specific book clicked?

Here is my code so far:

Book.java


BookCatalogBean.java



index.xhtml
Abhinav Taduka
Greenhorn

Joined: Feb 02, 2012
Posts: 6

You can either do it in multiple approaches using h:commandLink or h:outputLink

Approach1:



implement navigation rule to handle bookDetails.

Approach2:



implement navigation rule to handle someAction

Approach3:





Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Or better yet, you can use a JSF dataTable instead of violating the MVC paradigm by putting what amounts to executable code on the View template.

By proper use of CSS, a dataTable can be made to visually appear just like an ordered (or unordered) list. In fact, the h:messages tag does exactly that, if the message display options are set for it.

Customer surveys are for companies who didn't pay proper attention to begin with.
Jonny Devine
Greenhorn

Joined: Feb 08, 2012
Posts: 6
Abhinav Taduka wrote:You can either do it in multiple approaches using h:commandLink or hutputLink


Thanks very much! I shall try these out now.

Tim Holloway wrote:Or better yet, you can use a JSF dataTable instead of violating the MVC paradigm by putting what amounts to executable code on the View template.

By proper use of CSS, a dataTable can be made to visually appear just like an ordered (or unordered) list. In fact, the h:messages tag does exactly that, if the message display options are set for it.


But aren't tables becoming obsolete? When I program in OO PHP I like looping through arrays and designing the layout with div's. Seems so much easier. Perphaps im looking at this the wrong way.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

Yes, you are looking at it the wrong way. You're also buying into an outmoded bit of folk wisdom.

When CSS rose to ascendency, some dogmatists began insisting that HTML tables should be verboten and everything should be done with div elements, instead. The div has its place, but the HTML table tag is still cleaner and simpler when you want to lay out a general grid.

In any event, we're talking JSF here, not raw HTML, and in JSF, the dataTable is the premier way to present grid-structured data (including cases where the "grid" is only 1 column wide, such as an ordered list). In addition to the layout, it also provides the datamodel and code infrastructure to make it easier.

Furthermore, we're talking Model/View/Controller. In MVC, each of the 3 components has a definite role. In JSF, most of the Controllers are pre-supplied for you, the backing bean is the Model, and the JSF page definition is the View template. The View template should be exactly that - a template, not a code module. Code goes in the Model (and in the Controllers, but like I said, JSF's Controllers are mostly pre-supplied).

I'm very fond of PHP as a quick-and-dirty way of getting webapps, out, but the key word here is dirty. It is, in fact, precisely the case that PHP embeds the code onto the View that make PHP difficult to work with on large complex projects. JSF, on the other hand, is horribly expensive as a platform for developing simple webapps, precisely because of all the extra files you have to set up and include. As you scale up, PHP becomes less beautiful and J2EE (and JSF) become more beautiful. They each have their places.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Confused. How do I add links to each item in a list, how to get JSF to know which link was clicked?