Skip to content

Simple Named Parameter Method

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

This feature is only available in Ext JS 4.x and Sencha Touch 2.x

Server

Named parameter methods on the server are annotated with @ExtDirectMethod and the type SIMPLE_NAMED:

    @Service
    public class NamedService {
    
      @ExtDirectMethod(ExtDirectMethodType.SIMPLE_NAMED)
      public String showDetails(String firstName, String lastName, int age)     
      { 
         ...
      }
    }

Calling named parameter methods only works if the code is compiled with debug statements. There is no standard way in Java to determine the name of a parameter. Spring does some magic and reads the names from the debug information. If your code is not or cannot compiled with debug statements add @RequestParam annotation in front of the parameters.

    @Service
    public class NamedService {
    
      @ExtDirectMethod(ExtDirectMethodType.SIMPLE_NAMED)
      public String showDetails(@RequestParam(value = "firstName") String firstName, 
                                @RequestParam(value = "lastName") String lastName, 
                                @RequestParam(value = "age") int age)     
      {
        ...
      }
    }

The library then reads the names of the parameters from the @RequestParam annotation. The annotation has precedence. The library always takes the parameter from @RequestParam if it exists, even when debug informations are available.

Like Simple Methods, named parameter methods supports these sever objects:

  • HttpServletResponse
  • HttpServletRequest
  • HttpSession
  • Locale
  • Principal
  • Parameters annotated with @RequestHeader (since 1.1.0)

Server object parameters may be added in any order.

      @ExtDirectMethod(ExtDirectMethodType.SIMPLE_NAMED)
      public String showDetails(HttpServletResponse response, 
                                String firstName, String lastName, 
                                HttpServletRequest request, int age)     
      { 
         ...
      }

Client

Calling the server method is similar to calling simple methods. Instead of adding the parameters one by one separated by a comma, these methods expect a JavaScript object with the name of the parameter as the key. The names have to match but the order doesn't matter. As usual the methods support a callback function as parameter after the values and a scope as the last parameter

    var values = {lastName: 'Doe', firstName: 'John', age: 27};
    namedService.showDetails(values, callbackFunction);
    
    //with scope
    namedService.showDetails(values, callbackFunction, this);