download doesn't work inside dialog jsf2 primefaces - jsf-2

I have this problem
when I put download link into a dialog box it doesn't work, but when I put it into panelgrid it works
is it a bug in primefaces or what ?
do you have any idea

<h:form>
<p:panel header="Query">
<.......some come is here ........
<p:commandButton value="Export CSV" icon="ui-icon-document"
process="#this" rendered="#{xxx.showTable}"
oncomplete="exportConfirmationDialogShow.show()"></p:commandButton>
</h:panelGrid>
</p:outputPanel>
</h:panelGrid>
</p:panel>
</h:form>
Dialog ;
<p:dialog header="Choose Delimiter Type" id="dialogCSV"
widgetVar="exportConfirmationDialogShow" resizable="false">
<h:form id="csvForm">
<h:panelGrid columns="2" style="margin-bottom:10px">
<h:outputLabel value="Delimiter:" />
<p:selectOneRadio id="delimiter" value="#{xxx.delimiterType}">
<f:selectItem itemLabel="Tab" itemValue="tab" />
<f:selectItem itemLabel="Pipe" itemValue="|" />
<f:selectItem itemLabel="Comma" itemValue="," />
</p:selectOneRadio>
</h:panelGrid>
<p:commandButton id="exportCsv" value="Export CSV"
actionListener="#{xxx.export2CSV}" ajax="false"
onclick="PrimeFaces.monitorDownload(hideStatus)">
<p:fileDownload value="#{xxx.exportFile}"
contentDisposition="attachment" />
</p:commandButton>
</h:form>
<script type="text/javascript">
function showStatus() {
exportConfirmationDialogShow.show();
}
function hideStatus() {
exportConfirmationDialogShow.hide();
}
</script>
</p:dialog>

Related

Primefaces h:panelgrid inside a p:tabView or p:outputpanel

