【问题标题】:Why does my form isn't reseting his styling after render?为什么我的表单在渲染后没有重置他的样式?
【发布时间】:2020-01-03 03:02:17
【问题描述】:

我有一个带有树形按钮的表单。其中一个是返回上一页的“取消”按钮。

问题是存在任何验证问题,例如未提交必填字段,当我返回表单时未重置字段的样式。

这是xhtml的简化结构:

   <panel id="horizontal">
        <form id="filterVipLoungeForm">
        </form>
        <form id="frmAddPax">
            <form id="frmAccessType">
            </form>
        </form>
        <panelGrid>
            <commandButton value="agregar" />
            <commandButton value="limpiar" />
            <commandButton value="cancelar" />
        </panelGrid>
    </panel>

调用添加乘客表单的按钮代码:

<p:commandButton
    value="#{label['manageVipLoungeEntrance.button.addPassenger']}"
    action="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 1)}"
    actionListener="#{manageVipLoungeEntranceExtMB.hideMainForm}"
    update=":filterVipLoungeForm :horizontal">
</p:commandButton>

取消按钮的代码:

<p:commandButton
    value="#{label['manageVipLoungeEntrance.button.cancel']}"
    onclick="showLocalDate()"
    action="#{manageVipLoungeEntranceExtMB.setRenderStatus(0, 1)}"
    actionListener="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 0)}"
    update=":filterVipLoungeForm :horizontal">
</p:commandButton>

这会从支持 bean 调用 setRenderStatus 中调用一个方法,该方法设置表单和要在渲染属性中评估的渲染状态。

在这个过程中取消按钮的表单的渲染状态设置为false,前一个表单的渲染状态设置为true。

hideMainForm方法调用两次setRenderStatus方法,设置主窗体渲染状态为false,添加乘客渲染状态为true。

问题存在任何验证错误,如果我返回上一页并返回表单,我仍然会收到验证错误。

[编辑]

对不起,我忘记添加本文中包含的两种形式的渲染评估代码:

表单“frmAddPax”的渲染状态验证

<h:form id="frmAddPax" rendered="#{manageMB.renderStatus.isRenderFormAddPax()}">

表单“filterVipLoungeForm”的渲染状态验证

<h:form id="filterVipLoungeForm" style="width:95% !important;"
rendered="#{manageMB.renderStatus.isRenderFormMain()}"
onkeypress="return event.keyCode != 13">

我尝试过使用&lt;p:resetInput&gt;,但它不起作用,我期待带有 id frmAddPax 的表单重置他的状态,但它不起作用:

<p:commandButton
    value="#{label['manageVipLoungeEntrance.button.cancel']}"
    onclick="showLocalDate()"
    action="#{manageVipLoungeEntranceExtMB.setRenderStatus(0, 1)}"
    actionListener="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 0)}"
    update=":filterVipLoungeForm :horizontal">
    <p:resetInput target=":frmAddPax" />
</p:commandButton>

【问题讨论】:

标签: primefaces jsf-2


【解决方案1】:

我使用了&lt;p:ajax resetValues="true"&gt;,这个可以满足我的需要。 我真的不知道为什么使用 ajax 而不是 resetInput。

<p:commandButton
    value="#{label['manageVipLoungeEntrance.button.cancel']}"
    onclick="showLocalDate()"
    action="#{manageVipLoungeEntranceExtMB.setRenderStatus(0, 1)}"
    actionListener="#{manageVipLoungeEntranceExtMB.setRenderStatus(3, 0)}"
    update=":filterVipLoungeForm :horizontal">
    <p:ajax update=":frmAddPax" resetValues="true" />
</p:commandButton>

【讨论】:

    猜你喜欢
    • 2014-08-20
    • 2020-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    相关资源
    最近更新 更多