You're doing it the hard way. Also, don't code function calls on JSF EL expressions. They're supposed to be references, not logic.
First, change this:
As I said, this is supposed to be a reference. JSF knows how to do the method call. And it's what's supposed to be doing the calling, not you.
Now let's look at your table. You're trying to do brute-force operations on the rows.
Again, let's change the xhtml to the proper form:
And, incidentally, it's not a bad idea to use a styleClass instead of style so that your tables can be consistent without having to edit every page. If you're really ambitious, you can even "skin" Primefaces, but that's too complex to cover here.
Notice that I changed the property name to returnListModel. That's because instead of using a raw List as the table's data model, we're going to wrap it in a JSF DataModel. Here's one way to do that:
Incidentally, the bean containing this method and object must not be Request scoped. Request scope is almost useless in JSF.
The DataModel is a class that adds cursor capabilities to the return list. That makes life much easier for the action method:
Wasn't that easy? No need to muck around in the FacesContext or anything. It all gets practically handed to you. You don't even have to update the ListModel, since it's still the same returnList, just modified.
And the dataTable xhtml gets simpler, too, since the DataModel already knows which row is which and doesn't need any parameters:
One other thing. Your database code would be bad in any Java webapp, not just J2EE. Use a Connection Pool, don't use DriverManager. If you're going to use a system as powerful as JSF, you shouldn't use inefficient database connections.
And DEFINITELY learn to do PreparedStatements. You've set yourself up for a SQL injection attack.
When it comes to destroying a civilization, gas chambers cannot hold a candle to echo chambers.
posted 4 months ago
Thank you for your detailed reply, i am a junior developer started working for two months and we use jsf at work