0

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?

Addison
  • 7,322
  • 2
  • 39
  • 55

1 Answers1

1

Take a look at this. Just use a @WebListener to modify the propery and get nulls intead of zeroes.

coerce to zero

Community
  • 1
  • 1
Julio
  • 46
  • 4
  • Works like a charm. I shouldn't have given up so easily when I saw the COERCE_TO_ZERO solutions. Thanks, Julio. – Addison Sep 09 '15 at 23:32