Results 1 to 8 of 8

Thread: Newbie: I need advice on when I should be creating new Controllers...

  1. #1
    Join Date
    Sep 2006
    Posts
    22

    Default Newbie: I need advice on when I should be creating new Controllers...

    I want to make a website with many pages. From what I've read so far about Spring MVC, all the examples seem to have a controller for each jsp. But I'm curious to know how things are set up for larger sites.

    Is there a controller for each jsp? I hope not, since there are many jsps.

    Do you tend to map many jsps to a single (or small number of) controllers? And if so, how do you decide which pages go with which controllers?

    Thanks

  2. #2
    Join Date
    Oct 2004
    Location
    Stockholm
    Posts
    79

    Default

    The whole point of a MVC is that you need a controller that preparese the model for your view. Of course, to make thinks go faster, you can prepare a default controller that creates an empty model and just shows your jsps. Whenever you need to add some model to the jsp you will change the default controller to a more specific one.
    Roberto Cosenza
    --
    Skicka stora filer enkelt med http://www.filecentral.se

  3. #3
    Join Date
    Oct 2006
    Posts
    124

    Default

    This might help you:

    Code:
    http://www.springframework.org/docs/MVC-step-by-step/Spring-MVC-step-by-step-Part-2.html

  4. #4
    Join Date
    Sep 2006
    Posts
    22

    Default

    Quote Originally Posted by robcos View Post
    ...you can prepare a default controller that creates an empty model and just shows your jsps...
    Do all your jsps go through the default controller? And does it do anything useful? If so, posting the code would be great :-)

  5. #5

    Default

    How would this default controller figure out which view to return? Or would you use a MultiView controller or something like that?

  6. #6

    Default

    But I'm curious to know how things are set up for larger sites.

    Is there a controller for each jsp? I hope not, since there are many jsps.
    In fact it is a good design to have a controller for each jsp, and its especially true for larger sites. With a single controller you run the risk of writing more if..else conditions, either within the controller or inside validators.

    For a single controller handling everything, you could try by extending from a MultiActionController/ MultiActionFormController and mapping directly to a method via MethodNameResolver, but the code will not look 'modularized'.

  7. #7
    Join Date
    Oct 2004
    Location
    Stockholm
    Posts
    79

    Default

    When sketching an application, I use a "standard" controller that takes the url and returns a jsp called with the same name (index.html -> index.jsp, addstuff.html -> addstuff.jsp and so on) and an empty model.
    When I go deeper into the application and start writing real controllers, I substitute each of the "standard" controllers with forms/controllers that do more stuff than returning an empty model. It is a good way to have all your urls in place before you write any java code.
    Roberto Cosenza
    --
    Skicka stora filer enkelt med http://www.filecentral.se

  8. #8
    Join Date
    Oct 2004
    Location
    Stockholm
    Posts
    79

    Default

    For those who are interested on the implementation of my default controller, you can visit the the spring consulting page on my site and download the source from there.
    Roberto Cosenza
    --
    Skicka stora filer enkelt med http://www.filecentral.se

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •