2
I created a JSF page with a client form, after saving client by pressing the sign up button. The object persisted in the BD, and consequently I would like you to change pages going to the index.xhtml
or clear form fields to continue registering customers.
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>
java customers.
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 am starting now with JSF porting if my code is wrong I am grateful for help to fix, but this code is working, persisting in the database correctly.
The problem is how to open another page or clear the inputtext
form after clicking the sign up button.
Anthony I use faces-config.xml. I implemented the "index" Return, it worked in parts because it reloaded the page to the index, but the url in the browser did not change, continued with the client registration url. Apparently just inflated html, but there was no page redirection
– Skywalker
Thanks for the documentation.
– Skywalker
Juarez, another of the many details of the navigation model. By default the JSF makes forward, to make redirect you need to declare this explicitly. With implicit navigation use
index?faces-redirect=true
, with explicit navigation use<redirect/>
.– Anthony Accioly
Thank you Anthony, problem solved, I used <redirect/> in faces-config.xml and returning the page Outcome in the insert method, and with this same solution I can make a redirect to the same page and the fields are clean. Thank you! is bone this JSF, I will kill myself in the documentation, grateful!
– Skywalker