Jul/110
Updating A Spring Tutorial
Open Netbeans.
New Web Application, Spring v2.5, changed default dispatcher to ‘springapp’
created a custom landing page – edit web.xml welcome page to make it the default.
Look at the springapp-servlet.xml and the indexController.
p:viewName="index" />
Apr/110
Spring / Netbeans – a missing context.xml file
So I’ve upgraded to Netbeans 7 recently, and had an issue that comes up when creating a new Spring MVC Web Application. That is, when I run the Tomcat application an error message appears – context.xml (The system cannot find the file specified).
Looking around on the internet it seems this may have been around for a while, so I was mystified as to why I hadn’t come across it before. However it seems like the kind of bug which stops occuring when I create my new Spring Web Application with another project already open in the Project Group. Don’t ask me why, and this may change in the future – but if you’re stuck on this it may be worth a try.
May/100
Selecting MySQL rows within a Time Range for a Java Program
Earlier I discussed selecting rows from a table within a specified date range. What if you need to select rows from within a time range?
Again a SELECT statement with a WHERE clause is needed. The method below will give the statement for the start and end times of the statement. Unlike the earlier example this has a DateFormat to supply the String required to generate the SQL statement.
GregorianCalendar calStart = new GregorianCalendar() ;
calStart.set( Calendar.HOUR_OF_DAY, 18 ) ;
calStart.set( Calendar.MINUTE, 1 ) ;
String sql = "SELECT * FROM " + dbh.userTable.tableName +
" WHERE status=1 AND "
+ SQLStrings.getWhereBetweenDates( "signup_time", calStart ) ;
.....
public static String getWhereBetweenDates( String columnName, GregorianCalendar calStart)
{
GregorianCalendar now = new GregorianCalendar() ;
StringBuffer sb = new StringBuffer( columnName + " BETWEEN " ) ;
SimpleDateFormat df = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ) ;
String beforeDateString = df.format( calStart.getTime() ) ;
String afterDateString = df.format( now.getTime() ) ;
sb.append( beforeDateString + " AND " + afterDateString ) ;
return sb.toString() ;
}
Note that the DateFormat String here was determined by what was present in the MySQL database for that particular column. YMMV – so if there are problems maybe check your database table to see what particular format that column takes.
Apr/101
Netbeans Editor Code Folds
Some times its handy to be able to hide sections of code in the Netbeans editor window.
// <editor-fold desc="This section of the code deals with the item."> Your code goes here... // </editor-fold>
These are just the basics. More information is available from the Netbeans page.
Mar/102
jQuery / Java / Autocomplete
If you haven’t heard of jQuery, its a Javascript library that allows you to implement AJAX functionality in your web pages. You can find out more about it from the jQuery website.
My first attempt with jQuery involved using an autocomplete plugin provided by Pengoworks. Autocomplete is where you start typing in a few letters and the text box will come up with some suggestions. There was a tutorial for this present on the jquery autocomplete page, but it didn’t quite meet my needs, and maybe it doesn’t meet yours.
There are two ways in which to use the auto complete functionality. If there are a few options (ie upto 50) the list of suggestions can be embedded in the web page itself, but if there are many options (1000s) the suggestions need to come back from a server. It was this second process that the tutorial did not cover, and hence the reason for providing a step by step guide to doing it here.
In partcular, I’m working from Java in Netbeans 6.8.
Aug/090
VisualWeb JSF being discontinued
One of the primary reasons for starting this blog was to log any nifty tricks I learnt whilst using Netbeans and VisualWeb JSF. However this has now been converted to a non-essential Sun item. I was also planning to document IceFACES, an AJAX support framework, which no longer supports a Visual developer setup with Netbeans 6.7 due to the removal of the ‘Woodstock’ components for the core IDE. Being new with IceFACES from within a text editor looses the productivity gains it should provide.
As I have some projects looming up and have to think about maintenance down the line, I have decided to make the switch to Eclipse – specifically I am using the MyEclipse platform. Its not free as in beer, but comes with lots of neat addons tied in with it, so I am putting this through its paces.
Jul/091
sun.misc.BASE64Encoder replacement required
The package sun.misc.BASE64Encoder that was used in some code I was referencing came up with a warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
Not good for futureproofing!
Its replacement can be found using the relevant class from Apache Commons library. This is in the Codec suite of the Apache Commons library.