In this entry, I'll explain how to create a simple Visual Web Java EE 5 application that displays CLOB values from an Oracle database in a Table component. Here is the supported Oracle driver information for Visual Web
NetBeans Visual Web components support many types of converters to convert data types to String for displaying values in components (Table, StaticText, Dropdown List, ..).
There are however, these in-the-box converters do not support all types, such as database LOB fields (CLOB, BLOB (not blog), BFILE) . For these, a custom converter is required.
Here is a sample converter that converts a CLOB to a String. Thanks to Sun Java Studio Creator users OranP and japebo0
for providing this converter. To use this converter with a JSF component, a bean property along with an accessor method must be created to instantiate the converter class*.
private Converter myClob = new ClobConverter();
public Converter getMyClob() {
return myClob;
}
Next, in the JSP source where the component is defined, the converter is set using JSF Expression Language statement to retrieve the value from the property of the bean class, myClob.
<webuijsf:staticText binding="#{Page1.staticText7}" converter="#{Page1.myClob}" id="staticText7" text="#{currentRow.value['CLOB_COL']}"/>
Next, converter must be registered in the faces-config.xml file:
<faces-config version="1.2"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns
si="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
<converter>
<converter-id>ClobConverter</converter-id>
<converter-class>
webapplication8.ClobConverter
</converter-class>
</converter>
<managed-bean>
<managed-bean-name>SessionBean1</managed-bean-name>
<managed-bean-class>webapplication8.SessionBean1</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>Page1</managed-bean-name>
<managed-bean-class>webapplication8.Page1</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
...
</faces-config>
Next setup the database. You can use the pre-registered Derby connection, travel on TRAVEL.
Select this connection, right-click and choose Connect... then again, right-click then choose Execute Command... and paste the following SQL into the SQL Editor, then click the smaller Green arrow in the toolbar of the SQL Editor. Note the SQL below is for Oracle. I can provide the SQL for other databases at the end of this blog entry.
CREATE TABLE clob_table (
id NUMBER PRIMARY KEY,
text VARCHAR(30),
clob_col CLOB
);
INSERT INTO clob_Table VALUES (0, 'RECORD 0', 'COMMENT FOR RECORD 0');
INSERT INTO clob_Table VALUES (1, 'RECORD 1', 'COMMENT FOR RECORD 1');
INSERT INTO clob_Table VALUES (2, 'RECORD 2', 'COMMENT FOR RECORD 2');
INSERT INTO clob_Table VALUES (3, 'RECORD 3', 'COMMENT FOR RECORD 3');
Create a new Web Application using the Visual JSF Framework. Then, from the Palette, drag and drop a Table component onto the Designer surface. Next, from the Services tab, expand the travel on TRAVEL connection and drag and drop a CLOB_TABLE onto the Table component (the outline of the component will turn blue)
Next, change from the Design view to the JSP source view and if you haven't already, add the converter option to the StaticText component that is bound to CLOB_COL
<webuijsf:tableColumn binding="#{Page1.tableColumn6}" headerText="CLOB_COL" id="tableColumn6" sort="CLOB_COL"> <webuijsf:staticText binding="#{Page1.staticText7}" converter="#{Page1.myClob}" id="staticText7" text="#{currentRow.value['CLOB_COL']}"/> </webuijsf:tableColumn>
And make sure the converter is registered in the faces-config as above.
Finally, you can execute the application. Your browser should render the Table component as shown in the screenshot. If the page is blank then in NetBeans, click on the the Output tab at the bottom and then the Glassfish tab. Scroll to the bottom to check the error.
I'll attach a sample project for reference.
Sample project that connects to Oracle.
To resolve project errors, edit the sun-resources.xml and replace the database settings with your Oracle settings.