i made this calculator program using jsf and a class
i used command buttons to pass and append numbers (like a pocket calculator not first number second number sort of calculator) here is the sample of the code i have a problem with
i want entered values to be appended so for example CLICKING 1 three times gives 111
here the enteredvalue shows as one while the appendedvalue is always the same (1) i have
@ApplicationScoped in the class
<h:inputText value="#{mbcalculator.result}"/>
<h:commandButton value="1" action="#{mbcalculator.setNumber}">
<f:setPropertyActionListener target="#{mbcalculator.enteredvalue}"
value="1" />
//mbcalculator class
public String setNumber() {
appendNumber(enteredvalue);
return null;
}
public void appendNumber(String x) {
StringBuffer buffer = new StringBuffer();
buffer.append(x + "");
String str = buffer.toString();
appendedvalue = Integer.parseInt(str);
result = appendedvalue;
System.out.println("enter"+enteredvalue);
System.out.println("append"+appendedvalue);
System.out.println("result"+result);
}
In the
appendNumber()you’re overriding the wholeresultinstead of appending to it.Fix it accordingly by really appending to the
result.