Skip to content

Form Post Method1_1_x

Ralph Schaer edited this page Apr 14, 2020 · 7 revisions

The FORM_POST method handling changed in version 1.1.0. [Here](Form Post Method1_0_x) you find the documentation if you use FORM_POST methods with 1.0.x.

Server

Form post methods need to fulfill some requirements:

  • These annotations are present
    • @ExtDirectMethod(ExtDirectMethodType.FORM_POST)
    • @RequestMapping
  • The value of the @RequestMapping method attribute is RequestMethod.POST
  • The method is a member of a Spring MVC @Controller bean
  • The method returns nothing (void) and has to write the response with the help of ExtDirectResponseBuilder.
    @Controller
    public class Profile {
    
      @ExtDirectMethod(ExtDirectMethodType.FORM_POST)
      @RequestMapping(value = "/updateBasicInfo", method = RequestMethod.POST)
      public void updateBasicInfo(HttpServletRequest request,
                                  HttpServletResponse response, 
                                  @Valid BasicInfo basicInfo, 
                                  BindingResult result) {
        if (!result.hasErrors()) {
          if (basicInfo.getEmail().equals("[email protected]")) {
            result.rejectValue("email", null, "email already taken");
          }
        }
        ExtDirectResponseBuilder.create(request, response).addErrors(result).buildAndWrite();
      }
    }

Such a method supports all the arguments a normal Spring MVC method does:
http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-arguments

Validation is also working the same way:
http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/validation.html#validation-mvc

The class ExtDirectResponseBuilder helps building the response and writes it into the http servlet response.

See also Form Post Exception Handling

Client

To configure a form post handler add the submit property in the api configuration of BasicForm.

  //Ext JS 3.x
  var basicInfo = new Ext.form.FormPanel( {
  //Ext JS 4.x
  var basicInfo = Ext.create('Ext.form.Panel', {
    ...
    api: {
      ...
      submit: profile.updateBasicInfo
    }

  });

It's possible to send additional parameters with the submit method.

  basicInfo.getForm().submit( {
    params: {
      foo: 'bar',
      uid: 34
    }
  });