Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Forms 操作/方法调用失败后关闭时清除p:对话框中的窗体_Forms_Jsf 2_Primefaces_Dialog_Reset - Fatal编程技术网

Forms 操作/方法调用失败后关闭时清除p:对话框中的窗体

Forms 操作/方法调用失败后关闭时清除p:对话框中的窗体,forms,jsf-2,primefaces,dialog,reset,Forms,Jsf 2,Primefaces,Dialog,Reset,我在通过AJAX提交的p:dialog组件中得到了一个表单。对话框中的表单是通过另一个.xhtml的ui:include生成的,其中只包含表单及其组件(不,我没有嵌套表单;对话框本身不在任何表单中)。包含的页面的支持bean是“ViewScope” 大多数功能正常: 验证成功后,表单将执行save方法;保存成功后,对话框关闭;打开后续记录会显示数据库中的正确记录信息 验证失败时,提交的值将保持不变,对话框将保持打开状态,并显示验证错误,修复无效字段并在成功保存后重新提交结果 当p:comma

我在通过AJAX提交的
p:dialog
组件中得到了一个表单。对话框中的表单是通过另一个
.xhtml
ui:include
生成的,其中只包含表单及其组件(不,我没有嵌套表单;对话框本身不在任何表单中)。包含的页面的支持bean是“ViewScope”

大多数功能正常:

  • 验证成功后,表单将执行save方法;保存成功后,对话框关闭;打开后续记录会显示数据库中的正确记录信息
  • 验证失败时,提交的值将保持不变,对话框将保持打开状态,并显示验证错误,修复无效字段并在成功保存后重新提交结果
p:commandButton
调用的
操作失败时,就会出现问题。如果失败,对话框将保持打开状态,并通过
h:messages
向用户显示“错误保存更改”;此外,提交的值仍保留在输入字段中。当表单保持打开状态时,这是很好的(甚至是需要的),但是,在关闭对话框并重新打开它时,提交的值仍然在文本字段中。这是不好的,因为它给用户的印象是保存成功了(由于对话框更新,
h:messages
组件现在为空)

到目前为止,我尝试了以下方法,但没有一种方法能够解决问题:

  • 1.1)在对话框打开时,将包含表单的支持bean设置为bean的新实例
  • 1.2)由于bean现在是一个新实例,我还使用数据bean中的细节重新填充address对象
  • 2.1)禁用对话框上的关闭按钮,并在对话框中添加带有
    p:resetInput
    组件的
    p:commandButton
    “取消”按钮 它可以关闭对话框/重置表单。(对话框关闭,但已提交。) 表单中的值将保持不变)
  • 2.2)从此
    p:commandButton
    调用一个方法,该方法删除所包含表单的支持bean的
    RequestMap
  • 2.3)尝试将按钮设置为
    immediate=true
    immediate=false
  • 2.4)尝试将按钮设置为
    process=@this
    ,这是一种类似的策略,我用来关闭表单,以确保表单上有新字段 重新开放
您可能会认为,在将支持bean设置为新实例和重新填充address对象之间,我会看到一个新的表单,但没有

以下是一些来源:

mainform.xhtml的一部分

    <p:dialog id="dlgAddress"
              header="Address Edit"
              widgetVar="dialogAddress"
              dynamic="true"
              modal="false"
              closable="false"
              resizable="false"
              styleClass="dlgAddress"
              visible="#{addressform.showDlgAddress}">
        <ui:include src="addressform.xhtml"/>
    </p:dialog>
<h:form id="fDlgAddress">
    <div id="addresses-container">
        <h:messages id="msgDlgAddress" errorClass="errormsg" infoClass="infomsg1" layout="table"/>
        <h:panelGrid columns="1"
                     styleClass="pgAddresses"
                     rendered="#{!addressform.address.exists}">
            <h:outputText value="No active #{addressform.address.atypCode} address found."
                          styleClass="record-not-exists"/>
            <h:outputText value="Use the form below to create one."/>
        </h:panelGrid>
        <p:panelGrid columns="2"
                     styleClass="pgDlgForm pgAddresses">
            <h:outputLabel value="Address Type"/>
            <h:inputText id="atypCode1"
                         value="#{addressform.address.atypCode}"
                         disabled="true"
                         rendered="#{addressform.address.exists}"/>
            <h:selectOneMenu id="atypCode2"
                             value="#{addressform.address.atypCode}"
                             rendered="#{!addressform.address.exists}">
                <f:selectItems value="#{addressform.atypCodeList}"
                               var="atyp"
                               itemValue="#{atyp}"
                               itemLabel="#{atyp}"/>
            </h:selectOneMenu>
            <h:outputLabel value="Street 1" 
                           for="street1"/>
            <h:inputText id="street1"
                         value="#{addressform.address.addressLine1}"/>
            <h:outputLabel value="Street 2" 
                           for="street2"/>
            <h:inputText id="street2"
                         value="#{addressform.address.addressLine2}"/>
            <h:outputLabel value="Street 3" 
                           for="street3"/>
            <h:inputText id="street3"
                         value="#{addressform.address.addressLine3}"/>
            <h:outputLabel value="Street 4" 
                           for="street4"/>
            <h:inputText id="street4"
                         value="#{addressform.address.addressLine4}"/>
            <h:outputLabel value="City" 
                           for="city"/>
            <h:inputText id="city"
                         value="#{addressform.address.city}"
                         required="true"
                         requiredMessage="Please enter a city."/>
            <h:outputLabel value="State" 
                           for="statCode"/>
            <h:selectOneMenu id="statCode"
                             value="#{addressform.address.stateCode}">
                <f:selectItem itemLabel="Select State/Province"
                              itemValue=""/>
                <f:selectItems value="#{states.statesList}"
                               var="stat"
                               itemValue="#{stat.statCode}"
                               itemLabel="#{stat.statDesc}"/>
            </h:selectOneMenu>
            <h:outputLabel value="Zip Code" 
                           for="zipCode"/>
            <h:inputText id="zipCode"
                         value="#{addressform.address.zip}"/>
            <h:outputLabel value="Country" 
                           for="natnCode"/>
            <h:selectOneMenu id="natnCode"
                             value="#{addressform.address.nationCode}"
                             required="true"
                             requiredMessage="Please choose a nation.">
                <f:selectItem itemLabel="Select Country"
                              itemValue=""/>
                <f:selectItems value="#{nations.nationsList}"
                               var="natn"
                               itemValue="#{natn.natnCode}"
                               itemLabel="#{natn.natnDesc}"/>
            </h:selectOneMenu>
            <h:outputLabel value="From Date" 
                           for="fromDate"/>
            <p:calendar id="fromDate"
                        value="#{addressform.address.fromDate}"
                        showButtonPanel="true"/>
            <h:outputLabel value="To Date" 
                           for="toDate"/>
            <p:calendar id="toDate"
                        value="#{addressform.address.toDate}"
                        showButtonPanel="true"/>
            <h:outputLabel value="Inactivate"
                           for="inactivateAddress"
                           rendered="#{addressform.address.exists}"/>
            <h:selectBooleanCheckbox id="inactivateAddress"
                                     value="#{addressform.address.inactivate}"
                                     rendered="#{addressform.address.exists}"/>
            <h:outputLabel value="Delete"
                           for="deleteAddress"
                           rendered="#{addressform.address.exists}"/>
            <h:selectBooleanCheckbox id="deleteAddress"
                                     value="#{addressform.address.delete}"
                                     rendered="#{addressform.address.exists}"/>
        </p:panelGrid>
    </div>
    <div class="button-container">
        <p:commandButton value="Save Changes"
                         action="#{addressform.save}"
                         type="submit"
                         ajax="true"
                         process="@form"
                         update="@form"/>
        <p:commandButton value="Cancel"
                         process="@this"
                         onclick="dialogAddress.hide();">
            <p:resetInput target="fDlgAddress"/>
        </p:commandButton>
    </div>
</h:form>
Addressform(地址表单的支持bean)

其他资料:

  • JSF2
  • Primefaces 3.5
  • Tomcat 6.0
  • 网虫
试试这个:

  • 将对话框放入表单中(dialogInputForm)

  • 添加属性update=“:dialogInputForm”

  • 将resetInput标记嵌套在打开对话框的按钮内,并将目标指定为刚创建的表单
  • 命令按钮:

    <p:commandButton process="@this" actionListener="#{bean.prepare}" update=":dialogInputForm" oncomplete="thirdPartyDialog.show()" value="Open Input Dialog" >
         <p:resetInput target=":dialogInputForm" />
    </p:commandButton>
    
    
    
    以及包含对话框的窗体

    <h:form id="dialogInputForm" >
     ... your dialog ...
    </h:form>
    
    
    ... 你的对话。。。
    
    这对我很有效,请将此ajax事件放置在对话框中。当对话框关闭时,验证将被清除

    <p:dialog id="dlgAddress"
                  header="Address Edit"
                  widgetVar="dialogAddress"
                  dynamic="true"
                  modal="false"
                  closable="false"
                  resizable="false"
                  styleClass="dlgAddress"
                  visible="#{addressform.showDlgAddress}">
            <ui:include src="addressform.xhtml"/>
    
       <p:ajax event="close" update="dlgAddress" resetValues="true" />
    
    </p:dialog>
    
    
    
    Hmmm。。。我明天可以在工作中试试,但我想我已经试过了。结果是p:resetInput使表单看起来好像没有加载任何记录,不仅清除了要清除的前一条记录中“卡住”提交的值,而且还清除了新传入记录的值。令人难以置信的是,此解决方案有效!我对重置对话框的值这个问题感到绝望。
    起作用。谢谢!对我发现它工作可靠。但是,我确实将表单嵌套在对话框中,这似乎不会引起问题。我想我的问题出现在最初尝试使用
    @form
    作为
    的目标时。您必须在此组件中使用实际的表单ID,并更新与上面示例中相同的表单。谢谢。试过了,只有当目标实际上是一个表单时才有效,如果它是一个复合组件的客户端id(文档说任何父组件都可以工作)就不起作用。悲哀的我不得不承认ID和代码在某个时候会变得脆弱。我试过你的解决方案,但从未使用过会话管理Bean我试过你的解决方案,也从未使用过会话管理Bean
    <h:form id="dialogInputForm" >
     ... your dialog ...
    </h:form>
    
    <p:dialog id="dlgAddress"
                  header="Address Edit"
                  widgetVar="dialogAddress"
                  dynamic="true"
                  modal="false"
                  closable="false"
                  resizable="false"
                  styleClass="dlgAddress"
                  visible="#{addressform.showDlgAddress}">
            <ui:include src="addressform.xhtml"/>
    
       <p:ajax event="close" update="dlgAddress" resetValues="true" />
    
    </p:dialog>