google-apps-scriptweb-applicationsuiapp

Discovering information at runtime


Since the GAS documentation actually sucks, I thought I might try to at least discover information about the parameters that are passed to even handlers. This trivial example shows what am I trying to do.

MyGui is built using the Gui-builder.
It contains a button - btn, which has a click callback - btn_click It also contains a TextArea - txtArea1

simples

function doGet() {
  var app = UiApp.createApplication();
  app.add(app.loadComponent("MyGui"));
  return app;
}

function btn_click(e) {

  var app = UiApp.getActiveApplication();
  var ta = app.getElementById('txtArea1');

  if(!e)
  {
    ta.setText('null object');
  }
  else
  {
    ta.setText(e.toDebugString());
  }

  return app;
}

Silly me ! I assumed that since the documentation repeated states that the GAS components are built upon GWT, and GWT being Java based, EVERYTHING is a java.lang.Object, that I should be able to call toDebugString() to find at least some information about the object passed into the handler function.

Sorry, I am very close to giving up on using GAS, it's just a toy right now, and I don't have time to play, I actually have work to do.


Solution

  • The client side of UiApp is GWT widgets. Nowhere have we stated that the server side is made up of GWT Java objects (it isn't), nor would that even make sense based on how they are documented to work. The server objects are no more than references to the client objects - references that you can use to associate commands with, which then get shipped down to the client. There is no debug information to be had, because the server "widgets" have no information other than the id of the client widget they are storing up commands for.