JAXB 布尔处理异常和 JSF

发布于 2024-09-04 22:28:08 字数 1186 浏览 3 评论 0原文

JAXB 中存在一个已知错误:https://jaxb.dev。 java.net/issues/show_bug.cgi?id=733

JAXB 无法正确生成布尔字段 getter 和 setter,此错误未修复以实现向后兼容性。

存在 JAXB 插件,它将确保生成以下布尔字段的 getter 和 setter:

  1. 生成 setXXX(Boolean value)
  2. getXXX()
    • 如果布尔属性在 XSD 中指定默认值,则 getXXX() 返回布尔值
    • 如果布尔属性未在 XSD 中指定默认值,则 getXXX() 返回 Boolean

问题:尝试编辑/查看 JSF 组件(例如复选框)中的 XXX 字段不起作用 - 该组件被禁用。

我使用 Apache Trinidad 1.2。该组件的编码如下:

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

我没有深入追踪这一点,但假设(由下面的解决方法支持)是 JSF EL 解析器(或 Whathaveyou)查找 Boolean getXXX() 方法,因为它没有找到它,该组件被禁用。

解决方法:如果我将 getXXX() 方法更改为返回布尔值,则一切正常。

问题

  • 对于如何以最快的方式集体解决这个问题,您有什么想法?
    • 我是否错过了 boolean-getter JAXB 插件的一些自定义?
  • 是否有可能(是否有意义)更改 JSF 解析器(或whathaveyou),以便如果未找到 Boolean getXXX(),它将回退到 boolean getXXX()?

我不想手动干预并更改所有生成的 getXXX() 方法以返回布尔值而不是布尔值。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

娇女薄笑 2024-09-11 22:28:08

问题:尝试编辑/查看 JSF 组件(例如复选框)中的 XXX 字段不起作用 - 该组件已被禁用。


I我已经使用 JSF 多年了,但我从未在 JSF 中看到过这个特殊问题。从技术上讲,组件也不可能根据其值的类型而被禁用。当找不到属性或值类型不可转换时,它宁愿抛出 PropertyNotFoundExceptionConverterException

我使用 和以下 getter 进行了快速测试:

  • public boolean isChecked() 有效美好的。
  • public boolean getChecked() 工作正常。
  • public Boolean isChecked() 在渲染期间抛出 PropertyNotFoundException(正确)。
  • public Boolean getChecked() 工作正常。

根据这些信息,我将重新调查问题并审查结论。您是否使用了一些不是您自己编写的自动生成的或第 3 方 JSF 代码?您仔细检查过 JSF 代码吗?不就是在某些 disabled 属性中使用这个属性吗? Boolean 的默认值为 null,而 boolean 默认为 falsenullfalse 在 EL 中的行为不同。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文