Musings: MVC Front Controller/Command and Controller Strategy

Hi,
I am currently taking my first shot at implementing the Front Controller pattern, the Command and Controller Strategy flavor, in Java. When applying the pattern, my chosen point of focus is achieving as much isolation as possible of Client-specific implementation details from the rest of the framework (Web-based framework Clients, Swing-based framework Clients, queueing-based framework Clients, etc.) However, I am running into a lot of (apparent?) inconsistencies when it comes to CCS discussions "out there", so I have a feeling that perhaps I have misunderstood the Front Controller/Command and Controller Strategy pattern. Maybe the MVC gurus out there would have some thoughts on the matter.
My issues:
1.) Some CCS discussions seem to assign View presentation (sometimes called "dispatch", or "rendering", or "forwarding"?) to an ApplicationController. It seems puzzling to me, since only a concrete FrontController should include any knowledge of a concrete View structure. Shouldn't only a FrontController perform a logical-to-physical resource mapping, thus encapsulating knowledge whether a particular View is a separate, stand-alone Web page or a compound, argument-driven Swing object, and how to "present it" (by either redirecting to a Web page, or bringing a particular Swing object into the foreground)?
2.) Some CCS discussions seem to introduce Client-specific implementation details at the ApplicationController level, for example "HTTP requests" or "HTTP responses". It seems puzzling to me, since I feel that every part of the framework, except for a concrete FrontController, should be completely independent of the nature of a Client making a request. Instead, I created a generic Request object w/arguments and have a concrete FrontController translate any client-specific details into such a generic Request, before delegating to an ApplicationController.
3.) In the light of the (2.) above, I am not sure what constitutes a "response" from an ApplicationController back to a FrontController. It seems to me that the only universal "response" is a LogicalViewEnumeration: what View to present once a command has been completed, in many cases a "don't care", or a "show the requestor", or a "show a home page" (not every request has to result in changing a View). Well, perhaps a LogicalViewEnumeration as well as possible View arguments (?).
4.) In the light of the (3.) above, I suspect that any failures in Request delegation, or Command execution, should be perhaps propagated back to a FrontController by exceptions only, since, say, a WebFrontController might want to show a click-through error page, when a SwingFrontController might prefer to show an error dialog box, a LogicalErrorViewEnumeration might not make sense at all in the context of a particular Client, for example a queueing Client.
5.) In the light of the (4.) above, there is the question of an appropriate Request interface (into an ApplicationController), an appropriate Response interface (back into a FrontController), as well as an appropriate ViewArguments interface (into a FrontController and later into a View). The problem with generic Requests is that they can be created with nonsensical argument combinations, so shouldn't Requests be abstract and force proper arguments in concrete subclasses, through explicit constructors (in a sense, degenerate Commands)? The problem with Responses and ViewArguments is that... well, I have not found any formal discussion anywhere as to what those should look like. In most samples I have encountered, Responses include Client-specific implementation details, as mentioned in (2.), above.
6.) Some CCS discussions seem to introduce a Flow Manager at the ApplicationController level. It seems puzzling to me, since the whole point of the Command and Controller Strategy flavor seems to be centralization of business logic execution within self-contained Command objects. Shouldn't Requests get associated with Handlers (objects capable of actually carrying out Requests) and transformed into Commands inside an ApplicationController, thus Commands themselves return appropriate LogicalViewEnumeration back to an ApplicationController, back to a FrontController? Let's consider a ShowMyShippingAddress request coming into the framework: unless such a Request is eventually treated as a Command returning a particular LogicalViewEnumeration, it is suddenly a Flow Manager "acting" as a business logic driver. I guess the question here is: except for a few special cases handled by a particular ApplicationController (authentication, error conditions, default behavior, etc.), should flow management be considered stand-alone, or always delegated to Commands?
7.) Some CCS discussions seem to include an extra Request argument that specifies an ApplicationController to use (Request.Action="create", Request.Controller="account", Request.Username="me-me-me"), instead of using a Router inside of a FrontController to resolve to a particular ApplicationController through a generic action (Request.Action="createAccount", Request.Username="me-me-me"). I am not sure about the reason for such a design decision: why should a Client or a FrontController be allowed to concern itself with an implementation-level structure of the framework? Wouldn't any framework state -dependent ApplicationController resolution issues be best handled inside a Router, used by a FrontController to resolve [obtain] an appropriate ApplicationController, thus preventing Clients from ever forcing the framework into a possibly inconsistent behavior?
Any comments appreciated...
Thanks,
Gary

