Originally posted by Alec Lee:
But why in JSP we don't have similar facilities?
It doesn't. The scoped variables that a page requires to operate correctly are part of an unwritten contract that any controller that forwards to that page must satisfy.
All too often this contract is left for those writing controllers, if different from those writing the JSP, to figure out for themselves.
A good JSP developer will document the page contract.
For myself, I prefer the page to blow up spectacularly rather than exhibit subtle and incorrect behaviors when the contract is broken, so my pages explicitly
test that the contract is met and throw an exception if not.
To make this as painless as possible, I created a "contract tag" that declares the expectations of the page and also serves as the documentation for the page contract.
Some typical usages might be:
and so on.
Any contract that is not met results in an exception that makes it clear that the controller has not met its obligations, thus preventing long debug session trying to figure out what's missing.
[ October 05, 2006: Message edited by: Bear Bibeault ]