This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I understand the Page Controller, Task Controller example but i'm having some difficulty with the Front Controller technique.
... The "unit of control" in a Front Controller environment is generally not a servlet at all, but rather a delegate class that implements an interface that the Front Controller uses to manipulate the controller unit. Because these delegate classes represent operations to be performed, they themselves are instances of a pattern known as the Command Pattern and are therefore usually termed Commands. ...
I get the idea based on the Command pattern. The Command classes share an interface. The Front Controller is composed with Command classed. The url has a string like /command/* that is parsed by the web.xml sending control to the Front controller. In there, an id, which is after /command/* is used to determine which of the Command classes to use. This then delegates to a method from the Command classes, like execute() which has the code for the task to be performed (non-idempotent vs indempotent). I get all this. What I'm not clear about is how this will do Post-Request-Get? If the user hits reload or back button, won't the same id be sent anyway?
... The PRG Technique described previously also applies in the Front Controller scenario in which Commands can be Task Commands (typically non-idempotent, operational) or Page Commands (always idempotent, page preparatory). ...
Do you or Bear have any examples please? [ January 18, 2007: Message edited by: kwame Iwegbue ]
... * A GET request is made identifying the data to be displayed to a Page Controller. * The Page Controller gathers the data from the business tier and places it on the request as scoped variables. * The Page Controller forwards to the JSP page which display the data. ...
* A POST request is made to a Task Controller with data need to complete the controller's task. * The Task Controller instructs the business tier to perform the appropriate operation(s). * The Task Controller redirects to the appropriate Page Controller to display the results of the operation, which then follows the steps outlined in the previous scenario.
Does it mean that the configuration code in the Front controller servlet has to differentiate between GET and POST? SO if it is a POST request, delegates to Task command class (which then redirects to Page command class); if it is a GET request , then send to Page command class?
user reloads page. again mapped to MyFrontControllerServlet. again doDeleteTask is called
That is not what will happen.
Because you redirected to showConfirmDelete, that is the URL that is "sitting" on your browser. And that's the action that will get called again when the user hits reload.
That's what the redirect does for you. If you forwarded from doDeleteTask to showConfirmDelete, the browser has no knowledege of that and will refresh doDeleteTask. But the redirect causes the browser to be updated with the URL of the Page Command.
Joined: Sep 02, 2000
Thanks Bear. makes sense! Like I said, great article. Call up the GOF. It should be made into a pattern or something: "The Front Man pattern"