webfirmframework for Java Experts

Execute JavaScript From Server

The normal way to execute a JavaScript code is to insert a Script tag class containing JavaScript code in the UI. But, in some special cases like server restart, there won't be a BrowserPage object so in such cases it's possible to push ByteBuffer returned by BrowserPageAction.getActionByteBufferForExecuteJS method which can execute the given JavaScript code in the browser.

Eg :- To execute an alert in the browser push the actionByteBuffer to the client directly using the websocket of the corresponding browserPage or using browserPage.performBrowserPageAction method.

ByteBuffer actionByteBuffer = BrowserPageAction.getActionByteBufferForExecuteJS(
					"alert('executed script');");
websocket.session.getBasicRemote().sendBinary(actionByteBuffer);
//alternatively browserPage.performBrowserPageAction(actionByteBuffer);