gniemcew wrote:
1.) Some CCS discussions seem to assign View presentation (sometimes called "dispatch", or "rendering", or "forwarding"?) to an ApplicationController. It seems puzzling to me, since only a concrete FrontController should include any knowledge of a concrete View structure. Shouldn't only a FrontController perform a logical-to-physical resource mapping, thus encapsulating knowledge whether a particular View is a separate, stand-alone Web page or a compound, argument-driven Swing object, and how to "present it" (by either redirecting to a Web page, or bringing a particular Swing object into the foreground)?It is hard to tell without reading the actual discussion, but my guess is that the posters were either conflating or being loose with the distinction between a FrontController and an ApplicationController. The former is (normally) intimately tied to the actual view being used (HTTP, Swing, etc.) whereas the ApplicationController typically is not. Both are involved in dispatch and event processing. The former normally renders a view whereas the latter does not.
gniemcew wrote:
2.) Some CCS discussions seem to introduce Client-specific implementation details at the ApplicationController level, for example "HTTP requests" or "HTTP responses". It seems puzzling to me, since I feel that every part of the framework, except for a concrete FrontController, should be completely independent of the nature of a Client making a request. Instead, I created a generic Request object w/arguments and have a concrete FrontController translate any client-specific details into such a generic Request, before delegating to an ApplicationController.Generic is fine. However, you can become generic to the point where your Request and Response interfaces are only acting as "marker" interfaces (think of java.io.Serializable). Writing a truly generic controller is possible, but personally, I have never found the effort justified.
gniemcew wrote:
3.) In the light of the (2.) above, I am not sure what constitutes a "response" from an ApplicationController back to a FrontController. It seems to me that the only universal "response" is a LogicalViewEnumeration: what View to present once a command has been completed, in many cases a "don't care", or a "show the requestor", or a "show a home page" (not every request has to result in changing a View). Well, perhaps a LogicalViewEnumeration as well as possible View arguments (?).A given service (if you ascribe to SOA) should be the fundamental unit in your architectural design. A good application controller would be responsible for determining how to dispatch a given Command. Whether a Command pattern is used or whether service methods are invoked directly from your FrontController, the ApplicationController should enforce common service aspects. These include authentication, authorization, auditing, orchestration, validation, logging, error handling, just to name a few.
The ApplicationController should ideally offload these aspects from a given service. The service would indicate how the aspects are to be applied (e.g., strong authentication required, x role required, fetching of existing process state, etc.) This allows services to be developed more quickly and to have these critical aforementioned aspects developed and tested centrally.
Your FrontController, in contrast, is responsible for transforming whatever input it is designed to receive (HTTP form data posts, XML-RPC, etc.) and ensure that it honors the contract(s) that the ApplicationController establishes. There are no cut-and-dry decisions though about when a given piece of functionality should be ApplicationController or FrontController. Take error handling. Should I emit just a generic ServiceException or allow the FrontController to decide what to do with a more concrete checked exception? (The FrontController, in any case, should present the error to the user in a manner dictated by the protocol it serves).
gniemcew wrote:
4.) In the light of the (3.) above, I suspect that any failures in Request delegation, or Command execution, should be perhaps propagated back to a FrontController by exceptions only, since, say, a WebFrontController might want to show a click-through error page, when a SwingFrontController might prefer to show an error dialog box, a LogicalErrorViewEnumeration might not make sense at all in the context of a particular Client, for example a queueing Client.See above. Yes. However, the ApplicationController could easily 'hide' details about the failure. For example, any number of exceptions being mapped to a generic DataAccessException or even more abstractly to a ServiceFailureException. The ApplicationController could indicate whether the failure was recoverable and/or populate information necessary to speed up production support (e.g., mapping exceptions to error codes and/or providing a primary key in an error audit log table for support to reference). A given FrontController would present that information to the user in the method that makes sense (e.g., error dialog for Swing, error page for HTML, etc.)
gniemcew wrote:
5.) In the light of the (4.) above, there is the question of an appropriate Request interface (into an ApplicationController), an appropriate Response interface (back into a FrontController), as well as an appropriate ViewArguments interface (into a FrontController and later into a View). The problem with generic Requests is that they can be created with nonsensical argument combinations, so shouldn't Requests be abstract and force proper arguments in concrete subclasses, through explicit constructors (in a sense, degenerate Commands)? The problem with Responses and ViewArguments is that... well, I have not found any formal discussion anywhere as to what those should look like. In most samples I have encountered, Responses include Client-specific implementation details, as mentioned in (2.), above.See comment on marker interfaces above. Nothing, however, stops you from requiring a certain sub-type in a given service method. You can still pass in the interface and validate the proper type by an assert statement (after all, in the vast majority of situations, the proper service method should get the proper instance of a given Request object). IMO, the FrontController would create the Command instance which would be passed to the ApplicationController which would dispatch and invoke the proper service method. A model response would be received by the FrontController which would then render the appropriate view.
gniemcew wrote:
6.) Some CCS discussions seem to introduce a Flow Manager at the ApplicationController level. It seems puzzling to me, since the whole point of the Command and Controller Strategy flavor seems to be centralization of business logic execution within self-contained Command objects. Shouldn't Requests get associated with Handlers (objects capable of actually carrying out Requests) and transformed into Commands inside an ApplicationController, thus Commands themselves return appropriate LogicalViewEnumeration back to an ApplicationController, back to a FrontController? Let's consider a ShowMyShippingAddress request coming into the framework: unless such a Request is eventually treated as a Command returning a particular LogicalViewEnumeration, it is suddenly a Flow Manager "acting" as a business logic driver. I guess the question here is: except for a few special cases handled by a particular ApplicationController (authentication, error conditions, default behavior, etc.), should flow management be considered stand-alone, or always delegated to Commands?There are distinct kinds of flow management. For example, orchestration (or BPM) is properly at either the service or ApplicationController layers. However, determining which view to display is properly at the FrontController layer. The ApplicationController should receive a Command (with a populate Request) and return that Command (with a populated Response). Both the Request and Response are fundamentally model classes (within MVC). The FrontController is responsible for populating the Request and/or Command and rendering the Response and/or Command. Generic error handling is usually centralized for both controllers.
gniemcew wrote:
7.) Some CCS discussions seem to include an extra Request argument that specifies an ApplicationController to use (Request.Action="create", Request.Controller="account", Request.Username="me-me-me"), instead of using a Router inside of a FrontController to resolve to a particular ApplicationController through a generic action (Request.Action="createAccount", Request.Username="me-me-me"). I am not sure about the reason for such a design decision: why should a Client or a FrontController be allowed to concern itself with an implementation-level structure of the framework? Wouldn't any framework state -dependent ApplicationController resolution issues be best handled inside a Router, used by a FrontController to resolve [obtain] an appropriate ApplicationController, thus preventing Clients from ever forcing the framework into a possibly inconsistent behavior?I am not 100% sure of what you are getting at here. However, it seems to be the method by which commands are dispatched. They are in effect allowing a FrontController to dictate which of n ApplicationControllers should receive the request. If we allow a FrontController to directly invoke a service method, then the ApplicationController is simply a centralized framework that should always be invoked for each service method (enforced via AOP or some other mechanism). If there is a single, concrete ApplicationController which handles dispatch, then all FrontControllers communicate directly with that instance. It is really just a design decision (probably based on your comfort level with concepts like AOP that allow the ApplicationController to exist solely behind the scenes).
I might have totally missed your questions, but those are my thoughts on a Monday. Best of luck.
- Saish

