2

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?

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Chucky
  • 1,706
  • 6
  • 27
  • 58
  • You simply misunderstood its purpose. – BalusC Jul 24 '13 at 15:46
  • 1
    possible duplicate of [Why does require the properties of a ManagedBean to be set to null first after the form is submitted?](http://stackoverflow.com/questions/17674734/why-does-presetinput-require-the-properties-of-a-managedbean-to-be-set-to-nul) – BalusC Jul 24 '13 at 15:46
  • I see. I thought it might not work as I was expecting. I've taken a look at this link but it doesn't seem to offer what I'm looking for. Do you know what I should use? – Chucky Jul 24 '13 at 15:49
  • That link has your actual solution in the last paragraph and contains "See also" links. – BalusC Jul 24 '13 at 15:51
  • Straight up, I'm not seeing it in either. All I need is that when a user submits, and then opens the dialog again to submit another, that the field be empty. But it's retaining the value from the previous attempt. Can't see anything like that in the links! – Chucky Jul 24 '13 at 15:56
  • Oh this way. So, you aren't ajax-updating the dialog's content before opening? – BalusC Jul 24 '13 at 15:57
  • No. A button just opens the dialog and it should be a blank form for a user to input to. – Chucky Jul 24 '13 at 15:59
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34150/discussion-between-chucky-and-balusc) – Chucky Jul 25 '13 at 11:47

1 Answers1

4

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:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452