Announcement Announcement Module
Collapse
No announcement yet.
A design question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • A design question

    Guys,

    I have a design question I could use some inputs on.

    The basic flow of the web application is basically:
    1) A view forwards to a controller.
    2) The controller processes the view, execute business logic, decide what the next view should be, prepare model for the view, and forward to the view.

    Let's say the business function we need to execute is productSearch().

    productSearch takes in a specific set of inputs, process business logic, and based on the result, return to different views.

    Should all that be extracted to a seperate function in a helper class? Say SearchManager?

    I like this approach since productSearch could be invoked from different controllers and it will behave exactly the same way. Returns a ModelAndView based on the same logic.

    However, I don't like this approach because now productSearch is coupled with the knowledge of views and things like httprequest. It will be harder for me to seperate the business logic out by themselves later.

    What is the best practice here? What are the standard objects that the controller should interact with and what are their responsibliites?

    Thanks!

  • #2
    I am not sure I am the best person to help but here it is.
    The request should be mapped to a bean (either through a command object or manually in the controller code).
    So the logic should not be dependent on the httpRequest.

    As for the second part, it depends really on how you decide which is the next view to be displayed.

    Ideally, you would process the business logic based on bean and return someting that can be used as a model. Based on that data in the controller you could decide which view to forward the request to.

    Comment


    • #3
      Hi,
      I think you've got the right idea by moving the business logic out of the controller class and you can easily do it in a way that decouples the business layer from the web-tier layer, in other words the business layer doesn't need to know anything about the HTTP request etc, it just deals with JavaBeans.

      I'm assuming you are using a form for user input of search criteria, such as product name or id. If so, then you probably have a controller class that extends Spring's SimpleFormController. The bean definition for this class can include a property called commandClass. This will be a class that you write and it will be a simple JavaBean that will contain the data displayed in the HTML form as well as any other properties you want to add. You might choose to call it ProductSearchCommand. Your controller class receives this object as a parameter to it's onSubmit() method.

      Your controller will also have a reference to the business service interface that you use to perform the business logic. SearchManager was the example you gave. The SearchManager implementation class would receive the ProductSearchCommand object as a parameter to its business method, use the details in this command object to perform the search and then return maybe a list of ProductSearchResult objects to the controller. The controller class would then create a ModelAndView object and populate it with the list of results before forwarding to the appropriate view.

      Hope that helps

      Comment


      • #4
        yup, that helps, thanks!

        Comment

        Working...
        X