【问题标题】:Primefaces why invoke setXXXX method when closing the DialogPrimefaces 为什么在关闭对话框时调用 setXXXX 方法
【发布时间】:2013-01-30 21:53:31
【问题描述】:

关闭对话框时为什么调用 setDataTransferRangeInSeconds() 方法?通常关闭对话框时我可能没有被调用?

    <h:form>
        <p:dialog header="Service Alarm Options" 
                widgetVar="updatedlg"
                closable="true" 
                minWidth="500"
                 minHeight="1000"
                resizable="false"
                dynamic="false" 
                >
            <h:panelGrid id="servicedetails">
                <p:commandButton value="Save"
                    action="#{alarmBean.updateServiceOptions}" />
                <p:commandButton value="#{messages.exit}" icon="ui-icon-close"
                    style="valign:bottom;float:right;padding-right:20px"
                    oncomplete="updatedlg.hide();">
                </p:commandButton>
                <p:inputText
                    value="#{alarmBean.selectedDocument.dataTransferRangeInSeconds}"></p:inputText>
            </h:panelGrid>

        </p:dialog>
    </h:form>

已更新。

    <p:dialog header="Service Alarm Options" widgetVar="updatedlg"
        closable="true" minWidth="500" minHeight="1000" resizable="false"
        dynamic="false">
        <h:form>
            <h:panelGrid id="servicedetails">
                <p:commandButton value="Save"
                    action="#{alarmBean.selectedDocument.saveNewFeatures}" />
                <p:commandButton value="#{messages.exit}" icon="ui-icon-close"
                    style="valign:bottom;float:right;padding-right:20px"
                    onclick="updatedlg.hide();" type="button" />
                <p:inputText
                    value="#{alarmBean.selectedDocument.dataTransferRangeInSeconds}"></p:inputText>
            </h:panelGrid>
        </h:form>
    </p:dialog>

【问题讨论】:

  • 点击按钮时会调用updateServiceOptions()方法吗?

标签: forms jsf-2 dialog primefaces


【解决方案1】:

通常不会,但将对话框放在表单中是不正确的。重新排序您的代码并让您的表单位于对话框中:

<p:dialog>
  <h:form>
      <!-- your form -->
  </h:form>
</p:dialog>

您的退出按钮也是 AJAX 按钮(Primefaces 中的默认设置),它发送 AJAX 请求并在该请求之后隐藏对话框。在该请求期间,来自输入的请求值被发送并在 bean 中设置。将按钮更改为:

<p:commandButton value="#{messages.exit}" icon="ui-icon-close"
                style="valign:bottom;float:right;padding-right:20px"
                onclick="updatedlg.hide();" type="button"/>

这将创建一个按钮,它只调用一个 javascript 来关闭对话框。

【讨论】:

  • 对不起,它也不起作用。您可以找到有问题的更新对话框。
  • 添加 update="@form" 解决了这个问题。完整的对话正在回答中。
【解决方案2】:
<p:dialog header="Service Alarm Options" widgetVar="updatedlg"
        closable="false" minWidth="500" minHeight="1000" resizable="false"
        dynamic="false">
        <h:form>
            <h:panelGrid id="servicedetails">
                <p:commandButton value="Save"
                    action="#{alarmBean.selectedDocument.saveNewFeatures}" />
                <p:commandButton value="#{messages.exit}" icon="ui-icon-close"
                    style="valign:bottom;float:right;padding-right:20px"
                    update="@form"
                    actionListener="#{alarmBean.selectedDocument.resetFeatures}"
                    oncomplete="updatedlg.hide();">                     
                </p:commandButton>              
                <p:inputText
                    value="#{alarmBean.selectedDocument.dataTransferRangeInSeconds}"></p:inputText>
            </h:panelGrid>
        </h:form>
    </p:dialog>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-10-27
    • 2017-12-01
    • 2017-06-04
    • 2012-09-20
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多