I’m writing an app for my wife. A time-tracker. It’s a whole load of experiments in one. It’s view-driven in that she makes a html-mockup, then we discuss it, plan a data-model if need be, and I implement the logic. I’m trying to do it using the highest tier technologies I can, so all in JSP is the dream. And I’m aiming to migrate it from mysql to postgres for production.
I’ve chosen to use the JSTL, and more surprisingly for someone who spends all his time using Java to load from databases, I’m going to attempt to rely on the JSTL sql taglib, that is, SQL in JSP! [Shocks, cries, people faint at their browsers]. The crux of the idea being, can a technology be BAD, or is it merely the inexperienced uses people put it to. Can I happily setup an MVC structure [and with it a pattern-framework that my wife can follow in later projects] without having to launch into the depths of JDBC?
I think I can. Part of this is due to the fact that I think that SQL is a part of the Controller and not a part of the Model. Admittedly it’s a part that should probably be abstracted below the Controller, but there’s no great need. It’s the Controller’s job to decide when and where to load new model’s etc, and that’s what the SQL is primarily for. Indeed, the only Java will be the Model, aka a set of JavaBeans.
This is where i hit my first real grumble. I’m being simple and lazy. Why oh why is the classic bad Java struct not recognised as a Bean
public class Person {
public String name;
}
I know, I know. But it’s an irritating limitation as I so very very rarely find a need to put anything in the encapsulation. Part of this is to try bad ideas and see if they really are that bad, so a shame I can’t try that one. The world is saved.
I’ve hit some oddities in JSTL, but all in all it seems to be working okay. Once JSP 2.0 is available I can see that a fair chunk of the oddities will work or be simplified. Indeed, it’s hard to remember that when the JSTL isn’t working I can just rely on the good old basic JSP bits.
My first real crash is in everyone’s favourite: Sequenced numbers for object IDs.
In PHP, which is where I’ve often done little hacky apps for my wife, the mysql-drivers have a nice bit in which the auto-increment field of the table is returned from the insert-method. I’ve hidden this all behind a PHP-OO API, but it is still very nice. In JSTL, I can’t even use such nasty hacks as SELECT LAST_INSERT_ID(). I suspect because of a commit or some such, it always returns 0. I’d only have to port to postgres anyway, so I need a better solution.
Brett McLaughlin discusses it in his Enterprise Applications book, so I may take a brief sidestep to research a good sequence-number API or make my own. [At work we use Oracle Sequence numbers explicitly, so it’s been a while since I’ve had to think about this issue. Back in the UK we just used a unique number [time and memory]].
So after the first night or so of hacking, I’m still quite enthused that a good JSP architecture can be created without resorting to much Java [and the little Java needed could easily be generated from a command-line wizard, in fact, I should do that]. Although it’s easy to slip into a mess of jsp files, and I’ll have to keep refactoring the framework until it’s ready to be declared ‘The Way We Do It’, I think it looks good.