This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes JSF and the fly likes Data Table: Can't update ResultSet from JSP page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Data Table: Can Watch "Data Table: Can New topic

Data Table: Can't update ResultSet from JSP page

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1121

I'm trying to update a resultSet when the user interacts with a selectBooleanCheckbox on the JSP page, but it's not working.

My Managed Bean & database query creates an updatedable PreparedStatement and I see the Data Table with the selectBooleanCheckbox column I added to the Data Table on the JSP page.

So far so good. I can click "Submit" on the JSP page and see the values of the ResultSet.

So far so good...

But, when I try to click the checkbox on the JSP page (a column in the Data Table), I get a serious (Tomcat???) 5.0.28 error:

"Attribute o-n-C-l-i-c-k invalid for tag selectBooleanCheckbox according to TLD"

Does this version of Tomcat support the o-n-c-l-i-c-k=s-u-b-m-i-t() logic?

The o-n-C-l-i-c-k() code comes right out of an example in Core JSF.

I tried to include the logic for the tag, but couldn't get past the JavaRanch illegal character screener. Oh well, it's just the standard on click equals submit ( ) logic.

My Managed Bean (backing bean) has the bean methods to handle the boolean property isSelected (that is, a getter and a setter).


Without the o-n-C-l-i-c-k=s-u-m-b-i-t() in the selectBooleanCheckbox above, the code runs fine and displays results, ***UNLESS*** I check a checkbox in the data table.

If I check a check box in the data table and then click Submit (on the JSP page), I get no output at all. If I un-check that checkbox in the Data table and click Submit again, I again see data output. Strange.

I'm sure I'm "close"....

Please help!!!

Thanks in advance.

-- Mike
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1121
To add a little more info to my posting above....

The basic problem is that I'm going a query and get a populated Data Table. The submit button's action goes to an update method on the bean which works as long as I don't click any of the selectBooleancheckboxes on the Data Table.

The selectBooleancheckboxes correctly get checked on the initial loading of the Data Table depending on whether the database column has a 1 or 0.

*** BUT*** If I click one of the selectBooleancheckboxes that were populated by the database query, and click submit on the form, then ***NOTHING*** happens. I get no output. The update method does not fire. If I un-check them and submit again, all is fine -- the update method works.

What I'm trying to do is save back to the database the items the user has checked so I'm just trying to get a handle, so to speak, on the changes made to the Data Table.

I added the read/write properties to the backing bean, but they don't fire either.

The data table populates (the parent tag) initially with a getAll method.

This is incredibly confusing.

Any and all ideas would be appreciated.


-- M
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17151

"onclick" isn't Java, it's JavaScript, and on top of that, it's case-sensitive, so "onClick()" and "onclick()" aren't the same when you're talking TLDs.

Since onClick() is JavaScript (client-side code), it's probably not really what you wanted here unless you're trying to do AJAX-style coding. More likely what you really wanted was to handle rows that you tagged via checkboxes as a unit event.

If you've set up a JSF table and mapped it against an array or collection of rows, each of which has a boolean column mapped to a checkbox, it's as simple as polling the updated checkbox values when you handle the Submit button. That is,

Your exact code may vary, especially if you use the Java 5 iterator or have to do a Java 4 cast of the "get()" operation results.

An IDE is no substitute for an Intelligent Developer.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1121
Hey Tim!

Thanks for writing back...Here's a little more detail...

I've actually set up a Data Table and mapped it to an updatedable ResultSet & a prepared statment. The checkbox column is part of that ResultSet (mapped to an integer MySQL field).

The Data Table comes up, initially, fine, with checks (from the database) in the right rows for the Data Table with the checkbox so there doesn't seem to be a DB/JDBC problem.

The problem is that, after the Data Table appears populated, and then if I _check_ one of the checkboxes and click Submit, **NOTHING** happens. The method that normally fires when I click submit doesn't do anything. I stuck a breakpoint there, but nada.

But get this.... if I then remove the check I just checked and click Submit again, it works again.


Here's what the checkbox column definition looks like within the Data Table definition:

<f:facet name="header">
<h utputText value="#{msgs.selected}" />
<h:selectBooleanCheckbox value="#{form.selected}" />

Then I have a method in the bean that has a getter/setter method. That method never fires either when I click the check box.


Could the problem be that this checkbox is part of an (updateable) ResultSet and just doesn't take well to manual changes? This doesn't sound like it would be possible, but I'm not sure why the GUI stops working after I click a check box.

Maybe I need to do more to "wire up" the connection to the Managed Bean -- though it seems to be working unless I click the check box.

I hope to hear back from you again with ideas.


-- M
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I don't see anything in this code that would suggest any method would be called when you check/uncheck this checkbox.

What kind of updatable ResultSet are you wiring too? Not sure that this is the cause of your immediate problems, but unless the ResultSet object works offline, I would recommend moving to an object that contains your data but is not connected at all to the database. A Collection of some sort.

Also, what JSF implementation are you using?

GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

I tried to include the logic for the tag, but couldn't get past the JavaRanch illegal character screener. Oh well, it's just the standard on click equals submit ( ) logic.

Sorry, I didn't see that the first run through. That is probably why you didn't inlude the on click information...Still looking into this problem for you. I have setup a small test environment so I am running through some code.
Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1121
Hi Gregg,

Thanks a lot for your reply. Here's some more detail. I'll get you as much detail as you need and work with you on this issue! <s>

I'm using MyEclipse 4.0.3 and added the JSF libraries from there.

The crucial issue is I don't know how to bind a column to an updateable resultSet. If I can't, what good is a resultSet to bind to a Data Table in the first place?

My Data Table comes up populated with the updateable ResultSet so I'm not sure how I could use a collection instead.

I checked the metadata and, sure enough the connection reports that its an updateable ResultSet with a data type of TINYINT(1) for the checkbox field.

I also tried to edit another column in the Data Table bound to the resultSet but also got conversion errors.

The checkboxes come up, initially, correctly checked or unchecked from the query, so I'm part way there (but still "no where" <g> .

I think my using the value ="#{tx.updated}" implies a read/only attribute, but using the binding tag didn't work either though using "binding=" did hit the Managed Bean's methods I set up. However, when you're bound to a resultSet, I don't think you'd want to have bean properties with getters/setters, right? That's what being bound to the updateable ResultSet is for (I think, anyway...).

The bottom line: I don't seem to know how to bind a control to an updateable ResultSet (or for that matter a JSTL Result). I haven't found a single example on it.

I'm probably missing something SO basic, but I've been trying to figure this out for over a week and gotten nowhere.

Regarding your other question, clicking Submit button is when I see the "conversion errors".


<h:commandButton value="#{msgs.saveText}" action="#{TableData.update}" />

It's interesting to note that cliking the Submit button also re-runs the method that populates the Data Table first. I never get to the 'update' method called for in the commandButton above.

--- Here's the column with the checkbox.

<%-- checkbox column --%>
<f:facet name="header">
<h utputText value="#{msgs.updated}" />
<h:selectBooleanCheckbox value ="#{tx.updated}" />
<h:messages layout="table" />


The method that populates the Data Table is this:
(Pseudo-code shown below)

String sql = "select ....?";
PreparedStatement stmt = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE );

// set the prepared Statement Parameter
stmt.setLong(1, variableGottenFromEnvironment);
resultSet = stmt.executeQuery();
model = new ResultSetDataModel(resultSet);
return model;


Hope you can help me figure this out.

Please let me know if you need any additional information, OK?

Thanks very much in advance.

-- Mike
I agree. Here's the link:
subject: Data Table: Can't update ResultSet from JSP page
It's not a secret anymore!