I am working with a h:panelgrid in a p:tabView, but the components in the panelgrid are more smaller than components(inputtext, buttons, the font size) that are outside of him.
The code is :
<ui:composition
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<p:panel header="Datos Generales de Proyecto" />
<h:panelGrid id="idPgProyecto" columns="4" width="100%" border="0" columnClasses="colC1-T,colC2-T,colC3">
<p:outputLabel for="idEmpresa" value="Empresa:" style="margin-right:2px;" />
<p:inputText id="idEmpresa" style="width:350px;" value="#{proyectoBean.prVista.strEmpresa}"
readonly="true"/>
<h:outputText value="   " />
<h:outputText value="   " />
<p:outputLabel for="idCodProyecto" value="Codigo: " style="margin-right:2px;"/>
<p:inputText id="idCodProyecto" value="#{proyectoBean.prVista.codigo}" style="width:350px;" />
<p:message for="idCodProyecto" display="text" />
<h:outputText value="   " />
</h:panelGrid>
<h:panelGrid id="idPgPr1" columns="5" width="100%" border="0" columnClasses="colC1-T,colC2-T,colC3,colC1-T">
<p:outputLabel for="idNombre" value="Nombre: " style="margin-right:2px;"/>
<p:inputText id="idNombre" value="#{proyectoBean.prVista.nombre}" style="width:350px;"
required="true" requiredMessage="Ingrese Nombre"/>
<p:message for="idNombre" display="icon" />
<p:outputLabel for="idFechaInicio" value="Fecha Inicio: " style="margin-right:10px;"/>
<p:calendar id="idFechaInicio" value="#{proyectoBean.prVista.fechaInicio}" showOn="button" pattern="dd-MM-yyyy"
navigator="true">
</p:calendar>
</h:panelGrid>
<p:outputPanel rendered="#{proyectoBean.prVista.id != null and proyectoBean.prVista.strEstadoProyecto == 'INC'}">
<h:panelGrid id="idPgProyecto5" columns="3" width="100%" border="0" columnClasses="colC1-T,colC2-T">
<h:outputText value="   " />
<p:commandButton value="Cerrar Proyecto" style="width: 360px; color: blue;" actionListener="#{proyectoBean.cerrarProyecto}" update="idFormProyecto">
<p:confirm header="Confirmacion de Cierre de Proyecto" message="¿Esta seguro de cerrar Proyecto?" icon="ui-icon-alert" />
</p:commandButton>
<h:outputText value="   " />
</h:panelGrid>
</p:outputPanel>
<p:tabView >
<p:tab title="Maquinas Perforacion" >
<h:outputText value="Este es un texto de prueba"/>
<h:panelGrid id="idPgMaquina" columns="5" width="100%" border="0" columnClasses="colC1-T,colC2-T,colC3,colC1-T">
<p:outputLabel for="idSlcMaquina" value="Asignar Maquina:" style="margin-right:2px;font-size: 12px;"/>
<p:selectOneMenu id="idSlcMaquina" style="width:358px;" effect="none" value="#{proyectoBean.pu.idMaquina}"
disabled="#{proyectoBean.prVista.id == null}">
<f:selectItem itemLabel=" ---- Seleccione Maquina ---- " itemValue="#{null}" noSelectionOption="true"/>
<f:selectItems value="#{proyectoBean.pu.lstMaquinas}" var="m" itemValue="#{m.id}" itemLabel="#{m.nombre}"/>
</p:selectOneMenu>
<p:commandButton id="idBtnASignar" actionListener="#{proyectoBean.asignarMaquinaProyecto}"
update="idPgMaquina,idDTMaquinasProyecto" title="Agregar Maquina a lista" icon="ui-icon-plus"/>
<h:outputText value="   " />
<h:outputText value="   " />
</h:panelGrid>
</p:tab>
<p:tab title="Empleados" >
<h:panelGrid columns="3" width="100%" columnClasses="colC1-T,colC2-T" border="0">
<p:outputLabel value="Empleado:" for="idAutoCompleteEmpleado" style="margin-right:2px;"/>
<p:autoComplete id="idAutoCompleteEmpleado" value="#{proyectoBean.pu.empleado}" completeMethod="#{proyectoBean.completarEmpleado}"
var="empleado" itemLabel="#{empleado.nombreCompleto}" itemValue="#{empleado}" converter="empleadoPRConverter"
minQueryLength="2" onclick="this.select();" forceSelection="true" size="65" disabled="#{proyectoBean.prVista.id == null}">
<p:ajax event="itemSelect" listener="#{proyectoBean.seleccionarEmpleado}" update="idDTEmpleadoProyecto"/>
</p:autoComplete>
<p:message for="idAutoCompleteEmpleado" display="text"/>
</h:panelGrid>
</p:tab>
</p:tabView>
</ui:composition>
The panelgrid inside a outputpanel or tabview has the components more smaller that the others panelgrid that are outside. I'm working with PF 4.0 and JSF 2.2
Thanks for all
Seems like this is because it scales based on width. In tabview width of panelgrid is much smaller, than outside.
In this case, I would suggest to create css styles for each component and apply them, rather then making them stretch automatically

primefaces export data table dynamic columns

