mardi 4 août 2015

How to assign value to global variable in bean through ajax

I need your help in assigning the entered value in an inputText to a global variable that can be used in multiple methods in a bean. The JSF page has the code:

<p:inputText id="refNo2" value="#{Bean1.refNo}">
    <p:ajax event="keyup" update="ref2" />
</p:inputText>

<h:outputText id="ref2" value="#{Bean1.refNo}"/> 

With the above code anything that is entered in the inputText, it will be shown in the outputText. And the java code for refNo in Bean1 is:

private String refNo = "";

public void setRefNo(String refNo) {
    this.refNo = refNo;
}

public String getRefNo() {
    return refNo;
}

In Bean1, I am calling a method which is called showRef() that has the code:

public void showRef() {
    System.out.println("Reference No. is"+refNo);
}

It is printing the value as blank or empty where the user entered in the inputText the value = 777 and it was shown in the outputText. So how can I get the value of the refNo in the showRef() method?

Aucun commentaire:

Enregistrer un commentaire