views:

185

answers:

1

There is a known bug in JAXB: https://jaxb.dev.java.net/issues/show_bug.cgi?id=733

JAXB does not properly generate boolean field getters and setters, this bug is left unfixed for backwards compatibility.

A JAXB plugin exists and will ensure that the following getters and setters for boolean fields are generated:

  1. setXXX(Boolean value) is generated
  2. getXXX() is generated
    • If the boolean attribute specifies default value in the XSD, then getXXX() returns boolean,
    • If the boolean attribute does not specify default in the XSD, then getXXX() returns Boolean.

Problem: trying to edit/view the XXX field in a JSF component (such as checkbox) does not work - the component is disabled.

I use Apache Trinidad 1.2. The component is coded as follows:

<tr:selectBooleanCheckbox value="#{MvsDatasetUI.object.mvsDataset.temporary}" id="temporary" converter="javax.faces.Boolean" />

I have not traced this in depth but the assumption (backed by the workaround below) is that JSF EL resolver (or whathaveyou) looks for Boolean getXXX() method and since it does not find it, the component is disabled.

Workaround: If I change the getXXX() method to return Boolean, then everything goes.

Questions:

  • What are your ideas on how to address this problem en-masse in the fastest way possible?
    • Have I missed some customization for the boolean-getter JAXB plugin?
  • Is it possible (does it make sense) to alter JSF resolver (or whathaveyou) so that if Boolean getXXX() is not found, it will fall back to boolean getXXX()?

I would prefer not to manually intervene and change all the generated getXXX() methods to return Boolean instead of boolean.

+1  A: 

Problem: trying to edit/view the XXX field in a JSF component (such as checkbox) does not work - the component is disabled.

I've worked with JSF for ages, but I've never seen this particular issue in JSF. It's technically also impossible that a component get disabled based on the type of its value. It would rather have thrown a PropertyNotFoundException or a ConverterException whenever the property cannot be found or the value type is unconvertible.

I did a quick test with the <h:selectBooleanCheckbox value="#{bean.checked}" /> and the following getters:

  • public boolean isChecked() works fine.
  • public boolean getChecked() works fine.
  • public Boolean isChecked() throws PropertyNotFoundException during render (correct).
  • public Boolean getChecked() works fine.

Based on this information, I'd reinvestigate the problem and review the conclusions. Aren't you using some autogenerated or 3rd party JSF code which you thus haven't written yourself? Have you checked the JSF code closely? Isn't it just using this property in some disabled attribute? The Boolean has default value of null while boolean defaults to false. Both null and false behave differently in EL.

BalusC
Thanks, these are very good (and refreshing :)) points. I will re-investigate. We are using Apache Trinidad.The property is used in a value attribute and use converter: javax.faces.Boolean.Just to have 100% clear picture here - all your quick tests are done with setter: setChecked(Boolean value)?
finrod
Yes, although it in fact doesn't matter since the setter is only of relevance when you *submit* the form.
BalusC
Still didn't get to re-investigate this in depth. I will update this question once I do. Thank you for sharing your expertise.
finrod