Getting Started With Project jMaki for the GlassFish v3 Application Server

ProcedureAccessing an External Service from a Widget

  1. Expand the plotCity > Web Pages node.

  2. Open index.jsp in the editor pane.

  3. Add a publish attribute to the thisCity combobox widget and set it to /cities:

    <a:widget id="thisCity"
    	name="dojo.combobox"
    	publish="/cities"
    	subscribe="/cb"
    	value="${StateBean.cities}" />
  4. Expand the plotCity > Web Pages node.

  5. Open glue.js in a source editor.

  6. Add the following handler to the end of glue.js:

    jmaki.subscribe("/cities/onSelect", function(item) {
    	var city = item.value;
    	var state = jmaki.attributes.get('thisState').getValue();
    	var location = city + ", " + state;
    	var encodedLocation = encodeURIComponent("location=" + location);
    	var url = jmaki.xhp + 
    		"?id=yahoogeocoder&urlparams=" + 	
    		encodedLocation;
    	jmaki.doAjax({url: url, callback : function(req) {
    		if (req.responseText.length > 0) {
    			// convert the response to an object
    			var response = eval("(" + req.responseText + ")");
    			var coordinates = response.coordinates;
    			v = {results:coordinates};
    			jmaki.publish("/jmaki/plotmap", coordinates);
    		} else {
    			jmaki.log("Failed to get coordinates for " + 
    				location );
    		}
    	}
    });
    });
  7. Save glue.js.