Announcement

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

    Localized Error Messages for Server Side DSRequest

    Hi Isomorphic. Is there any way to set the actionUrl for a server DSRequest, like it it possible for a client DSRequest?

    I need to do this (I think) so that I can specify the locale explicitly, in order to get my server side requests to return validation messages in the user's locale. These requests are created to perform some DataSource.OP_ADD operations, and the localized messages are important so that I can tell the user what failed in the process, in case of errors.

    This is what I am trying to use, since I didn't find a setActionUrl method, but with no success:

    Code:
    DSRequest.setAttribute("actionUrl", "http://localhost:8081/MyApp/myapp/sc/IDACall?locale=es");
    I already verified that the URL is correct client side, but when I open the Developer Console, my server requests are not being sent to this url, so the problem is that clearly this is not the way to set the url for the requests.

    Is this the right approach to try and localize the messages from my server side DSRequests?

    By the way, I am using 6.0p 2016-04-12.

    Thanks
    Last edited by carlossierra; 6 May 2016, 15:28.

    #2
    Hi carlossierra,

    are you talking about clientless requests (started by a servlet) or some additional requests inside a DMI that gets called by user interaction.
    If the latter, just giving using the original RPCManager (dsRequest.getRPCManager()) in the new DSRequest's constructor should be enough.
    This will use the same locale detection mechanisms like the one for GWT permutation selection (http request header accept language).

    Best regards
    Blama

    Comment


      #3
      Blama DSRequests started by a servlet. Any ideas for that? Thanks!

      Comment


        #4
        Yes. Will come back to you on Monday.
        Or look at my threads from the last 2 months and Isomorphic's answers. It's there with "use xyz once". Sth like ServletRequest.getInstance(), from the SmartGWT classes.

        Comment


          #5
          Hi carlossierra,

          please see this thread, where DSRequest.setRequestContext() is explained a bit.
          See this thread for Servlet + DMI validation with l10n, which works in releases newer than March, 24th (see post #4 from Isomorphic).

          My servlet code looks like this:

          Very top of doGet()/doPost() (only once, see here):
          Code:
          RequestContext receiveMailRequestContext = RequestContext.instance(this, servletRequest, servletResponse);
          Use this will all child requests like this:
          Code:
          dsRequest.setRequestContext(requestContext);
          As I have code used by client contact that always has a RPCManager and Servlet, I have these helper methods making the existing DMI working in both cases:
          Code:
          public static void prepareRequest(DSRequest dsRequest, RPCManager rpcManager, DSTransaction dsTransaction, Long userID,
                      RequestContext requestContext) throws Exception {
                  if (rpcManager != null) {
                      dsRequest.setRPCManager(rpcManager);
                  } else {
                      prepareRequest(dsRequest, requestContext);
                      if (dsTransaction != null) {
                          dsRequest.setDSTransaction(dsTransaction);
                          if (userID != null && dsTransaction.getUserId() == null) {
                              dsTransaction.setUserId(userID.toString());
                              dsTransaction.setClientRequest(false);
                          }
                      } else if (dsTransaction == null) {
                          if (userID != null) {
                              dsRequest.setUserId(userID.toString());
                              dsRequest.setClientRequest(false);
                          }
                      }
                  }
              }
          
              public static void prepareRequest(DSRequest dsRequest, DSTransaction dsTransaction, Long userID, RequestContext requestContext)
                      throws Exception {
                  prepareRequest(dsRequest, null, dsTransaction, userID, requestContext);
              }
          
              public static void prepareRequest(DSRequest dsRequest, Long userID, RequestContext requestContext) throws Exception {
                  prepareRequest(dsRequest, null, null, userID, requestContext);
              }
          
              public static void prepareRequest(DSRequest dsRequest, RPCManager rpcManager) throws Exception {
                  prepareRequest(dsRequest, rpcManager, null, null, null);
              }
          
              public static void prepareRequest(DSRequest dsRequest, RPCManager rpcManager, DSTransaction dsTransaction) throws Exception {
                  prepareRequest(dsRequest, rpcManager, dsTransaction, null, null);
              }
          
              public static void prepareRequest(DSRequest dsRequest, RPCManager rpcManager, DSTransaction dsTransaction, RequestContext requestContext)
                      throws Exception {
                  prepareRequest(dsRequest, rpcManager, dsTransaction, null, requestContext);
              }
          
              public static void prepareRequest(DSRequest dsRequest, DSRequest parentDSRequest) throws Exception {
                  prepareRequest(dsRequest, parentDSRequest.getRPCManager(), parentDSRequest.getDsTransaction(),
                          Long.getLong(parentDSRequest.getUserId()), parentDSRequest.getRequestContext());
              }
          
              public static void prepareRequest(DSRequest dsRequest, RequestContext requestContext) {
                  dsRequest.setRequestContext(requestContext);
              }
          My servlet is hit by a cron job wget, not by "the real user", so I have to fake the request from being from the user, which might not be true in your case.
          For me, I have to fake the language for the user I'm sending a mail to in my case using a language value I safe in the DB for every user.

          Assuming you servlet is hit by the user, handing down the RequestContext should be enough.

          Best regards
          Blama

          Comment


            #6
            Blama, sorry for not getting back to you before (it was a holiday weekend here in Colombia). I confirm that your suggested approach is just what I was needing. Thanks for helping me out!!

            Comment


              #7
              Hi carlossierra,

              that's great to hear.

              Best regards
              Blama

              Comment

              Working...
              X