Reputation: 4529
I use a dataTable to display the some records. The user can add/change records using a dialog named actionsDialog. Before saving the record, a modal dialog, called reasonDialog, is displayed and the user has to enter some reasons for the current operation. In my logic I set the reason to null after the data is saved into database.
The problem appears when I repeat the operation. The reason contains the previous value. I have debugged the code and noticed that this happens because the reason is assigned the local value of the inputTextarea. How can I get rid of the local value? I am using PrimeFaces 3.0, Mojara 2.0.4, Tomcat 7.
My reason dialog facelet is:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<p:dialog header="#{label.reason}" widgetVar="reasonDialog"
showEffect="fade" hideEffect="explode" modal="true" dynamic="true">
<h:panelGrid columns="2">
<p:inputTextarea rows="5" cols="40" autoResize="false"
value="#{recordsBean.reason}" maxLength="1024" />
<f:facet name="footer">
<p:outputPanel layout="block">
<p:commandButton value="ok" update="genericRecords msgs"
action="#{recordsBean.execute}"
oncomplete="reasonDialog.hide();actionsDialog.hide()" />
</p:outputPanel>
</f:facet>
</h:panelGrid>
</p:dialog>
</ui:composition>
The action dialog looks like this:
<p:dialog id="actionsDialog" widgetVar="actionsDialog" dynamic="true"
resizable="false" height="600" showEffect="fade" hideEffect="fade" modal="true">
<ui:include src="/WEB-INF/flows/genericRecord.xhtml"/>
<f:facet name="footer">
<p:outputPanel layout="block">
<p:commandButton value="save" onclick="reasonDialog.show()" />
<p:commandButton value="cancel" immediate="true"
oncomplete="actionsDialog.hide()" />
</p:outputPanel>
</f:facet>
</p:dialog>
Upvotes: 1
Views: 11189
Reputation: 1
//This is an Alternative Solution if nothing worked:
Nothing worked for me...answers or comments.. so i had to do the following:
I used ResetInputs
to reset the form inside my dialog and a method to open it from my bean.
So,
<p:commandButton value="Show" actionListener="#{myBean.showDialog()}" update=":myForm">
<p:resetInput target=":myForm"/>
</p:commandButton>
And then in my bean i did this method, wich opens the dialog (with the dialog's widgetVar) and initialize my object again, so every time i open my dialog, the values in all the <p:inputText>
(or whatever) will be always in blank/null.
public void showDialog(){
car = new Car();
RequestContext context = RequestContext.getCurrentInstance();
context.execute("PF('wvDialog').show();");
//added widgetVar to myDialog called wvDialog
}
Inside the dialog i have some <p:inputText>
, <p:selectOneMenu>
, <p:calendar>
and others. All of them dont remember previous values again when the dialog is closed, after submit, or errors.
This was the only way it worked for me, hope it helps some1!
Upvotes: 0
Reputation: 1108782
You need to update/refresh dialog's contents before showing it. Reference its (relative) client ID in the update
attribute and move the show()
from onclick
to oncomplete
so that it takes place after the update.
<p:commandButton value="save" update="reasonDialog" oncomplete="reasonDialog.show()" />
Otherwise it will of course still display the old content as it was before it was closed. You're namely by ajax/JS interacting with exactly the same page, not a new page or so.
Upvotes: 9
Reputation: 6738
Try to add ajax="false" attribute in your p:commandButton; See sample
<p:commandButton value="ok" update="genericRecords msgs"
action="#{recordsBean.execute}" ajax="false"
oncomplete="reasonDialog.hide();actionsDialog.hide()" />
Upvotes: 1