I want to know how to update a String in my backing bean directly from a Javascript function.
My example tries to call the Javascript function (where the String img will get updated), and then I want to access its new updated content in the save function which is the action event of the button.
This is an extract from the Xhtml file:
<Script>
function jsSave(){
var text=document.getElementById("form:img");
text.value="New text value";
}
</Script>
<p:commandButton value="Change text" onclick="jsSave();" action="#{backbean.save()}"/>
<h:outputText value="#{masterpage_bean.img}" id="img"/>
In the backing bean I have this code:
String img;
public String getImg() {
return img;
}
public void setImg(String img) {
this.img = img;
}
public String save(){
String tex;
tex=img;
// I want to do some stuff with the updated value of img here.
return null;
}