I have some problem with the primefaces dialog. I have a context menu. When I click on the context menu, it shows a dialog. This dialog contains a panel with a required input text. When the dialog is shown, a validation error is displayed in the panel because the input text is empty. The idea is to display validation error only when the user clicks on the commandButton of the dialog. Then, when the dialog is opened, it must be emptied. That means, no validation error and nothing in the input text. It seems that the attribute update in the context menu is a problem. In one side, it is necessary to empty the input text when the user displays the dialog for the second time, but it displays also the validation error the first time the dialog is displayed.
<p:contextMenu for="folderTree">
<p:menuitem value="New Folder" update="addFolderPanel" oncomplete="addFolderDialog.show()" actionListener="#{folderManagedBean.initDialog}" icon="ui-icon-plus"/>
</p:contextMenu>
<p:dialog header="New Folder" widgetVar="addFolderDialog" modal="true" resizable="false"
showEffect="clip" hideEffect="fold">
<p:outputPanel id="addFolderPanel">
<p:message id="defaultMessage" for="txAddFolder"/>
<h:panelGrid columns="2" cellpadding="4">
<h:outputText for="txAddFolder" value="Folder Name: *" />
<p:inputText id="txAddFolder" value="#{folderManagedBean.newFolderName}" required="true" requiredMessage="The field folder name is required."/>
<p:commandButton icon="ui-icon-check" value="OK" update="folderTree" oncomplete="handleDialogClose(xhr, status, args)" actionListener="#{folderManagedBean.addFolder}"/>
</h:panelGrid>
</p:outputPanel>
</p:dialog>
Code of the managed bean:
public void initDialog() {
this.newFolderName = "";
RequestContext.getCurrentInstance().reset("form:addFolderPanel");
}
Basically, I would like to know why the dialog shows a validation error the first time it is opened and how to solve this problem.
Any help would be really appreciated.
Finaly, I find myself tha answer to my question.
It is necessary to remove the
updateattribute from the context menu and to add it in the attributeupdateof the commandButton.Like that, when the user opens the dialog, there is no update, thus no validation error. Then, when he clicks on the button to save its changes there is 2 cases:
I hope it can help!