Reputation: 487
My bean isn't firing my setter method and I can't figure out why.
Here's the import part of the xhtml
<script type="text/javascript">
function updateTextInput(val, box) {
//document.getElementById(box).value=val;
}
</script>
Min value: </td><td><input type="range" name="minVal" min="-100" max="200" onchange="updateTextInput(this.value, 'minValInput');"/><h:inputText id="minValInput" value="#{myClass.minVal}"></h:inputText>
<h:form><h:commandButton value="#{myClass.status}" action="welcome">
And here's my bean:
public class MyClass implements Serializable {
private static final long serialVersionUID = 1L;
private String status = "";
private int minVal = 0;
public String getStatus() {
if(status == "") {
status = "Start";
}
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getMinVal() {
System.out.println("*********************" + minVal);
return minVal;
}
public void setMinVal(int minVal) {
System.out.println("*********************" + minVal);
this.minVal = minVal;
}
My command button getter and setter's fire fine, but from my output I can tell minVal's getters are executed twice while the setter is never executed. I'm sure I'm overlooking something simple here but can't quite figure it out. Does anyone see something I overlooked?
Upvotes: 0
Views: 193
Reputation: 1108632
It's because your <h:inputText>
isn't inside a <h:form>
.
Unrelated to the concrete problem, JSF utility library OmniFaces allows you to use <h:inputText type="range">
instead and JSF component library PrimeFaces offers a <p:slider>
to have a range input in jQuery UI look'n'feel. You may find it easier than fiddling around with plain HTML and JS.
Upvotes: 3