My JSF Books/Videos My JSF Tutorials OmniFaces/JSF PPTs
JSF 2.3 Tutorial
JSF Caching Tutorial
JSF Navigation Tutorial
JSF Scopes Tutorial
JSF Page Author Beginner's Guide
OmniFaces 2.3 Tutorial Examples
OmniFaces 2.2 Tutorial Examples
JSF Events Tutorial
OmniFaces Callbacks Usages
JSF State Tutorial
JSF and Design Patterns
JSF 2.3 New Features (2.3-m04)
Introduction to OmniFaces
25+ Reasons to use OmniFaces in JSF
OmniFaces Validators
OmniFaces Converters
JSF Design Patterns
Mastering OmniFaces
Reusable and less-verbose JSF code

My JSF Resources ...

Java EE Guardian
Member of JCG Program
Member MVB DZone
Blog curated on ZEEF
OmniFaces is an utility library for JSF, including PrimeFaces, RichFaces, ICEfaces ...

[OmniFaces Utilities] - Find the right JSF OmniFaces 2 utilities methods/functions

Search on blog

Se încarcă...

Petition by Java EE Guardians

Twitter

miercuri, 2 septembrie 2015

[OmniFaces utilities 2.2] Add given JavaScript code as inline script to end of body of the current view


[OmniFaces utilities] The addScriptToBody() adds the given JavaScript code as inline script to end of body of the current view.
Note: This doesn't have any effect during ajax postbacks. Rather use Ajax#oncomplete(String...).

Method:

Usage:

Whenever you need to programmatically add inline a snippet of JavaScript code in the <body> section, you can use the Components#addScriptToBody() method. For example, let's suppose that we have the following dummy snippet of JavaScript code:

alert('I was added by the Components#addScriptToBody() utility method !')

Further, in an managed bean action method (or other JSF artifact) we can instruct JSF to add the given JavaScript code as inline script to end of body of the current view:

import org.omnifaces.util.Components;
...
String snippetOfJS = "alert('I was added by the Components#addScriptToBody() utility method !')";
UIComponent comp = Components.addScriptToBody(snippetOfJS);

The inline code is added in the page as below (just check the page source code to see the below markup):

<html xmlns ...>
 ...
 <body>
  ...
  <script type="text/javascript">alert('I was added by the Components#addScriptToBody() utility method !')</script>
 </body>
</html>

You may also want to read:

Niciun comentariu :

Trimiteți un comentariu

JSF BOOKS COLLECTION

Postări populare

OmniFaces/JSF Fans

Follow by Email

Visitors Starting 4 September 2015

Locations of Site Visitors