I created a JSF page with a client form, after saving client by pressing the button register. The object persisted in the DB, and consequently I would like you to switch pages by going to index.xhtml
or clearing the form fields to continue to register clients.
cadastroCliente.xhtml
<form>
<!-- inputTexts referentes ao cliente. Aqui-->
<p:commandButton value="Cadastrar" id="cadastrar" ajax="false"
style="margin-top: 25px; margin-bottom:7px;"
action="#{clienteBean.inserir}">
</p:commandButton>
</form>
ClientBean.java
public void inserir(){
dataCadastro = new Date();
Session session = DAOHibernateUtil.getSessionFactory().getCurrentSession();
try{
session.beginTransaction();
if(!isCpfValido(session)){
FacesContext.getCurrentInstance().addMessage("cpfmessage", new FacesMessage(FacesMessage.SEVERITY_WARN,"CPF já cadastrado", "este CPF já esta sendo utilizado!"));
}else{
Cliente cliente = this;
session.save(cliente);
session.getTransaction().commit();
cliente = new Cliente();
}
}catch(RuntimeException e){
session.getTransaction().rollback();
}finally{
if(session.isConnected()){
session.close();
}
}
}
I'm starting now with JSF behaving if my code is wrong I'm grateful for help correcting, but this code is working by persisting in the database correctly.
The problem is like opening another page or clearing the inputtext
of the form after clicking the register button.