Similar Messages

  • Difference between MVC & Front- Controller

    Hi All,
    could anyone help me out in differenciating the MVC & Front controller patterns.
    regards
    Karthik

    When should an application use the Front Controller
    patern and when should they use MVC? This boils down to scope of the problem domain and requirements.
    The Front Controller seems largely like a subset of
    MVC.Yes.
    Is there a situation where the Front Controller
    is more advantageous to use than MVC?Where its lighter weight pays off, i.e where you do not have a conventional model, e.g with streaming prototcol handlers or with fast readers. MVC is most useful for a N-Tier J2ee application offering CRUD type functionality.

  • Front Controller Pattern and issues

    Hi,
    I've implemented the front controller pattern using a Servlet and some JSP pages. The issue I have is that if the JSP page button is clicked, the controller handles the request and performs the proper forwarding.
    But for instance, if I type in the URL for the page directly without going through the servlet in the FORM tag then obviously the servlet cannot process the request.
    Here's a more concrete example: I have an informational page that you get to by first logging in. But if I type the name of the page directly, http://localhost/employerInfo.jsp I am taken directly to this page, even though I should have logged in first.
    I believe there's a way to do this, but I'm completely stumped as to how.
    Any information or insight is greatly appreciated.
    Thanks,
    John

    Hey John,
    What you need to do is not to access the employerInfo.jsp directly but call the servlet.
    You can map a servlet to a URL. For example, using your example below you can call: http://localhost/myservlet?action=openEmployeeInfo
    Now your servlet can retreive the action using String x = request.getParameter("action"); You can test if x.equals("openEmployeeInfo") then get the information from a db or something else. Set the info on a context like request, session or servlet context and then forward to the jsp page using the request dispatcher.
    RequestDispatcher rd = request.getRequestDispatcher("/employeeInfo.jsp");
    rd.forward(request, response);
    If you have more questions, post here again.

  • Front Controller Pattern

    I'm going to implement the front controller pattern. As it is implemented in the blueprints (Pet Store), requestmappings.xml and screendefinitions.xml are only read upon start up. Thus, the web application has to be restarted to carry out changes.
    I'd like the possibility to perform changes to these files without restarting the app. How should I go about? As I don't want to read the file for every request, I need some kind of cache. But this cache should have some kind of automatic updating mechanism when the files are changed.
    Has anyone done something like this for large web applications?

    I've used a similar approach for this (kitv.co.uk), the project not the website, which is pretty heavy weight application, interactive digital Television over IP.
    My design used the command pattern (GOF 233), which is (IMHO) a better solution to implement the front controller.
    I created an action/command to perform a reload, this re-initialises my request/response handlers (equivelent to the ScreenFlowManager). The re-initialise is really just an alternative wrapper as the initial load.

  • Splitting up the Spring front controller servlet into more than one file

    In a multi-developer environment, it's obviously a bit of a pain to all use the same front controller xml file for mapping requests. Therefore does anyone know of a way we could split this into many files, for example one for each logically distinct application?
    Many thanks

    Hi,
    What are these files did you want to delete? As I know, the trusted installer group owns many system files and will deny you access to move or delete. incorrect deletion of these files will cause serious problem. If you want to delete these files, you can
    take the owner of these files and guarantee administrator permissions with icacls command, it can reduce amount of your work.
    How to Handle NTFS Folder Permissions, Security Descriptors and ACLs in PowerShell
    http://blogs.technet.com/b/josebda/archive/2010/11/12/how-to-handle-ntfs-folder-permissions-security-descriptors-and-acls-in-powershell.aspx
    And according to your description, do you want to convert an internal hard drive to external? if so, how did you perform this action? here is an article you can refer to:
    http://www.computershopper.com/peripherals/howto/build-your-own-external-hard-drive
    NOTE
    This
    response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.
    Microsoft
    does not control these sites and has not tested any software or information found on these sites.
    Yolanda Zhu
    TechNet Community Support

  • Front Controller in Web Logic

    I am currently working on a front controller.
    WHat i whant to do is pass all call to object on my server through this controller
    like this
    a get for /Info.jsp is caught by the /* servlet url pattern
    next i will handle and check things.
    Finally a want t pass the user the Page.
    This causes a loop.
    Anybody any ideas on how to solve this in web logic

    I think what you need to do is make sure that your scripts are not stored in the root path of your application.
    In your example you are using the root context to trap all requests incoming, processing that request and then presumably trying to forward or redirect to the /login.jsp page after initial processing. Unfortunately requests sent to /* are intercepted and passed to your controller so the attempt to forward to /login.jsp loops back through your server repeatedly.
    Perhaps if you map your controller servlet to a different context to the one where you store your scripts you will then be able to forward successfully
    e.g map the context /members/* to your controller, but store your scripts in the /private context - /private/login.jsp . Then provide a mapping in your controller between script name and actual script location, do a lookup and forward accordingly.
    if you make sure that all your links within your application point through /members/ they will always be processed through your controller. For example the login page would be accessed as /members/login.jsp but after processing in your controller you do a look up and see that login.jsp is in private so you forward your request to /private/login.jsp .
    Well, thats how I would approach it anyway ....

  • Front Controller Servlet

    Hello friends.
    I need to implement a Front Controller servlet. I will then forward the request to other servlets. So, even I the client explicitly requests the servlet, say /Dummy, I want the request to pass through /FrontController first.
    If I map FrontController to /*, and Dummy to /Dummy, then the letter will override the more general mapping. Also, the first mapping (/*) will spoil all other URL requests, such as /index.htm, etc.
    Please, give a hint.

    Is it possible at all?
    When a servlet is called (any servlet), another servlet intercepts it first, and then forward the request to the called servlet.

  • Front controller calls

    Hey all
    At the moment my front controller servlet determines where my JSP calls come from via hidden html fields, sort of like this:
    <input type="hidden" name="jspSource" value="addToFavorite" />But I've also seen people take this route:
    <form action="/controllerServlet?action=<addToFavorite>Are there any conventions here I should follow? I find that my method works well, but I need a bunch of if clauses in the controller to determine where the call comes from, like this if(jspSource.equals("addToFavorite"))

    Just always use the same parameter. I usually use two parameters:
    action - this determines what servlet / jsp to invoke
    subaction - this determines what the servlet should do and what the jsp should display.
    Example:
    action - repository
    subaction - deletefile

  • Page/front controller

    Does JSF implement front controller pattern or page controller pattern?
    In this article http://websphere.sys-con.com/read/46516.htm I read that it implements page controller but sincerely I am not able to see JSF fit in this pattern...Do you think it is true? But, above all....why?:P
    thanks

    I hate to do this to you but check this link for the debate: http://mail-archives.apache.org/mod_mbox/struts-user/200603.mbox/%[email protected]%3E
    There is no doubt that JSF uses the Front Controller design pattern, but gives you "page controller" funcationality to.

  • Command and Conquer Game Speed

    Hi guys, recently i bought command and conquer from the psn store for ps3, tried playing it and game speed seems to be stuck on very fast with no option to lower it. Game is difficult enough to play with a controller let alone at super-speed. Been looking around the forums and can't find a fix for this, has anyone managed to lower the game speed?

    You can try deleting the GAMEDATA and redownload it.
    Edit: game manual here. http://www.world-of-playstation.com/manuals/playstation/COMMANDANDCONQUER.shtml

  • I'm having a real problem with my cursor which seems to have developed a mind of its own, zigzagging allover, highlighting things without my command, and basically making my MacBook unuseable (it's taken me half an hour just to compose this!).

    I'm having a real problem with my cursor which seems to have developed a mind of its own, zigzagging allover, highlighting things without my command, and basically making my MacBook unusable (it's taken me half an hour just to compose this!).

    There are several possible causes for this issue. Please take each of the following steps that you haven't already tried until it's resolved. Some may not apply in your case.
    1. Follow the instructions in this support article, and also this one, if applicable. A damaged or defective AC adapter could be the cause, even if it's the right kind.
    2. Press down all four corners of the trackpad at once and release. If there's any effect, it's likely to be temporary, and in that case the unit must be serviced or replaced.
    3. Open the Bluetooth preference pane in System Preferences and delete all pointing devices other than the trackpad, if applicable. Disconnect any USB pointing devices. By a "pointing device," I mean a peripheral that moves the cursor, such as a trackpad, mouse, trackball, or graphics tablet. A plain keyboard is not a pointing device.
    4. Start up in safe mode and test, preferably without launching any third-party applications. If you don't have the problem in safe mode, but it comes back when you restart as usual, stop here and post your results. Do the same if you can't start in safe mode. If there was no difference in safe mode, go on to the next step.
    5. Reset the System Management Controller.
    6. If you're using a Bluetooth trackpad or mouse, investigate potential sources of interference, including USB 3 devices.
    7. A swollen battery in a portable computer can impinge on the trackpad from below and cause erratic behavior. If you have trouble clicking the trackpad, this is likely the reason. The battery must be replaced without delay.
    8. There's a report that a (possibly defective) Thunderbolt Ethernet adapter can cause the built-in trackpad of a MacBook to behave erratically. If you're using such an adapter, disconnect it and test.
    9. There's also a report of erratic cursor movements caused by an external display that was connected but not turned on.
    10. If none of the above applies, or if you have another reason to think that your computer is being remotely controlled, remove it from the network by turning off Wi-Fi (or your Wi-Fi access point), disconnecting from a Bluetooth network link, and unplugging the Ethernet cable or USB modem, whichever is applicable. If the cursor movements stop at once, you should suspect an intrusion.
    11. Make a "Genius" appointment at an Apple Store to have the machine and/or external trackpad tested.

  • What is the diffrence between OMB plus command and OMB command

    what is the diffrence between OMB plus command and OMB command?
    are they both TCL command?

    Hi Alena,
    Welcome to SDN.
    Check this
    EXIT in Loops and Modularization Units
    Basic form
    EXIT.
    Effect
    Within a loop structure:
    Terminates looop processing (DO, WHILE, LOOP, SELECT).
    Within subroutines and other modularization units (but not in a loop structure):
    Leaves the subroutine or modularization unit (FORM, MODULE, FUNCTION, TOP-OF-PAGE, END-OF-PAGE).
    Outside loop structures and modularization units (report processing):
    Terminates report processing and triggers list display.
    But not sure about
    atexit() .. ,may use in Object Oriented Programming.
    (C++)
    "At exit-command in module pool."
    Mohinder
    Edited by: Mohinder Singh Chauhan on Aug 1, 2008 8:06 AM

  • I just downloaded and instaled firefox 4. Now, everytime I institute a command I get a po[p-up from Java script that tells me to uninstal set. I cannot go on untin I press ok and then I am good for one more command and it starts with the pop-up again.

    I'm not even sure if this is an extension or plug-in and all I can tell you is what I have already stated. I can only make one command at a time and after each one I get a pop-up from Java script that says uninstal set. I must depress ok to move on, but only for one more command and it starts over again. This also happened when I tried to instal firefox 4 a couple months ago and I deleted the program and went back to an earlier version.

    Mail troubleshooting - Yosemite
    Troubleshooting sending and receiving email messages
    Troubleshooting sending email messages
    SMTP servers keep going offline

  • What key(s) do i type to change language from english to other? i am writing s story in dual languages. i was told to click command and space bar together but it is not working.

    what key(s) do it type to change language from english to other? i am writing a story in dual languages. I was told to click command and space bar together but it is not working.

    Command Spacebar opens Spotlight as you have found out. If you want to change languages you need to say what app you are using to write the story in, I'm guessing you are using Pages or MS Word. If that's the case
    Pages: Open Inspector - Click the T tab - Click Language and change your language.
    MS Word: Tools Menu - Language - Choose your language.

  • Dunning by dunning procedure and collection strategy

    Hi All,
    Have some questions around dunning.
    1. Can dunning by dunning procedure and collection strategy coexist in the same company code - if this cannot be achieved by config can it be achieved by development - can we have something like account determination IDs of X to use dunning procedure, account determination IDs of Y to use collection strategy?
    2. If the answer to 1. is no, can one company code use dunning procedure and another company code use collection strategy?
    3. What is SAP's (or any other proven) recommended approach to migrate a production system utilising dunning by dunning procedure to dunning by collection strategy?
    Cheers.

    Have a look
    SAP-ISU will be used to carry out initial collection activities. Initial 1 or 2 reminder letters (based on the customer type, Live or Closed) will generated from SAP-ISU. Thereafter, the account will be managed in Tallyman. Thus, all the subsequent activities, such as sending further reminder letters, sending debt to collection agencies, carry out warrant activities and taking customers to court will be carried out in Tallyman system. During the time, the account is in Tallyman, no dunning activities will be carried out in SAP.
    There will be daily interfaces from SAP-ISU to Tallyman to update Tallyman of Accounts that have passed a certain dunning level in SAP-ISU and any changes to the account that are currently being managed in Tallyman. Similarly there will be interfaces from Tallyman to SAP to update SAP of Accounts, that have been marked for write off in Tallyman. Fees and Charges that have been applied in Tallyman, for example court fees, warrant fees etc.
    Regards
    Shashi
    Edited by: shashi jha on Mar 31, 2010 8:10 AM

Maybe you are looking for