I've been stuck on a problem which involves allowing an input field of type Double
to be null or other values.
Since I'm working with automatically generated code, I can't touch the get / set methods for my object. Additionally, I am unable to modify server parameters, such as -Dorg.apache.el.parser.COERCE_TO_ZERO
.
My most recent solution was to make a wrapper object for the auto-generated object, which deals in String
instead of Double
. Here it is:
public class WrapperType {
private AUTO_GENERATED_OBJECT autogen;
public WrapperType(AUTO_GENERATED_OBJECT autogen) {
this.autogen = autogen;
}
public String getOperation() {
if (autogen.getOperation() == null) {
return null;
}
return autogen.getOperation() + "";
}
public void setOperation(String value) {
if (value == null || value.isEmpty()) {
autogen.setOperation(null);
} else {
autogen.setOperation(Double.valueOf(value));
}
}
}
So all I have to do is, instead of calling the get/set on my autogenerated object, call the get/set on an equivilant wrapper, which can be obtained with something like:
public WrapperType convertVar(AUTO_GENERATED_OBJECT autogen) {
return new WrapperType(autogen);
}
And then refer to it where needed:
<p:inputText value="#{bean.convertVar(_var).operation}" />
Except that this doesn't work. I'm recieving an error that:
javax.el.PropertyNotFoundException: /operation/collections/tabs/page.xhtml The class 'MyClass$Proxy$_$$_WeldClientProxy' does not have the property 'convertVar'.
Anyone have any ideas on how to fix this problem, or to overcome my requirement of both null and numeric values?