Topic
  • No replies
SystemAdmin
SystemAdmin
1569 Posts

Pinned topic Problem in triggering ajax call using JSF 1.1 on Websphere portal 6.1

‏2012-07-30T17:38:35Z |
Hi All,
I am trying to generate random numbers continuously while the page loads. This is a Proof of concept that i am trying to achieve before getting started to work on a business requirement. I have an output text which displays the generated random numbers by calling the backing bean. What the behaviour i am expecting is, I want the backing bean's getRandomNumberInt() to be called continuously so that i see the random numbers getting changed on the page.

Any help would be appreciated. Below is the code snippet.

AjaxPage.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd">

<hx:scriptCollector id="scriptCollector1">
<h:form styleClass="form" id="form1">

<h:panelGroup styleClass="panelGroup" id="randomNumberGroup">
<h:outputText styleClass="outputText" id="randomNumber"
value="#{pc_AjaxEnabledPOCView.randomNumberInt}"></h:outputText>
</h:panelGroup>
<hx:ajaxRefreshRequest target="randomNumberGroup"
id="ajaxRefreshRequest1">
</hx:ajaxRefreshRequest>

<h:outputLink id="outPutLinkMoreRandomNumber">
<h:outputText id="randomNumberOutputTextId"
value="Fetch more Random Number">
</h:outputText>
<hx:behavior event="onload" id="behavior1" behaviorAction="get"
targetAction="randomNumberGroup"></hx:behavior>
</h:outputLink>

</h:form>
</hx:scriptCollector>

AjaxEnabledPOCView.java - Backing bean

public class AjaxEnabledPOCView extends PageCodeBase {
private double randomNumberInt = 0;

public double getRandomNumberInt() {
randomNumberInt = randomNumberInt + Math.random();
System.err.println("Random Number: -" + randomNumberInt);
return randomNumberInt++;
}

public void setRandomNumberInt(double randomNumberInt) {
this.randomNumberInt = randomNumberInt;
}

}