Package io.keikai.jsp

Class SmartUpdateBridge.Builder

  • Enclosing class:
    SmartUpdateBridge

    public static final class SmartUpdateBridge.Builder
    extends Object
    A builder utils to create an instance of SmartUpdateBridge to use.

    For example,

    
         Map jsonResult = SmartUpdateBridge.Builder.create(servletContext, req, resp)
              .withComponent(spreadsheet -> doAnything(spreadsheet)) // Optional
            .withBook(book -> {
                            Sheet sheet = book.getSheetAt(0);
                            if ("reset".equals(action)){
                                    handleReset(sheet);
              } else if("check".equals(action)){
                                handleCheck(sheet);
              }
       }).build();
     

    • Method Detail

      • create

        public static SmartUpdateBridge.Builder create​(javax.servlet.ServletContext servletContext,
                                                       javax.servlet.http.HttpServletRequest req,
                                                       javax.servlet.http.HttpServletResponse resp)
        Creates the builder instance.
        Parameters:
        servletContext -
        req -
        resp -
        Returns:
      • create

        public static SmartUpdateBridge.Builder create​(javax.servlet.ServletContext servletContext,
                                                       javax.servlet.http.HttpServletRequest req,
                                                       javax.servlet.http.HttpServletResponse resp,
                                                       Map data)
        Creates the builder instance with ServletRequest.getReader() data, which is passed from Browser's window.fetch API.

        For example at client side,

        
             // The browser's fetch API will go through HTTPServletRequest's body data,
             // not HTTPServletRequest's getParameters().
        
             fetch("/action", {
                 headers: {
                     'Content-Type': 'application/json',
                 },
                 method: 'POST',
                    body: JSON.stringify(kkjsp.prepare('myzss', {action: action})) // prepares with Keikai's request data
                 })
                  .then(function (response) {return response.json()})
                  .then(kkjsp.process) // Keikai JSP response processor
                  .then(handleAjaxResult); // User defined function
         

        Parameters:
        servletContext -
        req -
        resp -
        data - the request body data, which is used for Browser's window.fetch API.
        Returns:
        See Also:
        ServletRequest.getReader()
      • build

        public Map build()
        Builds the Keikai's response JSON data in Map format.
        Returns:
      • build

        public Map build​(Map result)
        Builds the Keikai's reponse JSON data in Map format and merge with the give custom data.
        Parameters:
        result -
        Returns: