p:resetInput does not reset the p:dialog when it is reopened

こ雲淡風輕ζ 提交于 2021-01-28 03:18:27

问题


Here is some html I am writing to allow categories to be added using a dialog:

<p:dialog id="newCategoryDlg" header="Add New Category" widgetVar="newCategoryDialog" resizable="false">

    <h:form id="newCategoryForm">
        <p:panelGrid id="displayNewCategory" columns="2" cellpadding="4" style="margin:0 auto;">

            <h:outputText value="Category Name :"></h:outputText>
            <p:inputText value="#{categoryController.newCategory.name}"
                         required="true" requiredMessage="Please Enter a Category ID!" />


            <f:facet name="footer">
                <p:commandButton value="Submit" update=":form:categoryTable"
                                 oncomplete="newCategoryDialog.hide();"
                                 actionListener="#{categoryController.addCategory}">
                    <p:resetInput target="displayNewCategory" />
                </p:commandButton>
                <p:commandButton type="reset" value="Reset"></p:commandButton>
            </f:facet>
        </p:panelGrid>




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

Now, for whatever reason, "" just doesn't seem to work no matter which widget or identifier I use. All I want is for old input entries to disappear after they have been submitted. What am I doing wrong?


回答1:


You misunderstood the purpose of <p:resetInput>. This misunderstanding is essentially already answered/explained here: Why does p:resetInput require properties of a managed bean to be set to null first after the form is submitted?

As to your concrete functional requirement of the need to update the dialog's content before opening, just do exactly that in the command button which opens the dialog:

<h:form>
    <p:commandButton value="Open dialog" action="#{dialogBean.init}" 
        process="@this" update=":dialog" oncomplete="w_dialog.open()" />
</h:form>

...

<p:dialog id="dialog" widgetVar="w_dialog" ...>

Note that when the dialog contains fields which needs to be validated, then the <p:resetInput> would be very applicable in the button who's updating and opening the dialog in order to clear out invalid state.

See also:

  • How to show details of current row from p:dataTable in a p:dialog and update after save
  • Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes


来源:https://stackoverflow.com/questions/17838220/presetinput-does-not-reset-the-pdialog-when-it-is-reopened

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!