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
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.
Joined: Jun 29, 2011
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
Joined: May 12, 2009
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:
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.
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.
Oracle Certified Professional: Java SE 6 Programmer
Oracle Certified Expert: Java EE 6 Web Component Developer
Oracle Certified Expert: Java EE 6 Enterprise JavaBeans Developer
Joined: Jun 29, 2011
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
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.
Customer surveys are for companies who didn't pay proper attention to begin with.