Skip to content
Anthony G edited this page Oct 11, 2016 · 25 revisions

Since 1.2.1 the library is able to handle FORM_POST the same way as all the other method types.
FORM_POST methods written in 1.1.x style are still supported. See documentation [here](Form Post Method1_1_x).

If you use version 1.0.x of the library see documentation [here](Form Post Method1_0_x).

If you write 1.2.1 style FORM_POST methods exception handling described here Form Post Exception Handling is not needed.

Server

A FORM_POST method handles submits of a Ext.form.Panel. The method has to be annotated with @ExtDirectMethod(ExtDirectMethodType.FORM_POST) and it has to return an instance of [ExtDirectFormPostResult] (http://rasc.ch/eds/apidocs/ch/ralscha/extdirectspring/bean/ExtDirectFormPostResult.html).

@Service
public class Profile {

    @ExtDirectMethod(ExtDirectMethodType.FORM_POST)
    public ExtDirectFormPostResult updateBasicInfo(@Valid BasicInfo basicInfo, BindingResult result) {
        if (!result.hasErrors()) {
            if (basicInfo.getEmail().equals("[email protected]")) {
                result.rejectValue("email", null, "email already taken");
            }
        }
        return new ExtDirectFormPostResult(result);
    }
}

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

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
    }
  });

FORM-DATA vs JSON posts

Please note that by default ExtJS forms submit using form-data. This means that de-serialization will not be handled by Jackson, but by a separate Spring MVC form handler. If you prefer to submit your forms using JSON you'll have to manually handle that:

buttons: [
    {
        text: 'Submit',
        handler: function() {
            myExtDirectService.formHandlingMethod(this.up('form').getValues(),
                function(result){
                    if(result.success) {
                        Ext.MessageBox.alert("Success", "Submitted form successfully");
                    }else{
                        Ext.MessageBox.alert("Failure", "Failed to submit form");
                    }
                }
            );
        }
    }
]

Examples

Clone this wiki locally