i want to add exporting for dynamic columns.
I think that should go. Dynamic Columns Export Data
I used the samplecode from Primefaces and edit it: Primefaces Example
The Code works, but the data isn't correct.
The File include the dynamic Data like data[i], data[i], .... and not the attributes in data[i].
Any idea?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:my="http://java.dynamic.list.de"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="META-INF/templates/Template.xhtml">
<ui:define name="content">
<h:form id="form" enctype="multipart/form-data">
<h:panelGrid columns="3">
<h:selectOneMenu id="showColl" value= "#{searchBean.collList.currentColl}" rendered = "#{searchBean.search.visible}">
<f:selectItems value="#{searchBean.collList.collList}" />
</h:selectOneMenu>
<h:outputText value="#{msgs.collection}" rendered = "#{searchBean.search.hide}"></h:outputText>
<h:outputText value="#{searchBean.collList.currentColl}" rendered = "#{searchBean.search.hide}"></h:outputText>
<h:commandButton id="show" action="#{searchBean.showFieldList}" value="#{msgs.plus}" rendered="#{searchBean.search.visible}" style=""/>
<h:commandButton id="hide" action="#{searchBean.hideFieldList}" value="#{msgs.minus}" rendered="#{searchBean.search.hide}" immediate="true" onchange="this.form.submit()" style=""/>
</h:panelGrid>
<h:panelGrid columns="1" rendered="#{searchBean.search.hide}">
<h:panelGrid columns="2">
<h:outputLabel value="#{msgs.Attr}"></h:outputLabel>
<h:selectOneMenu id="Field"
value="#{searchBean.collList.currentField}"
rendered="#{searchBean.search.readWrite}">
<f:selectItems
value="#{searchBean.collList.fieldList}" />
</h:selectOneMenu>
<h:outputText value="#{searchBean.collList.currentField}" rendered="#{searchBean.search.readOnly}"></h:outputText>
</h:panelGrid>
<h:panelGrid columns="2">
<h:outputLabel value="#{msgs.value}"></h:outputLabel>
<h:inputText value="#{searchBean.search.value}" rendered = "#{searchBean.search.readWrite}"></h:inputText>
<h:outputText value="#{searchBean.search.value}" rendered = "#{searchBean.search.readOnly}"></h:outputText>
</h:panelGrid>
<h:panelGrid columns="3">
<h:outputText value="#{msgs.sort_Order}"/>
<h:selectOneRadio id="sortOrder"
value="#{searchBean.search.ascendingData}"
immediate="true" onchange="this.form.submit()">
<f:selectItem itemLabel="#{msgs.ascending}" itemValue="a" itemDisabled="#{searchBean.search.readOnly}"/>
<f:selectItem itemLabel="#{msgs.descending}" itemValue="d" itemDisabled="#{searchBean.search.readOnly}"/>
</h:selectOneRadio>
</h:panelGrid>
</h:panelGrid>
<h:commandButton id="search" action="#{searchBean.searchButton}" value="#{msgs.search}" style=""/>
<p:dataTable id="datas" var="data" value="#{searchBean.readListMap.items}" style="width:150px"
scrollable="true" scrollWidth="800" scrollHeight="400" emptyMessage="Keine Daten vorhanden">
<p:columns value="#{searchBean.collList.fieldListColumns}" var="columnName" columnIndexVar="i" style="width:150px" headerText="#{columnName}">
#{data[i]}
</p:columns>
</p:dataTable>
<h:commandLink>
<p:graphicImage library="images" name="csv.png" />
<p:dataExporter type="csv" target="datas" fileName="assetDB" />
</h:commandLink>
<h:commandLink>
<p:graphicImage library="images" name="xml.png" />
<p:dataExporter type="xml" target="datas" fileName="assetDB" />
</h:commandLink>
</h:form>
</ui:define>
</ui:composition>
</html>
I used this code toe create the file.
result i a StringBuilder to create your costum string. i created a specific cvs file.
String tempString = result.toString();
InputStream stream = new ByteArrayInputStream(tempString.getBytes("UTF-8"));
Timestamp tstamp = new Timestamp(System.currentTimeMillis());
file = new DefaultStreamedContent(stream, "application/cvs", "test-"+tstamp+".cvs");
I write in the xhtml file the example from primefaces Primefaces example. Hope this helps other people to have problems with dynamic columns and primefaces to export the data.

To display validation message in primefaces dialog from managed bean

i am trying to display the message of the outcome of a validation done in managed bean in the dialog but it is not getting displayed in the dialog on submit of the form.
Please help me in fixing this
My JSF page snippet with dialog
<p:dialog header="Add LPC" id="lpcDlg" widgetVar="dlg" rendered="true"
appendToBody="true" resizable="true" modal="true" height="320px"
width="38%">
<h:form id="addLpc">
<div align="center" style="margin-bottom: 1px; padding-bottom: 1px;">
<h:outputLabel value="Add New LPC"
style="font-color:#000000;font-weight:bold;font-size:24px;padding-bottom:1px;"></h:outputLabel>
</div>
<div align="center">
<p:messages id="lpcDlgMsg" showDetail="false" autoUpdate="true"
closable="true" />
<p:messages id="lpcDlgMsg2" for="lpcDlgMessage" showDetail="false"
autoUpdate="true" closable="true" />
<h:panelGrid id="addLpcForm" columns="2" appendToBody="true">
<h:outputText value="LPC ID" />
<p:inputText id="lpcId" value="#{lpcBean.lpcId}" required="true"
requiredMessage="LPC ID is required">
<f:ajax event="blur" render="lpcDlgMsg" />
</p:inputText>
<h:outputText value="First Name" />
<p:inputText id="firstName" value="#{lpcBean.firstName}" />
.
.
.
.
</h:panelGrid>
</div>
<div align="center">
<p:commandButton id="submitButton" value="Submit" ajax="true"
update=":lpcForm:lpcDataTable,addLpc"
action="#{lpcBean.formSubmit}" oncomplete="dlg.hide()" />
<p:commandButton id="cancelButton" value="Cancel"
onclick="dlg.hide()" />
</div>
</h:form>
</p:dialog>
message with id lpcDlgMsg2 is the message i am trying to display on submit.The other message is getting displayed correct on blur.
Snippet of the method that is called on submit
public void formSubmit()
{
if(resultSet.next())
{
int lpcIdCount=rs.getInt("lpcCount");
if(lpcIdCount!=0)
{
FacesContext.getCurrentInstance().addMessage("lpcDlgMessage", new FacesMessage(FacesMessage.SEVERITY_ERROR," ", "Duplicate LPCID"));
System.out.println("after display");
}
else
{
.
.
.
.
}
}
}
}
Here is my suggestion:
<p:dialog header="Add LPC" id="lpcDlg" widgetVar="dlg" rendered="true"
appendToBody="true" resizable="true" modal="true" height="320px"
width="38%">
<h:form id="addLpc">
<div align="center">
<p:messages id="lpcDlgMsg" showDetail="false" autoUpdate="true"
closable="true" />
<h:panelGrid id="addLpcForm" columns="2" >
<h:outputText value="LPC ID" />
<p:inputText id="lpcId" required="true" />
<h:outputText value="First Name" />
<p:inputText id="firstName" required="true" />
</h:panelGrid>
</div>
<div align="center">
<p:commandButton id="submitButton" value="Submit"
oncomplete="if (!args.validationFailed){dlg.hide();}" />
<p:commandButton id="cancelButton" value="Cancel"
onclick="dlg.hide()" />
</div>
</h:form>
</p:dialog>
Note that I've simplified your code in order to avoid using a managedbean.
If you want your managed bean to perform the validation, use RequestContext to conditionally execute the code that will close the dialog and remove the oncomplete from Submit button.
if (success) {
RequestContext.getCurrentInstance().execute("dlg.hide()");
}else{
//show all the messages you need here
}
You have to add this javascript first inside head tag
function handleComplete(xhr, status, args) {
if (!args.validationFailed) {
dlg.hide();
} else {
}
}
More changes are
<p:commandButton id="submitButton" value="Submit" ajax="true"
update=":lpcForm:lpcDataTable,addLpc :lpcDlgMsg2"
actionListener="#{lpcBean.formSubmit}" oncomplete="handleComplete(xhr, status, args)" />
action to actionListener because action has String return type.
This will work fine.

update entity attribute through primefaces modal

Try to load and update attributes from a datatable to a form embedded in a primefaces modal box:
1) The datatable command to send user's data to the modal
<p:commandButton value="alterar"
action="#{usuarioMB.carregarAlteracao(u)}" update=":usuarioDesc"
process="#this" onclick="dlg.show();" />
2) It loads well the user's attributes in the modal box
<p:dialog id="modalDialog" header="Alterar Usuário" widgetVar="dlg"
modal="true" height="260" appendToBody="true" dynamic="true" >
<h:form id="usuarioDesc" styleClass="formTamanho">
<h:panelGrid id="#{msg.pnlIdProfile}" columns="2"
columnClasses="labelPanelGrid, contentPanelgrid">
<p:outputLabel value="Perfil:" />
<p:outputLabel value="#{usuarioMB.usuario.perfil.nome}" />
</h:panelGrid>
<h:panelGrid id="#{msg.pnlIdLogin}" columns="2"
columnClasses="labelPanelGrid, contentPanelgrid">
<p:outputLabel value="#{msg.lblLogin}" for="usuario_login" />
<p:inputText value="#{usuarioMB.usuario.login}" id="usuario_login"
required="true" requiredMessage="#{msg.msgReqLogin}" />
</h:panelGrid>
<h:panelGrid id="nomeUsuario" columns="2"
columnClasses="labelPanelGrid, contentPanelgrid">
<p:outputLabel value="Nome:" for="usuario_nome" />
<p:inputText value="#{usuarioMB.usuario.nome}" id="usuario_nome"
required="true" />
</h:panelGrid>
<h:panelGrid id="emailUsuario" columns="2"
columnClasses="labelPanelGrid, contentPanelgrid">
<p:outputLabel value="Email:" for="usuario_email" />
<p:inputText value="#{usuarioMB.usuario.email}" id="usuario_email"
required="false" />
</h:panelGrid>
<h:panelGrid id="#{msg.pnlIdCal}" columns="3"
columnClasses="labelPanelGrid, contentPanelgrid">
<p:outputLabel value="#{msg.lblBirth}" for="#{msg.calId}" />
<p:calendar value="#{usuarioMB.usuario.nascimento}"
id="#{msg.calId}" locale="#{msg.calLocale}" showButtonPanel="true"
navigator="true" />
<p:outputLabel value="(Ex: 16-04-1980)" />
</h:panelGrid>
<br />
<div id="btnForms" style="margin-left: 120px;">
<p:commandButton value="Alterar Usuário" id="alt_usuario"
action="#{usuarioMB.alterar()}" update=":usuarioDataTable:tableUsuarios"
process="#this" style="margin-left:5px;" oncomplete="dlg.hide();"/>
<p:commandButton value="Criar nova senha e mandar por email"
id="alt_senha"
action="#{usuarioMB.sendEmail(usuario.email)}"
process="#this"
style="margin-left:5px;" />
<p:commandButton value="Cancelar" onclick="dlg.hide();"
style="margin-left:5px;" />
</div>
</h:form>
</p:dialog>
3) When i modify the attribute through the fields in the modal, then use the command action "alterar" , then the managed bean still keeps the reference to the user's original datas, and no update happens.
public String alterar() {
try {
gerenciarUsuarioBean.alterar(usuario);
JSFMessageUtil.sendInfoMessageToUser("Usuário salvado com sucesso!");
} catch (DaoExcecao e) {
LOG.error(e);
JSFMessageUtil.sendErrorMessageToUser("Erro cadastrando usuário !");
}
usuario = new Usuario();
return "/views/gerencia/gerenciarUsuarios.xhtml";
}
In a nutshell, the user's attributes are auto merged in the database. Any help is welcome..
Ok, then there was a bit of confusion in the command buttons (process / update)
1) datatable cmd:
<p:commandButton value="alterar"
action="#{usuarioMB.carregarAlteracao(u)}" update=":usuarioDesc:usr"
process="#this" onclick="dlg.show();" />
2) Update button
<p:commandButton value="Alterar Usuário" id="alt_usuario"
action="#{usuarioMB.alterar()}"
update=":usuarioDataTable:tableUsuarios" process="#form"
style="margin-left:5px;" oncomplete="dlg.hide();" />
Hope it helps someone.

Clearing form fields after invalidation JSF

Ok i have the following problem: In my web app i have the CRUD all one page via dialogs controls of Primefaces. In the new dialog i have some validators. For example: when a user does not fill the necessary fields for form submission obviously the form doesn't submit. But when i close de New dialog and open it up again, the validation messages are still there! How can i get rid of this? I want a fresh new page (without accumulated validation errors) every time a dialogs open up! How that can be done?
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition 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.org/ui"
template="./../../resources/templates/baseTemplate.xhtml">
<ui:define name="content">
<f:view id="vRoot">
<p:fieldset legend="Gerenciar público">
<h:form id="frmPublicos">
<!-- Exibição de mensagens gerais -->
<p:growl id="gMessages" sticky="false" globalOnly="true" />
<!-- Exibição da lista de públicos -->
<p:dataTable id="dtPublicos"
value="#{publicoBean.lstDataTablePublico}"
paginator="true" rows="5"
rowsPerPageTemplate="5,10"
paginatorPosition="bottom"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
var="atual">
<!-- Every time dialog opens validation messages should be cleaned -->
<f:facet name="header">
<p:commandButton id="cbViewNovo"
value="Novo" type="button"
styleClass="cbViewNovo"
onclick="dlgNovo.show();"
update=":dlgNovoPublico"
process="#this">
<p:resetInput target=":dlgNovoPublico"/>
</p:commandButton>
</f:facet>
<!-- Colunas de edição e exclusão -->
<p:column>
<f:facet name="header">
<h:outputLabel value="Editar"/>
</f:facet>
<p:commandButton id="cbViewEditar"
image="ui-icon-pencil"
title="Editar"
update=":frmEditar:pEditarPublico"
oncomplete="dlgEditar.show();">
<f:setPropertyActionListener value="#{atual}" target="#{publicoBean.publicoSelecionado}" />
</p:commandButton>
</p:column>
<p:column>
<f:facet name="header">
<h:outputLabel value="Excluir"/>
</f:facet>
<p:commandButton id="cbViewExcluir" onclick="dlgExcluir.show();"
icon="ui-icon-close" title="Excluir">
<f:setPropertyActionListener value="#{atual}" target="#{publicoBean.publicoSelecionado}" />
</p:commandButton>
</p:column>
<p:column>
<f:facet name="header">
Nome
</f:facet>
<h:outputLabel id="olViewNomePublico" value="#{atual.nmePublico}"/>
</p:column>
<p:column>
<f:facet name="header">
Tipo de público
</f:facet>
<h:outputLabel id="olViewTipoPublico" value="#{atual.tdTipoPublico}"/>
</p:column>
</p:dataTable>
</h:form>
<!-- Caixa de diálogo de inclusão -->
<p:dialog id="dlgNovoPublico"
widgetVar="dlgNovo"
modal="true"
header="Novo público"
resizable="false">
<h:form id="frmNovo">
<p:panel id="pNovoPublico">
<p:messages id="mNovoMessages" redisplay="false" />
<p:panelGrid columns="2">
<p:outputLabel id="olNovoNomePublico" value="Nome:" for="itNovoNomePublico"/>
<p:inputText id="itNovoNomePublico" value="#{publicoBean.nome}" required="true"
requiredMessage="Digite o nome do público."/>
<p:outputLabel id="olNovoTipoPublico" for="somNovoTipoPublico" value="Tipo de público:"/>
<p:selectOneMenu id="somNovoTipoPublico"
value="#{publicoBean.tipoPublicoSelecionado}"
effect="fade"
converter="#{publicoBean.conversor}"
required="true"
requiredMessage="Selecione um tipo de público."
>
<f:selectItem itemLabel="Selecione um item..." itemValue=""/>
<f:selectItems value="#{publicoBean.lstMenuTipoPublico}" var="atual" itemLabel="#{atual.label}" itemValue="#{atual}"></f:selectItems>
</p:selectOneMenu>
<p:commandButton value="Cancelar" immediate="true" onclick="dlgNovo.hide()"/>
<p:commandButton id="cbNovoSalvar" value="Salvar"
actionListener="#{publicoBean.cadastrarPublico}"
oncomplete="handleSalvo(xhr, status, args);"
update=":frmPublicos:dtPublicos :frmNovo :frmPublicos:gMessages"
ajax="true"/>
</p:panelGrid>
</p:panel>
</h:form>
</p:dialog>
<!-- Caixa de diálogo de exclusão -->
<p:confirmDialog id="dialogoExcluir" message="Deseja realmente excluir?"
header="Excluir público" severity="alert"
widgetVar="dlgExcluir">
<h:form id="frmExcluir">
<p:commandButton id="cbExcluirCancelar" value="Cancelar" onclick="dlgExcluir.hide()" type="button" />
<p:commandButton id="cbExcluirContinuar" value="Continuar"
update=":frmPublicos:dtPublicos :frmPublicos:gMessages"
oncomplete="dlgExcluir.hide()"
actionListener="#{publicoBean.excluirPublico}"/>
</h:form>
</p:confirmDialog>
<!-- Caixa de diálogo de edição -->
<p:dialog id="dialogoEditar" widgetVar="dlgEditar" header="Editar público"
resizable="false" modal="true">
<h:form id="frmEditar">
<p:panel id="pEditarPublico">
<p:messages id="mEditarMessages" redisplay="false" />
<p:panelGrid columns="2">
<p:outputLabel id="olEditarNomePublico" value="Nome:" for="itEditarNomePublico"/>
<p:inputText id="itEditarNomePublico" value="#{publicoBean.publicoSelecionado.nmePublico}" required="true"
requiredMessage="Digite o nome do público."/>
<p:outputLabel id="olEditarTipoPublico" for="somEditarTipoPublico" value="Tipo de público:"/>
<p:selectOneMenu id="somEditarTipoPublico"
value="#{publicoBean.publicoSelecionado.tdTipoPublico}"
effect="fade"
converter="#{publicoBean.conversor}"
required="true"
requiredMessage="Selecione um tipo de público."
>
<f:selectItem itemLabel="Selecione um item..." itemValue=""/>
<f:selectItems value="#{publicoBean.lstMenuTipoPublico}"
var="atual"
itemLabel="#{atual.label}"
itemValue="#{atual}"></f:selectItems>
</p:selectOneMenu>
<p:commandButton value="Cancelar" immediate="true" onclick="dlgEditar.hide()"/>
<p:commandButton id="cbEditarSalvar" value="Salvar"
actionListener="#{publicoBean.alterarPublico}"
oncomplete="dlgEditar.hide();"
update=":frmPublicos:dtPublicos :frmEditar :frmPublicos:gMessages"/>
</p:panelGrid>
</p:panel>
</h:form>
</p:dialog>
</p:fieldset>
</f:view>
<!-- Javascript responsável por fechar a caixa de diálogo ao cadastrar-->
<script type="text/javascript">
function handleSalvo(xhr, status, args){
if(args.salvo){
dlgNovo.hide();
}
}
function handleEditar(xhr, status, args){
if(args.salvo){
dlgEditar.hide();
}
}
</script>
</ui:define>
Try p:resetInput. http://www.primefaces.org/showcase-labs/ui/resetInput.jsf
Try with pe:resetInput from Primefaces Extensions: http://fractalsoft.net/primeext-showcase-mojarra/sections/resetInput/formElements.jsf
<p:commandButton id="cbViewNovo"
value="Novo" type="button"
styleClass="cbViewNovo"
onclick="dlgNovo.show();"
update=":dlgNovoPublico"
process="#this">
<pe:resetInput target=":dlgNovoPublico"/>
</p:commandButton>

Resources