This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 132885

Summary: Checkboxes do not reflect underlying data
Product: obsolete Reporter: pncblessed <pncblessed>
Component: visualwebAssignee: Winston Prakash <wjprakash>
Status: RESOLVED FIXED    
Severity: blocker    
Priority: P2    
Version: 6.x   
Hardware: Sun   
OS: All   
Issue Type: DEFECT Exception Reporter:

Description pncblessed 2008-04-15 14:16:49 UTC
Checkboxes do not reflect underlying data - saving or loading

1. Create a MYSQL database
2. Create a table with a BIT field in it
3. Create a checkbox on a web faces page and bind it to the table's bit field
4. Add button with commitchanges

You'll see that the checkbox fails to read the binary field and also fails to save it/
Comment 1 _ krystyna 2008-04-15 21:48:35 UTC
Roman's findings:

I tried and was able to reproduce. I just created table with one row, add checkbox to the page, DnD table onto checkbox 
and then choose BIT field in "Bind to Data" dialog. I has value '1' for this field, but checkbox wasn't checked. But 
I'm not sure that checkbox component should treat BIT values as correct values. Probably this component just treat BIT 
values as 'false' and that's all. We need to ask developer of this component.
Comment 2 Winston Prakash 2008-04-15 22:04:40 UTC
It all depends on how the BIT is mapped to a Java type by the JDBC provider.
The recommended way is to map to boolean.

http://java.sun.com/j2se/1.3/docs/guide/jdbc/getstart/mapping.html

If the type returned by MySQL JDBC is not of type boolean then binding to that column will not help.

User need to create a getter/setter and manually. See my blog on this.

http://blogs.sun.com/winston/entry/non_boolean_checkbox
Comment 3 Jayashri Visvanathan 2008-04-16 05:28:02 UTC
This does not qualify for a P1 per the bug priority guidelines. There is work around as documented in Winston's blog, so
I am down grading this to P2.
It doesn't seem like a component issue after all. If so, Winston, can you close this ? Do we need to get feedback from
woodstock folks ?
thanks
Comment 4 pncblessed 2008-04-16 07:00:06 UTC
Thank you all thats great.
Comment 5 Winston Prakash 2008-04-16 14:59:49 UTC
Jayashri, as I mentioned, if the JDBC driver does not return a particular column as boolean, then binding it directly to
checkbox will not work. Checkbox as such is working correctly. 

In that case one should use an intermediate property in the Page bean (getter/setter) that would correctly convert the
bit value as booelan and set back the boolean as bit value (to persist back in the database) as I mentioned in my blog.

I'll close the bug, if I get confirmation from pncblessed that it is working.
Comment 6 pncblessed 2008-04-16 15:11:57 UTC
Okay

I did try changing the Data type in the database to BOOLEAN and it still doesn't map. The problem is I have one table
(USERS) with loads of boolean fields in them. Also it appears the PASSWORD componant fails to bind properly to a VARCHAR
field or anything else.

Incidentally if the check box is in a grid it binds without a problem.

I think its a bug still not a feature. 

By the way thank you so much for all you are doing for us Netbeans users it is really really appreciated, I do love
Netbeans and what I'm able to build with it and so does my firm! :-)
Comment 7 pncblessed 2008-04-22 09:31:18 UTC
Ok

Another update - I also tried using the "Converter" field in properties to specify the database field as being a boolean
but still to no avail. 
Comment 8 pncblessed 2008-04-30 12:24:31 UTC
Ok here's how to make it work.

1. DO NOT use bind to data  from the right click menu, it binds "SelectedValue" to the field which is not used.
2. Instead bind the property "Selected" for the checkbox to the database field.
3. In the Save code insert the following:-

cachedRowSetDataProvider1.setValue("locations",
                new Boolean(
                checkbox5.getSelected().toString()));

Checkbox5 is the checkbox
locations is the field in the database

I'm not setting it to fixed because really it still is a bug as the checkbox SHOULD bind to the underlying boolean field.
Comment 9 pncblessed 2008-06-04 10:59:35 UTC
Now fixed in the latest release of 6.1 patch upgrades.

Set the SELECTED property to the database field
Set the SELECTEDVALUE property to true

Thanks everyone!