Wednesday, October 30, 2013

Body onload with PrimeFaces autoRun

To perform an action during page load, the normal practice is to invoke a javascript with the onload attribute in HTML body.

function load() {
alert("Page is loaded");
<body onload="load()">
<h1>Hello World!</h1>

With PrimeFaces <p:remoteCommand /> component, backingBean action could be called directly during page load.
by turning on the autoRun attribute to true only.
<p:remoteCommand name="testAutoRun"
    autoRun="true" />

The benefits with <p:remoteCommand /> are:
1. easy to use
2. No hassles to write any javascript
3. other pages are not affected (if facelets template is used)



Related Posts Plugin for WordPress, Blogger...