0
After having made a registration, it clears the form normally, but when I change page and return to the registration page, the fields are filled with the values I previously registered. The scoped I’m using is @Viewscoped.
Registration page..
<ui:define name="content">
<h1 class="aw-page-title">Realizar Emprestimos</h1>
<h:form id="form" prependId="false">
<p:messages id="msgs"/>
<p:toolbar>
<f:facet name="left">
<p:toolbarGroup>
<p:commandButton value="Confirmar" action="#{empMB.inserir}" process="@this"
update="form:list_publicacao" ajax="false">
<f:ajax render="form:list_publicacao" resetValues="true"/>
</p:commandButton>
</p:toolbarGroup>
</f:facet>
<f:facet name="right">
<p:toolbarGroup>
<p:commandButton value="Cancelar" action="#{empMB.limparCampos()}"
immediate="true">
<f:ajax render="@form" resetValues="true"/>
</p:commandButton>
</p:toolbarGroup>
</f:facet>
</p:toolbar>
<f:ajax event="blur">
<h:panelGrid id="p1" columns="4" layout="grid">
<p:outputLabel value="Usuário: " for="usuario" />
<p:selectOneMenu id="usuario" effect="fade" filter="true"
filterMatchMode="contains"
value="#{empMB.emprestimo.usuario.idUsuario}" required="true"
requiredMessage="Selecione um usuário">
<f:selectItem itemLabel="selecione um usuario"
noSelectionOption="true" />
<f:selectItems value="#{usuarioMB.todosUsuarios}" var="usu"
itemValue="#{usu.idUsuario}" itemLabel="#{usu.nomeUsuario}" />
</p:selectOneMenu>
<p:outputLabel value="Data Emprestimo: " for="dataEmprestimo" />
<p:calendar id="dataEmprestimo"
value="#{empMB.emprestimo.dataEmprestimo}" effect="fold"
navigator="true" required="true"
requiredMessage="Inserir uma data do emprestimo"
pattern="dd/MM/yyyy" title="Data do Emprestimo">
<f:convertDateTime pattern="dd/MM/yyyy" locale="pt_BR"
timeZone="America/Sao_Paulo" />
</p:calendar>
</h:panelGrid>
<h:panelGrid id="p2" columns="2" layout="grid">
<p:outputLabel value="Publicacao: " for="publicacao" />
<p:selectOneMenu label="Publicação:" id="publicacao" effect="fade"
filter="true" filterMatchMode="contains"
value="#{empMB.emprestimo.publicacao.publicacaoId}">
<f:selectItem itemLabel="Selecione uma publicação"
noSelectionOption="true" />
<f:selectItems value="#{pubMB.publicacoesDisponiveis}" var="pub"
itemValue="#{pub.publicacaoId}" itemLabel="#{pub.titulo}" />
<f:ajax listener="#{empMB.setlistPublicacao()}"
render="list_publicacao msgs publicacao" />
</p:selectOneMenu>
</h:panelGrid>
<h2 style="font-size: 1.9em; margin-top: 3%;">Publicações
selecionadas</h2>
<p:dataTable reflow="true" id="list_publicacao"
value="#{empMB.listPublicacaoDesejada}" var="pub"
emptyMessage="Suas publicações aparecerão aqui.">
<ui:include src="/colunasPublicacoes.xhtml" />
</p:dataTable>
</f:ajax>
</h:form>
</ui:define>
Method..
public Emprestimo inserir() {
System.out.println(getListPublicacaoDesejada().size());
try {
for (int i = 0; i < getListPublicacaoDesejada().size(); i++) {
Calendar dataPrevista = Calendar.getInstance();
dataPrevista.setTime(emprestimo.getDataEmprestimo());
dataPrevista.add(Calendar.DAY_OF_MONTH,
Integer.parseInt(JSFHelper.getExternalContext().getInitParameter("previsaoDevolucao")));
emprestimo.setFuncionarioEmprestimo("usuarioteste08");
emprestimo.setDataPrevistaDevolucao(dataPrevista.getTime());
emprestimo.getPublicacao().setPublicacaoId(emprestimo.getListPublicacao().get(i).getPublicacaoId());
emprestimoFacade.inserir(emprestimo);
}
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Emprestimo(s)", "realizado(s) com sucesso!");
RequestContext.getCurrentInstance().showMessageInDialog(message);
emprestimo = new Emprestimo();
return emprestimo;
} catch (DAOException e) {
e.printStackTrace();
FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, "Atenção", "Erro ao realizada emprestimo");
RequestContext.getCurrentInstance().showMessageInDialog(message);
return null;
}
}
This already I thank.
Thanks Mario for answering. Awesome it seems, but I’ve solved using this method, but thank you anyway.
– Gabriel Cardoso