Hi,
I've found a solution, which works for me.
I don't know if I understand your problem exactly, but I'm gonna share it here in case it might help you, too

This is my
Dialog:
<p:dialog id="myDialog" widgetVar="myDialog" modal="true">
<p:ajax event="close" listener="#{itemController.initNewItem}"
update="myDialogForm" immediate="true" global="false"
oncomplete="MyUtils.removeErrorStates('myDialogForm');" />
<h:form id="myDialogForm">
<p:message for="newItemName" />
<p><h:outputText value="${uiText['dlgNewItem']}" /></p>
<h:panelGrid columns="2">
<h:outputLabel value="#{uiText['lblName']}:" />
<p:inputText id="newItemName" required="true"
value="#{itemController.newItem.name}"
requiredMessage="#{uiText['msgRequiredField']}" />
</h:panelGrid>
<h:panelGrid columns="2">
<f:facet name="footer">
<p:commandButton value="#{uiText['cmdOk']}"
actionListener="#{itemController.createNewItem}"
oncomplete="myDialog.hide();"
update="@form :msgs">
</p:commandButton>
<p:commandButton value="#{uiText['cmdCancel']}"
onclick="myDialog.hide();" type="button" />
</f:facet>
</h:panelGrid>
</h:form>
</p:dialog>
The ItemController:
@SessionScoped
@Named
public class ItemController implements Serializable
{
private static final long serialVersionUID = 1L;
private Item newItem;
// ...
// getter,
// setter,
// etc.
// ...
public void initNewItem()
{
newItem = new SampleItem();
}
@PostConstruct
public void init()
{
initNewItem();
}
}
My JavaScript function:
MyUtils.removeErrorStates = function(id)
{
$(PrimeFaces.escapeClientId(id) + ' .ui-state-error').removeClass('ui-state-error');
};
ItemController.initNewItem() creates a new item (with empty values) for the form of MyDialog.
MyUtils.removeErrorStates() simply removes the CSS class "ui-state-error" from all elements inside the element with the given "id", which, in this case, is the form of MyDialog.
The p:ajax does all this in the correct order (first reset the form data, then, after the update, remove the remaining error state).
Now the
dialog looks like the first time

... at least in my project

Regards,
Lawyno