
Originally Posted by
McGruff
is the ApplicationController pattern "a centralised point for handling screen navigation and the flow of an application" ((Fowler)). If you have a wizard style interface where a series of pages are shown in a particular order, or choice of page depends on the state of something or other (eg an authentication check leading either to a login page or to the page requested) then it's good to have a discrete part of the design responsible for this.
If you don't you don't need one - except I can't think of a case where you don't. The simplest dynamic page I can imagine is the foo request example, above. Even here clients won't necessarily get the page they asked for: bad input might have been submitted or a connection to the db server might be unavailable.
I hope I'm not "doing a Tony" here, but the best way I can think to implement an ApplicationController is with a ChainOfResponsibility. Requests map one-to-one with chains. Chains are configurable. 99% of the time client pages map one-to-one with handlers in the chain - add a handler for each of your possible "actions".
I'm guessing that your problem has arisen with form submissions. A request handling chain for a form submission might look like this:
BadRequestSyntax --> RedisplayHandler --> ProcessForm -->404 handler
Each handler has only one job to do. The redisplay handler will redisplay the form if the submission has invalid or missing values, if not, it does nothing at all and control passes to the ProcessForm handler. And so on.
There's a subtle difference between bad request syntax and invalid form submissions. Although both examine user input, the redisplay handler only looks at submission values in either GET or POST (depending on the form action). Bad request syntax performs wider checks on all of GPC. As a brief example, a missing required key outside of a form a submission could indicate tampering but a missing key in the form submission just means the user forgot to enter a value. Checking request syntax is basically a security check - kind of a firewall for the app - rather than a form validation check where you just want to know if the submission can be processed. Different logic, different actions to take, hence a different handler.
If access is restricted, you'd add:
BadRequestSyntax --> AuthenticationHandler --> AuthorisationHandler --> RedisplayHandler --> ProcessForm -->404 handler
In this case, AuthenticationHandler maps to a login page and AuthorisationHandler maps to a 403 page. However, if the user can be authenticated and is authorised, they don't do anything at all.
Bookmarks