GlassFish + JSF + PrimeFaces + push
Bonjour,
je suis novice dans le domaine et je suis en train de tester le push au sein d'une interface web JSF.
cependant je suis confronté a un problème que je n'arrive pas a comprendre.
J'imagine que j'ai du rater quelque chose mais je ne vois pas quoi.
Pour faire le test, j'ai mis un bouton qui va déclencher le push pour rafraichir un tableau qui contient des valeurs.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
@ManagedBean(name = "myctrl")
@RequestScoped
public class MyController {
private static ArrayList<Value> myLst = new ArrayList<>();
static {
for (int i = 0; i < 2; i++) {
myLst.add(new Value(i));
}
}
public List<Value> getMyLst() {
System.out.println("recup lst : " + new Date(System.currentTimeMillis()));
Random rand = new Random();
int num = rand.nextInt(100);
myLst.add(new Value(num));
return myLst;
}
public void setMyLst(ArrayList<Value> lst) {
this.myLst = lst;
}
public String launchPush() {
System.out.println("lancement du push : " + new Date(System.currentTimeMillis()));
PushContext pushContext = PushContextFactory.getDefault()
.getPushContext();
pushContext.push("/majStr", "update");
return null;
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
public class Value {
private int id;
private String val;
public Value() {
}
public Value(int num) {
id = num;
val = "val" + num;
}
public int getId() {
return this.id;
}
public void setId(int id) {
this.id = id;
}
public String getVal() {
return this.val;
}
public void setVal(String val) {
this.val = val;
}
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
Test pour le push
</h:head>
<h:body>
<h:form>
<h:commandButton value="Test action push"
action="#{myctrl.launchPush}" />
</h:form>
<hr />
<h:form id="Strform">
<p:dataTable id="strDataTable" value="#{myctrl.myLst}" var="my">
<p:column headerText="Id">
<h:outputText value="#{my.id}" />
</p:column>
<p:column headerText="Value">
<h:outputText value="#{my.val}" />
</p:column>
</p:dataTable>
<p:socket onMessage="updateStrTable" channel="/majStr" />
<p:remoteCommand name="updateStrTable" update="strDataTable" />
</h:form>
</h:body>
</html> |
pour une raison que je n'arrive pas a comprendre, lorsque je clique sur le bouton, je me retrouve a avoir deux appels à la méthode "getMyLst()".
Je ne comprend pas quel est mon erreur surtout que l'exemple est tout simple.
Quelqu'un peut il me dire comment je pourrais corriger ce problème ?
Merci d'avance !