So I get a Validation Error: Value is not valid
when submitting my form.
My enum looks like this:
public enum Version {
none, v1_3("1.3"), v1_4("1.4");
private BigDecimal version;
Version(String vers) {
version = new BigDecimal(vers);
}
Version() {
}
public String toString() {
if(version == null){
return " ";
}
else{
return version.toPlainString();
}
}
...
When I try to submit the following form I get the mentioned error:
<h:form>
<p>
<h:outputText value="Test Version: " />
<h:selectOneMenu binding="#{inputVersionTest}">
<f:selectItems value="#{myBean.getVersionValues()}" />
</h:selectOneMenu>
</p>
<h:commandButton value="Test" type="submit" action="#{myBean.test(inputVersionTest.value)}" />
</h:form>
I played around with my toString() method in my Enum and when I return "none" (just like the enum value naming) if the version attribute is null, the JSF form is actually working. The problem is that the values in my dropdown menu do not mach the enum values.
The values for the drop down menu is created by this method in myBean:
public Version[] getVersionValues(){
return Version.values();
}
The toString() method converts those values to " ", 1.3 and 1.4. But what I would need to make it work (it seems) is none, v1_3 and v1_4. I also tried to create my own equals method in Version.java, but it didn't work. (equals(String) and equals(Version)).