Announcement Announcement Module
Collapse
No announcement yet.
Where to put business logic (Spring MVC) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Where to put business logic (Spring MVC)

    Hello
    I am strugling to find the right place to put my business logic.

    Example:
    I have a form registerCustomerContact.jsp

    Country: _____________V (Dropdown)
    Company:_____________V (Dropdown)

    Name: _______________
    Surname:_______________
    E-mail: _______________

    When the user select a value in the Country dropdown, the form is submitted.
    Then i want the Company dropdown to be populated with companies from the selected Country.

    Until now, i have done this in my Validator, but it doesn't feel like it's the right place to have this business logic.

    In my head, the Validator shall only check if the entered data are correct.

    I have also tried to do this in SimpleFormController.formBackingObject method, but it doesn't work.

    Therefore i would be happy if someone could tell me where the best place to put such logic.

    -- Per

  • #2
    This is not a standard technique to use SimpleFormController I suppose You could try to populate your second as well as third and so on combo-box with java script. Just make a js function like getAllCompaniesByCountry in your DWR controller and call it every time the user selects another country.

    Comment


    • #3
      Where are you populating your drop downs from? A database? Has it alreaby been queried and cached?

      If you are using JAVA 1.5 and Spring 2.5 or newer you could do this in your Controller. Change you controller you are using form a SimpleFormController to a controller. Then use annotation to have different method calls for each drop down.

      @Controller //tells Spring this is a controller - you have to have a bit of config in your app config XML to make Spring know to look for controllers here - look it up in ref docs.
      @RequestMapping(/conuntry/*.htm) //tell Spring this class that it will handle all URL's starting with /country/ and ending with .htm.
      public class myController {
      @ReqeustMapping("state") //URL /contry/state.htm will be handled by this method
      public List<State> getStateList{
      }
      @RequestMapping("company")
      public List<Company> getCompanyList{
      }
      }

      Then all you have to do is run the right URL when you drop down boxes are selected and let your JSP build your drop down's.

      Comment


      • #4
        Here is how to configure a package containing controllers that are mapped with annotations.

        <context:component-scan base-package="springapp.web"/>

        Comment

        Working...
        X