-
Book Overview & Buying
-
Table Of Contents
PrimeFaces Cookbook
The RequestContext utility class provides an easy way to execute any JavaScript code after the current AJAX request completes. The JavaScript block has to be coded in Java and can be executed by passing it to the execute() method. An alternative approach would be to update a script block on a page and trigger the script execution manually. In this case, the JavaScript block is coded directly into a page.
In this recipe, we will see both solutions for JavaScript execution. For this purpose, we will develop a Menu component and toggle enabling/disabling of menu items with two command buttons. The first command button should toggle enabling/disabling with the server-side approach and the second one with the client-side approach.
Let's write a p:menu tag with three menu items. We also need two p:commandButton tags with appropriate action listeners.
<h:outputText id="indicator" value="Enabled? -#{javaScriptExecController.enabled}"/>...
Change the font size
Change margin width
Change background colour