Problem with CommandButton

0

I am creating an application using JAAS, Primefaces and JSF. I want to register a user in a database and I have a problem with the "Accept" button on the form which does nothing. I leave the code:

REGISTER VIEW

import com.mycompany.pfinalpsegrupo2.Usuarios;
import java.io.Serializable;
import java.util.logging.Logger;
import javax.annotation.ManagedBean;
import javax.enterprise.context.SessionScoped;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.event.ComponentSystemEvent;
import javax.inject.Inject;
@ManagedBean
@SessionScoped

public class RegisterView implements Serializable {
 String nombre;
 String email;
 String password;
private String confirmPassword;
@Inject
private UsuarioEJB EJB;
private static final Logger log = Logger.getLogger(RegisterView.class.getName());
    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getconfirmPassword() {
        return confirmPassword;
    }

    public void setconfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    public void validarPassword(ComponentSystemEvent event) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        UIComponent components = event.getComponent();
        UIInput uiInputPassword = (UIInput) components.findComponent("password");
        String password = uiInputPassword.getLocalValue() == null ? "" : uiInputPassword.getLocalValue().toString();
        UIInput uiInputConfirmPassword = (UIInput) components.findComponent("confirmpassword");
        String confirmPassword = uiInputConfirmPassword.getLocalValue() == null ? "": uiInputConfirmPassword.getLocalValue().toString();

        if (password.isEmpty() || confirmPassword.isEmpty()) {
            return;
        }
        if (!password.equals(confirmPassword)) {
            FacesMessage msg = new FacesMessage("Las contraseñas no coinciden");
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
            facesContext.addMessage(uiInputPassword.getClientId(), msg);
            facesContext.renderResponse();
        }
        UIInput uiInputEmail = (UIInput) components.findComponent("email");
        String email = uiInputEmail.getLocalValue() == null ? "" : uiInputEmail.getLocalValue().toString();
        if (EJB.findByEmail(email) != null) {
            FacesMessage msg = new FacesMessage("Ya existe un usuario con ese email");
            msg.setSeverity(FacesMessage.SEVERITY_ERROR);
            facesContext.addMessage(uiInputPassword.getClientId(), msg);
            facesContext.renderResponse();
        }
    }
    public String register() {
        Usuarios user = new Usuarios(email,password,nombre);

        EJB.createUser(user);
        log.info(" Email " + email +"Nombre: "+ nombre);
        return "confirmareg";
    }

}

CONFIRMAREG

<body>

    <ui:composition template="./WEB-INF/Template.xhtml">

        <ui:define name="content">
           <h3>Cuenta creada</h3>
         <br/><br/>
         <p:link value="Accede con tu nueva cuenta" outcome="login"/>
        </ui:define>

    </ui:composition>

</body>

Form

<body>

    <ui:composition template="./WEB-INF/Template.xhtml">

        <ui:define name="content">
          <h:form>
              <f:event listener="#{registerView.validarPassword}" type="postValidate" />
              <p:panel header="Crear una nueva cuenta">
                  <h:panelGrid id="grid" columns="3">
                      <h:outputLabel for="nombre" value="Nombre:" style="font-weight:bold"/>
                      <p:inputText id="nombre" value="#{registerView.nombre}" required="true"
                                   requiredMessage="Introduzca nombre y apellidos." maxlength="30"/>
                      <p:message for="nombre"/>
                      <h:outputLabel for="email" value="E-Mail:" style="font-weight:bold"/>
                      <p:inputText id="email" value="#{registerView.email}" required="true"
                                   requiredMessage="Introduzca su email."/>
                        <!--  <f:validator validatorId="emailValidator" />
                      </p:inputText>
                        -->
                      <p:message for="email"/>

                      <h:outputLabel for="password" value="Contraseña:" style="font-weight:bold"/>
                      <p:password id="password" value="#{registerView.password}" feedback="true"
                                  required="true" requiredMessage="Introduzca su contraseña."
                                  validatorMessage="La contraseña debe contener al menos un número,
                                 así como caracteres tanto en mayúscula como en minúscula, además de 
                                 contar con una longitud comprendida entre 6 y 20 caracteres alfanuméricos">
                          <f:validateRegex pattern="((?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{6,20})" />
                      </p:password>
                      <p:message for="password"/>
                      <h:outputLabel for="confirmpassword" value="Confirmar contraseña:" style="font-weight:bold"/>
                      <p:password id="confirmpassword" feedback="true"
                                  value="#{registerView.confirmPassword}" required="true"
                                  requiredMessage="Por favor, confirma tu contraseña."/>
                      <p:message for="confirmpassword"/>
                  </h:panelGrid>

                  <p:commandButton value="Registrarse" action="#{registerView.register}" ajax="false"/> 

              </p:panel>
          </h:form>

        </ui:define>

    </ui:composition>

</body>

Thanks in advance

    
asked by Iskandarina 10.05.2018 в 17:58
source

0 answers