来自未呈现组件的 JSF 验证错误

发布于 2024-12-21 12:44:55 字数 1749 浏览 4 评论 0原文

我有一个表单,其中有一个字段需要在编辑模式下呈现为只读值,在创建模式下呈现为下拉选择列表。

使用 将只读字段(在编辑模式下使用)呈现为纯文本。在创建模式下,该字段将呈现 ,其必需属性为“true”。

它似乎在大多数情况下都按我的预期工作,但有时在编辑模式下会出现验证错误(选择列表框未呈现)。

下面的代码片段使用相同的布尔值(只有一个字段否定要切换的布尔值)定义了两个字段,并设置了它们的渲染属性。

<h:outputLabel id="lblBusinessArea" value="Business Area:" />
<h:panelGroup id="baGroup">
    <h:selectOneListbox id="businessAreaList" size="1"
            rendered="#{shiftDetailsController.canEditBusinessArea}" 
            converter="businessAreaConverter"
            value="#{shiftDetailsController.selectedBusinessArea}"
            label="Business Area"
            required="true">
        <f:selectItems id="businessAreaListItems" value="#{shiftDetailsController.businessAreas}" />
        <a4j:support id="businessAreaA4j" event="onchange"
            ajaxSingle="true" reRender="deploymentGroupList, positionPayGroupList, sapPremCodeList" />
    </h:selectOneListbox>
    <h:outputText id="businessAreaRO" 
         rendered="#{!shiftDetailsController.canEditBusinessArea}" 
         value="#{shiftDetailsController.selectedBusinessArea.busAreaDesc}" />
</h:panelGroup>

下面是一个屏幕剪辑,显示了呈现为只读的字段(在编辑模式下)。单击“保存”按钮后,我收到一条验证错误消息,表明该字段是必填字段。

  1. 该值应该位于支持 bean 中,因为显示的值来自同一对象 (shiftDetailsController.selectedBusinessArea)。输出文本使用业务领域对象上的描述字段,选择字段使用 SelectItem 的标签中具有描述的整个对象。

字段呈现为只读,并显示验证消息

知道这是如何发生的吗?我可以使用确定渲染状态的相同布尔值来设置必需的属性...这样只有在渲染时才需要它...但是由于这个问题是间歇性的...我不知道这真的有帮助。

我还验证了页面上没有其他组件无意中具有“业务区域”标签值(在验证消息中使用)来误导我哪个组件真正具有空值;这是唯一一个带有“商业区”标签的区域。

I have a form that has a field that needs to be rendered as a read-only value when in edit mode and as a drop-down select list when in create mode.

The read-only field (used in edit mode) is rendered as plain text using <h:outputText>. In create mode, the field is rendered <h:selectOneListbox> that has a required attribute of "true".

It seems to work as I expect most of the time, but occasionally I get a validation error when in edit mode (the select list box is not rendered) .

Here is the code snippet that has both fields defined with their rendered attributes set using the same boolean value (just one field negates the boolean to toggle).

<h:outputLabel id="lblBusinessArea" value="Business Area:" />
<h:panelGroup id="baGroup">
    <h:selectOneListbox id="businessAreaList" size="1"
            rendered="#{shiftDetailsController.canEditBusinessArea}" 
            converter="businessAreaConverter"
            value="#{shiftDetailsController.selectedBusinessArea}"
            label="Business Area"
            required="true">
        <f:selectItems id="businessAreaListItems" value="#{shiftDetailsController.businessAreas}" />
        <a4j:support id="businessAreaA4j" event="onchange"
            ajaxSingle="true" reRender="deploymentGroupList, positionPayGroupList, sapPremCodeList" />
    </h:selectOneListbox>
    <h:outputText id="businessAreaRO" 
         rendered="#{!shiftDetailsController.canEditBusinessArea}" 
         value="#{shiftDetailsController.selectedBusinessArea.busAreaDesc}" />
</h:panelGroup>

Below is a screen clipping showing the field (in edit mode) rendered as read only. The "save" button was clicked and I get a validation error message that the field is required.

  1. The value should be there in the backing bean because the value displayed is from the same object (shiftDetailsController.selectedBusinessArea). The output text uses the description field on the business area ojbect and the select field uses the whole object where the SelectItem has the description in the label.

field rendered as read-only with validation message appearing

Any idea how this could be occurring? I could set the required attribute using the same boolean value that determines the rendered state...so that it is only required when it is rendered...but since this problem is intermittent...I don't know that will really help.

I also verified that no other components on the page inadvertently have a label value of "Business Area" (which is being used in the validation message) to mislead me in which component truly has a null value; this is the only one that has the label of "Business Area".

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

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

发布评论

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

评论(1

捂风挽笑 2024-12-28 12:44:55

我弄清楚这个问题发生了什么。

在提交表单并收到验证错误之前。我所做的更改导致控制两个组件可见性的标志被反转。

rendered="#{shiftDetailsController.canEditBusinessArea}"

换句话说,我在表单上所做的操作导致 canEditBusinessArea 更改值。但是,我没有重新渲染面板组(“baGroup”)以使 UI 反映更新。

因此,当我的表单提交时,验证阶段的组件被视为必需的......触发验证的发生。一旦我将“baGroup”添加到翻转编辑业务区域标志的操作的重新渲染中,UI 就开始反映更新,并且提交的表单具有值。

I figured out what was happening with this issue.

Prior to submitting the form and receiving the validation error. I was making a change that caused the flag controlling the two components' visibility to be reversed.

rendered="#{shiftDetailsController.canEditBusinessArea}"

In other words, what I was doing on the form was causing the canEditBusinessArea to change values. But, I was not re-rendering the panel group ("baGroup") to cause the UI to reflect the update.

Thus, when my form was submitted the component during the validation phase was seen as being required...triggering the validation to happen. As soon as I added "baGroup" to the reRender of the action that was flipping the edit business area flag, the UI began reflecting the update and the submitted form had the value.

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