formerly known as Dashboy John W Baker's Weblog

Tuesday Nov 13, 2007

 
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:xsi="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.
 

 


Comments:

Thanks.
but where is the converter source
and sample project?
(not very familiar with NetBeans)
usually CLOBs are used to store
images. probably a table column is
needed to store mime types
and converter needs to display
that.

Posted by 128.249.96.252 on November 14, 2007 at 02:46 AM PST #

Sorry I forgot to upload the project. It's available now. See the link at the bottom of this entry. Hmm... I usually use blobs to store images and clobs to store character data, such as files..

Next time, I'll post an example using blobs.

Posted by 192.18.43.225 on November 15, 2007 at 06:40 PM PST #

Hi,

I've got a problem with NB5.5.1 + Visual Web Pack and Oracle NCLOB data type.

When I try to insert data that's ok, no problem, but when I try to update rows then I receive an error

Number of conflicts while synchronizing: 1 SyncResolver.UPDATE_ROW_CONFLICT row 0 Niepoprawny typ kolumny (wrong column type) - I have tried to use String class, SerialClob class etc. Sometimes I do not receive any error, but data is not saved into database.

Second thing I would like you to ask is: can (and how) we may use database transactions with DataProviders ?

Best regards,

Posted by Matthew on January 22, 2008 at 07:47 AM PST #

Hmm… I don’t really know if the previous problem is so complicated or simply that library is worthless or there is no one interested in explaining how to avoid common pitfalls.
Frankly I am unable to find any interesting materials about it and solutions to common problems. I do believe it suffers from serious limitations and number of bugs.
If you consider using it, I would recommend rethinking that idea. Frankly, if I were to choose framework again, I would not choose that Visual Web Pack (which now is known as framework in NB6) and merely mimics Ms VS .NET. Idea is good, but the rest is far beyond counterpart from Ms (and to support my point of view I have 18 months of working experience with VS2k3 / VS2k5 and 6 months of trying to do the same in VWP).
Thanks for reading, have a good time…

Posted by Matthew on February 05, 2008 at 02:24 AM PST #

Post a Comment:
  • HTML Syntax: NOT allowed