This is my UI code in JSF. The app is a small currency conversion from Singaporean dollar to Japanese Yen.
<h:form>
<h:inputText id="conversion" value="#{conversor.sgd}"></h:inputText>
<h:commandButton value = "Convertir a yen">
<f:ajax execute = "@all" render = "conversion_lista" event="click"/>
</h:commandButton>
<h2><h:outputText id = "conversion_lista" value = "Conversion: #{conversor.jpy}"/></h2>
</h:form>
And this is my backing bean:
@Named("conversor")
@Dependent
public class Conversor {
private int sgd;
public Conversor() {
sgd = 1; //initial value
}
public int getSgd(){
return sgd;
}
public void setSgd(int sgd){
this.sgd = sgd;
}
public int getJpy(){
return sgd * 2; //fake
}
}
I want to click on the commandButton, execute the first inputText, make the sgd
property in the backing bean change, then render the outputText by previously calculating the converstion from Singaporean dollar to Japanese yen.
However the input isn't passed to the backing bean.
I did try some things like, making getJpy()
return a random number everytime it's called, and it did render a random number everytime I clicked the button. So that means that call works. But I can't pass the text input (sgd/singaporean dollar) to the backing bean and make the right conversion.
What's going on in here?