Skip to content
Ralph Schaer edited this page Sep 13, 2017 · 8 revisions

Spring 3.0.7

Make sure that you have at least version 3.0.7 of the Spring library as a dependency in your project. Version 3.1.2 works as well.

Deprecated Code

All the deprecated code from 1.0.x was removed.

  • Replace ExtDirectMethodType.TREE_LOADER with ExtDirectMethodType.TREE_LOAD

  • If there is a bean (map) "extDirectSpringExceptionToMessage" in your spring context replace it with a "extDirectSpringConfiguration" bean definition. See Configuration.

Method scanning

Method scanning now happens during startup of the application. In 1.0.x the scanning happened after the first request to api.js. This new behavior allows the library to report configuration problems and errors during startup. If something is not working look for warnings and errors in the log output.

JSON Handling

In version 1.0.x json serializing is handled by the MappingJacksonHttpMessageConverter and by ExtDirectSprings own JsonHandler. Deserializing is handled by MappingJacksonHttpMessageConverter.

In version 1.1.x serializing and deserializing is handled by the JsonHandler. MappingJacksonHttpMessageConverter is no longer needed for ExtDirectSpring 1.1. If there is a specially configured MappingJacksonHttpMessageConverter in the application you have to change this and configure the JsonHandler instead. Here an example with Spring JavaConfig.

@Bean
public JsonHandler jsonHandler() {	
  JsonHandler jsonHandler = new JsonHandler();				
  ObjectMapper objectMapper = new ObjectMapper();
  objectMapper.disable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS);
  jsonHandler.setMapper(objectMapper);
  return jsonHandler;		
}

FORM_POST

FORM_POST methods changed significantly. You have to change the code of these methods to make it work again with 1.1.x. These methods now must have a return type of void and no longer need the @ResponseBody annotation. The response has to be written with ExtDirectResponseBuilder. There is no longer a difference between methods with and methods without file upload.

Here to two examples that show the code changes that have to be made.

Example 1

Version 1.0.x

@ExtDirectMethod(ExtDirectMethodType.FORM_POST)
@ResponseBody
@RequestMapping(value = "/updateBasicInfo", method = RequestMethod.POST)
public ExtDirectResponse updateBasicInfo(Locale locale, 
                                         HttpServletRequest request, 
                                         @Valid BasicInfo basicInfo,
                                         BindingResult result) {
  if (!result.hasErrors()) {
    if (basicInfo.getEmail().equals("[email protected]")) {
      result.rejectValue("email", null, "email already taken");
    }
  }

  ExtDirectResponseBuilder builder = new ExtDirectResponseBuilder(request);
  builder.addErrors(result);
  return builder.build();
} 

Version 1.1.x

@ExtDirectMethod(ExtDirectMethodType.FORM_POST)
@RequestMapping(value = "/updateBasicInfo", method = RequestMethod.POST)
public void updateBasicInfo(Locale locale, 
                            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();
}

Example 2

Version 1.0.x

@ExtDirectMethod(ExtDirectMethodType.FORM_POST)
@RequestMapping(value = "/uploadTest", method = RequestMethod.POST)
public void uploadTest(Locale locale, 
                       HttpServletRequest request, 
                       @RequestParam("fileUpload") MultipartFile file,
                       HttpServletResponse response) throws IOException {
  ExtDirectResponseBuilder builder = new ExtDirectResponseBuilder(request);
  if (file != null && !file.isEmpty()) {
    builder.addResultProperty("fileContents", new String(file.getBytes()));
  }
  builder.successful();
  builder.buildAndWriteUploadResponse(response);
} 

Version 1.1.x

@ExtDirectMethod(ExtDirectMethodType.FORM_POST)
@RequestMapping(value = "/uploadTest", method = RequestMethod.POST)
public void uploadTest(Locale locale, 
                       HttpServletRequest request, 
                       @RequestParam("fileUpload") MultipartFile file,
                       HttpServletResponse response) throws IOException {
  ExtDirectResponseBuilder builder = new ExtDirectResponseBuilder(request, response);
  if (file != null && !file.isEmpty()) {
    builder.addResultProperty("fileContents", new String(file.getBytes()));
  }
  builder.successful();
  builder.buildAndWrite();
}
Clone this wiki locally