相忘于江湖

泉涸,鱼相与处于陆,相呴以湿,相濡以沫,不如相忘于江湖。《庄子.大宗师篇》

menuDataProvider.findFirst() failed

Tuesday Jul 10, 2007

When developing my small project based on JSF (Visual Web Pack) on NetBeans 5.5.1, I encountered a weird stuff -- the following codes don't work as expected, I always got 'Something wrong' warnings.

Integer dishID = new Integer(1);
RowKey rkMenu = menuDataProvider.findFirst("id", dishID);
if (rkMenu == null) {
info("Something wrong!!"):
return null;
}
info("You're lucky!!");

 

I found the cause when I tried to do manually searching:

menuDataProvider.refresh();
menuDataProvider.cursorFirst();
Integer curDishID = (Integer) menuDataProvider.getValue("id");

 

There is an Exception in the last line of above code snippet: java.lang.ClassCastException: java.lang.Long cannot be cast to java.lang.Integer.

This is pretty weird to me, since the property of menu.id is INTEGER in MySQL database. After double checking the design of menu database, I found that menu.id also has a UNSIGNED property. JSF (or Java) will map INTEGER column into Integer datatype, but will map INTEGER|UNSIGNED column into Long datatype. That may be the root cause.

Solution is pretty straightforward -- either remove the UNSIGNED property in database, or use Long datatype when accessing INTEGER|UNSIGNED column.


References:

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

Support Chinese in JSF, NetBeans

Tuesday Jul 03, 2007

I'm developing a small project based on the JSF (Visual Web Pack) on NetBeans 5.5.1. It works pretty well at the beginning. But when I tried to input some Chinese characters in the form, and save it into MySQL database through menuDataProvider.commitChanges(), it didn't work. The Chinese chars will become '?' next time it's retrieved and displayed.

Solution: JSF is based on UTF-8 already. But by default, the connection to mysql db is using ISO8859_1 encoding. Adding encoding info in the connecting url string in context.xml file should fix this issue.

url="jdbc:mysql://127.0.0.1:3306/lunch?useUnicode=true&characterEncoding=UTF-8"

 

[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg

NetBeans IDE 6.0

Thursday Jun 07, 2007

There are a couple of killing features in the coming NetBeans IDE version 6.0 (will be released in this November according to roadmap).
NetBeans IDE Roadmap

 

I especially like the JRuby on Rails Support, and the Swing GUI Builder. You can find the Flash demos from netbeans.org for them.



[0] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg