Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    #16
    All correct. However just to clarify, what you've just explained is the Java platform's definition of a Java Bean, not something we came up with.

    Comment


      #17
      Originally posted by Isomorphic
      ...definition of a Java Bean, not something we came up with.
      Did you define the DS.xml file format? I was left confused because when you were saying the fields didn't match the getter/setter, I was thinking that the *member* names had to match the getter/setter, not the XML field names. I figured the serialization code looked at the bean *only* and said "Oh, I have these members and corresponding getter/setters, so I'll serialize these key-value pairs into the response."

      This is also what I was expecting to happen when when I started this thread and tried to figure out how to throw a bean into the response and have the platform send it back to the server (as a map or whatever). This all makes it much clearer (at least for me).

      Thanks for the help.

      Comment


        #18
        Yes, we defined the .ds.XML format. However it is the Java platform that defines that a Java Bean's properties exist because of getter/setter pairs with a particular naming convention, and that given a getter/setter pair like getBlah() / setBlah(), the name of the property is considered to "blah" with a lowercase B.

        Comment


          #19
          Hi isomorphic,

          I am trying to get JSON object from server using RPC manager. I am sending a Map(java.util.Map) from server using REST. Getting data as well on client side. But the issue is that I am unable to convert that data in Map or any other object at client side. Here is my code snipet:
          Client side:
          RPCRequest request = new RPCRequest();
          request.setHttpMethod("GET");
          request.setContentType("application/json");
          request.setActionURL("/resource/cms/end-points");
          request.setUseSimpleHttp(true);
          RPCManager.sendRequest(request, new RPCCallback() {
          @Override
          public void execute(RPCResponse response, Object rawData, RPCRequest request) {
          try {
          // JavaScriptObject jso = response.getDataAsMap();
          Map<String,String> map = response.getDataAsMap();

          String msg = map.get("viewNewsUrl");
          GWT.log(msg);
          }
          catch(Exception ex) {
          GWT.log(ex.getLocalizedMessage());
          GWT.log(ex.getMessage());
          GWT.log(ex.toString());
          }
          }
          });

          Server side code is:
          @Controller
          @RequestMapping("/resource")
          public class ResourceResolverController {

          @RequestMapping(value="/cms/end-points", method = RequestMethod.GET, headers = "Accept="
          + MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
          @ResponseBody
          public Map<String, String> getCMSContentUrls(HttpServletRequest request, HttpServletResponse response) {

          Map<String, String> cmsContentUrls = new LinkedHashMap<String, String>();
          cmsContentUrls.put("viewNewsUrl", "some url");
          cmsContentUrls.put("addNewsUrl", "some url");
          cmsContentUrls.put("viewEventsUrl", "some url");
          cmsContentUrls.put("addEventsUrl", "some url");

          return cmsContentUrls;

          }
          }

          Getting below exception:

          convertToMap - unable to convert the passed JavaScript object to a Map. JavaScript is: "{"viewNewsUrl":"some url","addNewsUrl":"some url","viewEventsUrl":"some url","addEventsUrl":"some url"}"
          SuperDevModeLogger.java:71 convertToMap - unable to convert the passed JavaScript object to a Map. JavaScript is: "{"viewNewsUrl":"some url","addNewsUrl":"some url","viewEventsUrl":"some url","addEventsUrl":"some url"}"
          SuperDevModeLogger.java:71 java.lang.IllegalArgumentException: convertToMap - unable to convert the passed JavaScript object to a Map. JavaScript is: "{"viewNewsUrl":"some url","addNewsUrl":"some url","viewEventsUrl":"some url","addEventsUrl":"some url"}"

          I have tried multiple ways to map data at client side like below:

          JavaScriptObject jso = (JavaScriptObject)rawData; Map<String,String> map = (Map<String,String>)JSOHelper.convertToMap(jso);

          Comment


            #20
            Start by posting both the server-side log for the request as well as the response from the server as seen in the SmartGWT Developer Console RPC tab.

            Comment


              #21
              Hi isomorphic,

              What is the best approach to use global variables in smartgwt? I have some variables which should be loaded once globally and can be used later on as required. For more specifically, I have some configurable constants which are going to be retrieved from the server. I want to load these variables on page load in some global variables at smartgwt end use them later on. Can you suggest some approach with some example?
              Regards
              Ankul

              Comment


                #22
                Originally posted by ankulchoudhary View Post
                Hi isomorphic,

                What is the best approach to use global variables in smartgwt? I have some variables which should be loaded once globally and can be used later on as required. For more specifically, I have some configurable constants which are going to be retrieved from the server. I want to load these variables on page load in some global variables at smartgwt end use them later on. Can you suggest some approach with some example?
                Regards
                Ankul
                I'm using sth like this (don't know if it is the best approach because it delays the UI drawing by 1 server roundtrip, but I need the info before drawing the UI):

                In onModuleLoad:
                Code:
                final SettingsCache sc = SettingsCache.getInstance();
                sc.refresh(new RPCQueueCallback() {
                                    @Override
                                    public void execute(RPCResponse... response) {
                                        // Show tabs (depending on user grants)
                                        mainLayout = new MainLayout();
                                        mainLayout.draw();
                SettingsCache-singleton contains the logic to store the needed global vars.
                Code:
                    public void refresh(final RPCQueueCallback rpcQueueCallback) {
                        RPCManager.startQueue();
                        settingsAndDefaultsDS.fetchData(null, new DSCallback() {
                        ...
                        ...
                
                ...many requests...
                ...many requests...
                
                        RPCManager.sendQueue(rpcQueueCallback);
                    }
                Now in the application I get the singleton wherever I need it and have many many getters there for my global settings that come from the DB.

                Best regards
                Blama

                Comment

                Working...
                X