Announcement

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

  • Blama
    replied
    Hi jaikumar,

    you wont get the User object, which is a javax.servlet.http class, at the clientside. But:
    • You can call the Servlet after login in the browser to see the data returned. Make sure the Servlet can handle HTTP GET as well, eg:
      Code:
          @Override
      	    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
      	        doPost(request, response);
      	    }
    • You can then build structures on the client that parse the data (which is just String data, not related to your User class). So make sure to write all needed data with the Servlet.
    • My User.setData looks like:
      Code:
          public static void setData(String data) {
      	        JSONValue jv = JSONParser.parseStrict(data);
      	        JSONObject jo = jv.isObject();
      	
      	        userLoginName = jo.get(UserPropertiesEnum.LOGINNAME.getValue()).isString().stringValue();
      	        userId = Long.parseLong(jo.get(UserPropertiesEnum.ID.getValue()).isNumber().toString());
      	        userTenantId = Long.parseLong(jo.get(UserPropertiesEnum.TENANTID.getValue()).isNumber().toString());
      	
      	        userRolesAsString = jo.get(UserPropertiesEnum.ROLESASSTRING.getValue()).isString() != null ? jo
      	                .get(UserPropertiesEnum.ROLESASSTRING.getValue()).isString().stringValue() : "";
      	.....
      All class variables are static. That way I can always just use the respective getter.

    Best regards
    Blama

    Leave a comment:


  • jaikumar
    replied
    Blama,

    How to parse the JSON data (rawData thats coming from the Servlet) is that we have to use the JSONHelper?

    In the servlet I have set like below:

    User user = (User) session.getAttribute("userDetails");
    PrintWriter out = pResponse.getWriter();
    out.print(user);

    //In the client side
    RPCManager.sendRequest(requestProperties, new RPCCallback() {
    @Override
    public void execute(RPCResponse response, Object rawData, RPCRequest request) {
    System.err.println("Response : " + rawData); ---
    // JSONValue user = JSONParser.parse(rawData.toString());

    //TODO - How to get the User object here in the client
    }
    });
    Last edited by jaikumar; 8 Sep 2015, 19:14.

    Leave a comment:


  • jaikumar
    replied
    Thanks Blama, Yes I will try with RPC calls for servlet
    Last edited by jaikumar; 8 Sep 2015, 19:01.

    Leave a comment:


  • Blama
    replied
    Hi jaikumar,

    this is one of my 1st calls in onModuleLoad:

    Code:
            RPCManager.sendRequest(new RPCRequest() {
                {
                    setActionURL("ServletLogin");
                }
            }, new RPCCallback() {
                public void execute(RPCResponse response, Object rawData, RPCRequest request) {
                    // Very important!
                    User.setData(rawData.toString());
                    I18n i18n = GWT.create(I18n.class);
    
                    String title = StringFormatter.format("lms - {0} \"{1}\" ({2}: {3}, {4}: {5}, {6}: {7})", i18n.loggedInAs(),
                            User.getUserLoginname(), i18n.name(), User.getUserCompletename(), i18n.company(), User.getUserLegalEntityName(), i18n.roles(),
                            User.getUserRolesAsString());
                    com.google.gwt.user.client.Window.setTitle(title);
                    SettingsCache sc = SettingsCache.getInstance();
                    sc.refresh(new BooleanCallback() {
                        @Override
                        public void execute(Boolean value) {
    
                            // Show tabs (depending on user grants)
                            mainLayout = new MainLayout();
                            mainLayout.draw();
                            // Old: Add the main layout container to GWT's root panel
                            // RootLayoutPanel.get().add(mainLayout);
                            RootPanel.get("productName").getElement().removeFromParent();
                            RootPanel.get("loadingMsg").getElement().removeFromParent();
                            RootPanel.get("waitMsg").getElement().removeFromParent();
                            RootPanel.get("productImg").getElement().removeFromParent();
                            RootPanel.get("loadingIndicator").getElement().removeFromParent();
                            RootPanel.get("loading").getElement().removeFromParent();
                            RootPanel.get("loadingWrapper").getElement().removeFromParent();
    
                            // Check for current version of the JS code
                            if (BuildDate.getBuildDate() < User.getServerCompileDate()) {
                                final DateTimeFormat dateFormatter = DateTimeFormat.getFormat("yyyy-MM-dd HH:mm");
    
                                Date clientBuildDate = new Date(BuildDate.getBuildDate());
                                Date serverBuildDate = new Date(User.getServerCompileDate());
                                SC.warn(
                                        "Attention",
                                        "Server built: "
                                                + dateFormatter.format(serverBuildDate)
                                                + ", Client built: "
                                                + dateFormatter.format(clientBuildDate)
                                                + ". Please refresh the client by reloading it (Ctrl-F5 or deleting the browser cache). Otherwise several malfunctions will occur!");
                            }
                        }
                    });
    User.setData parses the json result from ServletLogin. Servlet login returns the session data as json.

    Is there a reason you don't want to use RPC calls?

    Best regards
    Blama
    Last edited by Blama; 31 Aug 2016, 02:25.

    Leave a comment:


  • jaikumar
    replied
    Thanks Blama for the Response.
    Insteadof writing a new Servlet I cannot extend the IDACall servlet and get the Session info in that and pass it to the onLoad?

    I am not sure how to call the Servlet from the onModuleLoad since we are not using any RPC calls. Do you have any samples?

    Leave a comment:


  • Blama
    replied
    Hi jaikumart,

    you'll need to write a (protected) Servlet that extracts the Session Data from the session and sends them as e.g. JSON data to the browser.
    Then contact the Servlet in your onLoad and process/store the data you got. That's how I do the same thing.

    Best regards
    Blama

    Leave a comment:


  • jaikumart
    replied
    Any help please

    Leave a comment:


  • jaikumar
    started a topic Session in client side

    Session in client side

    SmartClient Version: v10.0p_2015-06-10/PowerEdition Deployment (built 2015-06-10)
    Browser Version : IE 11.0.9600.17843


    How to get the attribute value from Session in the EntryPoint class. I need to get some user information from Session and use it in the EntryPoint class.

    Thanks
Working...
X