Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

onclick row action in dataTable

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I'd like to know if there are any known solutions/patterns to enable "onclick" actions in the dataTable. My application has a list-like display for a selection of entities and a details page. Previously, before migration to JSF, I had an "onclik" action on each row in a table, like this:

<tr onclick="window.location='details.jsp?entity_id=${entity.entity_id}';"> ... </tr>

But with JSF I didn't yet find an ability to specify a JSF action for an "onclick" action in the dataTable. The only solution I've found so far is using a commandLink like this:

<h:commandLink value="View details..." actionListener="#{listController.selectEntity}"/>

It is a regression from user standpoint, because previously user could click anywhere within a row, but now he/she may click only this link which is not really convenient.

Currently I consider implementing my own "clickableDataTable" component, but I wonder if there are simpler solutions?

Thanks,
Tim
 
Saloon Keeper
Posts: 23002
156
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm no expert on this, but I suspect that you can do it using CSS, since there are some popular "JavaScript-free" menu systems that do so.
 
Tim Wise
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm, unfortunately I'm not an expert on CSS either. Not sure if CSS can solve this, as since what I'd like (in the ideal solution) is that an action method of a managed-bean is executed when user clicks somewhere within a table row

BTW, as of JavaScript - I'm OK with using it on a list page - is there any way to call some action method from JavaScript? Maybe it is possible to "click" on a commandButton or a commandLink from JavaScript code? Although there are questions here too:
- how to inject a JavaScript code to dataTable's rows?
- and how to find an exact button or a link?, as since there are many of them - one per row
 
Tim Holloway
Saloon Keeper
Posts: 23002
156
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's nothing to support (or hinder) JavaScript in the base JSF standard. However RichFaces provides extensive JavaScript support, including the ability for JavaScript to fire off AJAX operations. You might also check their dataTable extensions - one of them might even have an "onRowClick" type of attribute you can exploit.

RichFaces isn't the only JavaScript-supportive JSF tag library, BTW. Just the one I've got the most practice with.
 
Tim Wise
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting... The thing I think of, is that as since JSF 2.0b supports AJAX - is there "onclick" action available in it's dataTables?
 
Doody calls. I would really rather that it didn't. Comfort me wise and sterile tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic