Saturday, April 14, 2007

Javascript with FreeMarker & WebWork


window.parent.lastAction = "${request.requestURI}";

FreeMarker's interpolation ${expression} works inside Javascript too. Through it, WebWork's action context, value stack are accessible in Javascript and is useful in some cases. Note that the expression needs to be quoted.

Another example is:

<@ww.text id="LoadingText" name="common.message.flow.loading"/>

in script:

var messageDialog = dojo.widget.byId ('messageDialog');
messageDialog.domNode.innerHTML ="${LoadingText}"

In this way, the internalizationed text is passed to Javascript since the text is saved in the action context with the specified id attribute. [The objects in webwork are stored in five scopes: default (action context), session, application, request. Action context is a ThreadLocal storage available only during action execution.]

-- 山光悦鸟性, 潭影空人心。

No comments: