Announcement Announcement Module
Collapse
No announcement yet.
Issue with multiple parameters in a controller Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with multiple parameters in a controller

    Hi,

    I am currently developing an application which lets users create clients and associate one or more emails with them.

    Here’s the roo script which I wrote to generate the application:

    # Email Table
    entity jpa --class ~.model.Email --testAutomatically
    field string --fieldName email --notNull --sizeMin 1 --sizeMax 30

    # Note Table
    entity jpa --class ~.model.Note --testAutomatically
    field string --fieldName note

    # Client Table
    entity jpa --class ~.model.Client --testAutomatically
    field string --fieldName name --notNull --sizeMin 1 --sizeMax 30
    field set --fieldName emails --type ~.model.Email --cardinality ONE_TO_MANY --mappedBy client
    field set --fieldName notes --type ~.model.Note --cardinality ONE_TO_MANY --mappedBy client

    # Email Table
    focus --class ~.model.Email
    field reference --fieldName client --type ~.model.Client --cardinality MANY_TO_ONE

    # Note Table
    focus --class ~.model.Note
    field reference --fieldName client --type ~.model.Client --cardinality MANY_TO_ONE

    # MVC
    # change project type to web application and output war artifact
    web mvc setup
    # Generate Controller, etc.
    web mvc all --package ~.web


    Whenever I attempt to create new e-mails in my running application, I get a Status 400 error stating that “the request sent by the client was syntactically incorrect”.

    The data sent over the network by my browser to the application are the following:

    POST /myapplication/emails

    and

    Email=email1&&client=client1

    In the POST’s BODY.

    My conclusion is that the 400 error is due to the presence of two parameters in the POST’s body instead of one.
    [The Client Controller processes one parameter - client name - without issues].

    Which roo commands should I use to regenerate the EmailController.email(@valid Email email, BindingResult, …) method in EmailController_Roo_Controller.aj so that it correctly processes two parameters instead of one?


    Many thanks.

    Philroc

  • #2
    Hi,

    I have added breakpoints all over the EmailController.....aj class and run my application in debugging mode to see where it "lands" when one clicks the Save Button on the Email Creation Page.

    What I have found is that it lands nowhere, not even in the

    @RequestMapping(method=RequestMethod.POST, produces="text/html")
    public String EmailController.create(@Valid Email email, BindingResult...

    method as one would expect.

    My conclusion is that Roo does not generate the appropriate controller code when entities contain sets of other entities (eg, a Client contains a set of Emails).

    Philroc

    Comment


    • #3
      This happens to me a lot. It seems you can't have an attribute named the same as the class. Try changing your "email" attribute to something else (theEmail). Your gonna have the same problem with your "note" attribute in your Note class.

      Comment


      • #4
        This afternoon, I discovered that the create method

        @RequestMapping(method=RequestMethod.POST, produces="text/html")
        public String EmailController.create(@Valid Email email, BindingResult...

        in the EmailController does not work because the Email class which is passed by Spring is not valid.

        On the other hand, the following create2 method works when the Email Creation Form is submitted:

        @RequestMapping(method=RequestMethod.POST, params ={"email","client"}, produces="text/html")
        public String EmailController.create(@RequestParam("email") String email, @RequestParam("client") Integer client...) {
        System.out.println("email = " +email);
        System.out.println("client = " + client);
        ...

        Philroc

        Comment

        Working...
        X