• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem Selecting DataTable Row

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, all
this is my first post on coderanch, or any java forum for that matter.
Ok, so im pretty new to the java scene. ive been working on some projects for personal practice, and im stuck on one
I have built an h:datatable that gets populated from an array in the backing beans
the table works alot like an inbox, it displays from, subject, date, etc

what i cant figure out how to do is have a row be selected on click, and then display the body of the message in a textarea.

like i said, i'm a super noob at coding, i have a couple of books that ive been using for help, but i cant seem to find this solution in them

can anyone help me out?

idk if this is important but im using jdeveloper
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately the basic reference implementation of JSF that you are probably using does not
easily support such a simple selection mechanism. There are ways of doing what you want, and
a good pointer is to search for BalusC. Although the advice from BalusC is pioneering and
always excellent in this case it is unlikely to easily help you.

What I would suggest is that, in addition to the basic JSF core functionality, you consider using
a component library. There are several options including ICEFaces, RichFaces and PrimeFaces.
I would recommend looking at PrimeFaces. Download the primefaces jar file and add it to your
classpath. Then add the "p:" namespace declaration to your .xhtml files as per the documentation.
Then go ahead an try the p:dataTable selectionMode="single" option.
 
john cartman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi brendan, thanks for the help, i literally spent an entire day googling this issue with no luck, all i kept finding was how to do it with those libraries you mentioned. however im not sure whether i can use those libraries, since idk if they will create any kind of compatibility issues with certain browsers and what not.

ill give it a shot and post back later letting you know how it went
 
Brendan Healey
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Primefaces runs on jQuery which is designed specifically to avoid browser compatibility issues.
In reality you won't get far without a component library unless you're prepared to do it all
yourself, which would be a massive case of re-inventing the wheel. JSF comes with only a very
basic set of components, the biggest and most obvious omission being the lack of ability to
select a row from a datatable. Well, I say that but BalusC solved this problem years ago:

http://balusc.blogspot.com/2006/06/using-datatables.html

Unless you've reached a fairly high level of competence in javascript and JSF internals I
wouldn't really recommend going the DIY route to be honest.

Primefaces 3 should be out within the next few months and I've high hopes that it will take the
high ground in the component lib space. In the meantime you can download v2.2.1 from here:

http://www.primefaces.org/downloads.html

You just need to install the one jar file in your classpath and you can be up and running in
minutes. I don't work for primefaces or anything but I went through an evaluation process
of the available frameworks and this was my choice.

Regards,
Brendan.
 
Bartender
Posts: 543
4
Netbeans IDE Redhat Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your requirement is simple, you can always just generate a commandlink in the table, use CSS to make the record feel like a button, and submit the record ID the backing bean, which then populates a bean with the message data. If that bean is available and not empty, you generate a textarea with the body in.

I do agree that it's much easier with a component library though. The greatest strength of JSF is that you basically let people do the pretty stuff for you - server and client side.
 
john cartman
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, so im using adf components now, and i can easily select the rows in the table, however now my js doesnt work since the attribute onclick, onchange, etc dont work anymore.

i need to be able to use the checkbox in the header to check/uncheck all the other checkboxes in that column
i need my delete button to only be activated if 1 or more checkboxes are checked, and deactivated if none are checked
and i need to make it so when i click on a row, the message body is displayed in some sort of text area below the table

all through beans if possible

should i post that in a different section?

here is the code for the button and table

 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, from the sound of it, all of what you're trying to do can be done with the basic core JSF without the actual need for PrimeFaces, ADF or any other extension tagset.

However, if you want to replace JUST the text in a textarea when you click on the row corresponding to that email, you need AJAX. Otherwise the whole page gets refreshed. For JSF 2, AJAX is part of the core. For JSF 1.x you would need an AJAX-aware extension tag library.

This sort of functionality is pretty simple. For example, if you make the email title into a commandLink object, the associated action processor can easily determine which row of the dataTable's underlying datamodel was selected. Then you use that information to retrieve the email body text and slap it into the property that supplies the value for the textArea control. When the page is refreshed (or the textarea is re-rendered by AJAX), the updated body text will magically be displayed.

OK it's not really magic, but it's pretty cool.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic