a4j 重新渲染后表单值未传递给 Seam bean

发布于 2024-09-01 14:12:57 字数 2664 浏览 4 评论 0原文

我正在 Seam 中制作一个网络应用程序,但遇到了一个我似乎无法解决的问题。

我有一个 JSF 表单,客户可以通过组合框选择预订类型。根据所选值,呈现其他表单组件。

例如:客户选择“小时”作为预订类型,将呈现一个 panelGroup,客户可以在其中选择开始和结束时间。但是,如果客户选择“一天中的一部分”作为预订类型,则会呈现一个 selectOneMenu,客户可以在其中选择一天中的一部分(早上、下午、晚上)。重新

渲染效果很好,但具有渲染条件的组件的值不会传递给 bean。它们保持空值。

这是我正在讨论的代码:

<s:div id="spot"
       rendered="#{selectedProduct.productType.name eq 'Flex Spot'}">

    <h:panelGrid columns="2">
        <h:outputText value="Reservation Type" />
        <h:selectOneMenu value="#{selectedPeriodPart}">
            <s:selectItems
                value="#{productManager.getAvailableDayPartsSpot()}"
                var="daypart"
                label="#{daypart.label}"></s:selectItems>
            <s:convertEnum />

            <a4j:support ajaxSingle="true"
                         event="onchange"
                         action="#"
                         reRender="spot">
            </a4j:support>
        </h:selectOneMenu>

        <h:outputText id="date_spot" value="Date" />

        <a4j:outputPanel id="calendar_spot" layout="block">
            <rich:calendar value="#{reservation.reservationPeriod.startDate}"
                           locale="en" cellWidth="24px"
                           cellHeight="22px"
                           style="width:200px" />
        </a4j:outputPanel>

        <h:outputText rendered="#{selectedPeriodPart eq 'DAY_PART'}"
                      value="Daypart" />

        <h:selectOneMenu value="#{selectedDaypart}"
                         rendered="#{selectedPeriodPart eq 'DAY_PART'}">
            <f:selectItem id="si_morning" itemLabel="Morning (6:00 - 12:00)"
                          itemValue="morning" />
            <f:selectItem id="si_afternoon"
                          itemLabel="Afternoon (12:00 - 18:00)" itemValue="afternoon" />
            <f:selectItem id="si_evening" itemLabel="Evening (18:00 - 00:00)"
                          itemValue="evening" />
        </h:selectOneMenu>

        <h:outputText rendered="#{selectedPeriodPart eq 'HOURS'}"
                      value="Hours" />

        <h:panelGroup id="hours_spot"
                      rendered="#{selectedPeriodPart eq 'HOURS'}">
            <ui:include src="/includes/reservation/select_hours.xhtml" />
        </h:panelGroup>
    </h:panelGrid>
</s:div>

注意:日历值确实会传递回 bean,但这段代码的值不会(如果您删除呈现的条件,它会传递):

selectOneMenu value="#{selectedDaypart}" rendered="#{selectedPeriodPart eq 'DAY_PART'}"

I'm making a webapp in Seam but ran into a problem I can't seem to fix.

I have a JSF form where the customer can select a reservation type through a combobox. Based on the selected value, other form components gets rendered.

For example: the customer selects Hours as reservation type, a panelGroup gets rendered where the customer can select a start- and an end hour. But if the customer would select 'part of the day' as reservation type, a selectOneMenu gets rendered where the customer can select a part of the day (morning, afternoon, evening)

The rerendering well but the values of the components with a rendered conditional won't get passed to the bean. They stay null values.

This is the code i'm talking about:

<s:div id="spot"
       rendered="#{selectedProduct.productType.name eq 'Flex Spot'}">

    <h:panelGrid columns="2">
        <h:outputText value="Reservation Type" />
        <h:selectOneMenu value="#{selectedPeriodPart}">
            <s:selectItems
                value="#{productManager.getAvailableDayPartsSpot()}"
                var="daypart"
                label="#{daypart.label}"></s:selectItems>
            <s:convertEnum />

            <a4j:support ajaxSingle="true"
                         event="onchange"
                         action="#"
                         reRender="spot">
            </a4j:support>
        </h:selectOneMenu>

        <h:outputText id="date_spot" value="Date" />

        <a4j:outputPanel id="calendar_spot" layout="block">
            <rich:calendar value="#{reservation.reservationPeriod.startDate}"
                           locale="en" cellWidth="24px"
                           cellHeight="22px"
                           style="width:200px" />
        </a4j:outputPanel>

        <h:outputText rendered="#{selectedPeriodPart eq 'DAY_PART'}"
                      value="Daypart" />

        <h:selectOneMenu value="#{selectedDaypart}"
                         rendered="#{selectedPeriodPart eq 'DAY_PART'}">
            <f:selectItem id="si_morning" itemLabel="Morning (6:00 - 12:00)"
                          itemValue="morning" />
            <f:selectItem id="si_afternoon"
                          itemLabel="Afternoon (12:00 - 18:00)" itemValue="afternoon" />
            <f:selectItem id="si_evening" itemLabel="Evening (18:00 - 00:00)"
                          itemValue="evening" />
        </h:selectOneMenu>

        <h:outputText rendered="#{selectedPeriodPart eq 'HOURS'}"
                      value="Hours" />

        <h:panelGroup id="hours_spot"
                      rendered="#{selectedPeriodPart eq 'HOURS'}">
            <ui:include src="/includes/reservation/select_hours.xhtml" />
        </h:panelGroup>
    </h:panelGrid>
</s:div>

Note: The calendar value do get passed back to the bean but the value of this piece of code doesn't (it does if you remove the rendered conditional):

selectOneMenu value="#{selectedDaypart}" rendered="#{selectedPeriodPart eq 'DAY_PART'}"

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

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

发布评论

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

评论(2

囍笑 2024-09-08 14:12:57

您需要确保负责 rendered 属性结果的条件在表单提交的后续请求中也相同。因为当组件未呈现时,JSF 将不会应用请求值。

简而言之,#{selectedPeriodPart} 后面的属性需要在后续请求中保持相同。有几种解决方案:

  1. 将 bean 放入会话范围内。最简单的解决方案,但对服务器内存和客户端体验不利(更新将反映在同一会话中的多个选项卡/窗口中)。

  2. 使用传递它。但不确定这如何适合 Ajax/Richfaces 图片。最好在这里使用

  3. 使用对话范围。 Seam 提供了这方面的设施。

You need to ensure that the conditionals responsible for the outcome of the rendered attribute are also the same in the subsequent request of the form submit. Because when a component isn't rendered, JSF won't apply the request values them.

In a nutshell, the property behind #{selectedPeriodPart} needs to be the same in the subsequent request. There are several solutions:

  1. Put bean in session scope. Easiest solution, but bad for server memory and client experience (updates would be reflected in multiple tabs/windows in same session).

  2. Pass it through using <h:inputHidden>. Not sure though how this fits in the Ajax/Richfaces picture. Better use <a4j:keepAlive> here.

  3. Use a conversation scope. Seam offers facilities for this.

夏了南城 2024-09-08 14:12:57

我修复了它 -.- 我发布的代码没有任何问题。
因为我无法解决这个问题,所以我继续在同一对话的其他页面上。我注意到一些更奇怪的行为:变量的喷射不起作用等。

我认为错误出现在代码的其他部分,在更正后,解决了整个问题。

谢谢各位的回答!

I fixed it -.- Nothing was wrong with the code I posted.
Because I wasn't able to solve this issue I continued on an other page in the same conversation. I noticed some more strange behaviour: outjection of a variable didn't work etc.

I figured the mistake was in some other part of the code which, after corrected, fixed the whole problem.

Thx for answering guys!

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