Action on primefaces does not redirect me

3

Home page:

<?xml version='1.0' encoding='UTF-8' ?>
<!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://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    <h:head>
        <title>Facelet Title</title>
        <h:outputStylesheet library="css" name="index.css"/>
        <link href="./resources/css/GrowlInicioRed.css" rel="stylesheet" type="text/css"/>
        <link href="./resources/css/Tema.css" rel="stylesheet" type="text/css" />
    </h:head>
    <h:body>
        <div class="header">
            <h:form id="signup"
                    style="text-align: center; margin-left: 30%; margin-right: 30%;">
                <p:growl id="growl" globalOnly="true" showDetail="true" autoUpdate="true"/>

                <h:graphicImage value="imagenes/businessman223.png" width="50" height="50"/>
                <br></br><br></br>

                <p:messages autoUpdate="true"/>

                <h:panelGrid columns="2">
                    <p:outputLabel for="txtUsuario" value="Usuario"/>

                    <p:inputText id="txtUsuario" required="true" value="#{indexBean.usuario.nombre}"
                                 requiredMessage="Usuario obligatorio"/>

                    <p:outputLabel for="txtClave" value="Clave"/>

                    <p:password id="txtClave" required="true" value="#{indexBean.usuario.password}"
                                feedback="true"
                                promptLabel="Digite su contraseña Por Favor" weakLabel="Minimo"
                                goodLabel="Medio" strongLabel="Maximo" requiredMessage="Clave obligatoria"/>

                    <p:commandButton value="Iniciar Sesion" icon="ui-icon-key"                                 
                                     actionListener="#{indexBean.listenerBotonInicioDeSesion()}"
                                     process="@this txtClave,txtUsuario" 
                                     action="principal"/>
                </h:panelGrid>
            </h:form>
        </div>
    </h:body>
</html>

principal.xhtml

<?xml version='1.0' encoding='UTF-8' ?>
<!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://xmlns.jcp.org/jsf/html"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <title>Principal</title>
        <h:outputStylesheet library="css" name="index.css"/>
        <link href="./resources/css/GrowlInicioRed.css" rel="stylesheet" type="text/css"/>
        <link href="./resources/css/Tema.css" rel="stylesheet" type="text/css" />
        <script name="jquery/jquery.js" library="primefaces"></script>        
    </h:head>
    <h:body>
        <h:form style="width:400px;"id="Inicio-Modulo">
            <p:growl id="growl" globalOnly="true" showDetail="true"/>
            <h4>BIENVENIDO A MODULO SEFARCOL<p></p>
        </h:form>
    </h:body>
</html>
    
asked by Alexander Gil Tafur 12.04.2016 в 21:58
source

4 answers

1

Your code is correct, it is not necessary to implement a method in the Bean for action rather than to programmatically redirect it but that depends of your logic, however, I feel that you have not defined your navigation rules in your faces-config.xml .

You should use something like the following:

<navigation-rule>
     <from-view-id>/login.xhtml</from-view-id>
     <navigation-case>
           <from-outcome>principal</from-outcome>
           <to-view-id>/portal/index.xhtml</to-view-id>
            <redirect include-view-params="true"></redirect>
     </navigation-case>
</navigation-rule>

In fact, the way you use actionListener and action are the most advisable.

    
answered by 26.01.2017 в 15:50
0

The main problem is that your UICommand <p:commandButton> has ajax functionality by default. Disable this functionality via ajax="false" :

<p:commandButton value="Iniciar Sesion" icon="ui-icon-key"
    actionListener="#{indexBean.listenerBotonInicioDeSesion()}"
    process="@this txtClave,txtUsuario"
    action="principal" ajax="false" />

Likewise, it is better to use action instead of actionListener to execute the action of UICommand and return the result of your navigation as a result in the method. This would be like that.

Facelets code:

<p:commandButton action="#{indexBean.inicioSesion}" ... />

Java Code:

@ManagedBean
@ViewScoped
public class IndexBean {
    public String inicioSesion() {
        /* código para validar sesión del usuario */
        return "principal";
    }
}
    
answered by 13.04.2016 в 19:44
0

The correct thing in the cases of login, is first of all a <welcome-file-list> to the file web.xml , which will define the routes in case of login. If you are using Spring Security, at the beginning of the session you will be redirected to the first of the accessible routes of that list.

On the other hand, and following the hypothesis that you are using Spring Security it is not necessary to use the action attribute in the commandButton , but it is necessary to deactivate the ajax and change type to submit , leaving the following way:

    <p:commandButton value="Iniciar Sesion" icon="ui-icon-key"      
        actionListener="#{indexBean.listenerBotonInicioDeSesion()}"
        process="@this txtClave,txtUsuario" ajax="false" type="submit"/>

The action attribute depends on whether or not you use Spring Security as a security framework.

    
answered by 27.04.2016 в 01:43
0

It should work for you this way:

<p:commandButton action="#{beanManejado.accionRedireccionar}" value="Volver" />

And on your bean like this:

public String accionRedireccionar() {

    return "<carpeta_dentro_WEBINF>/pagina.xhtml?faces-redirect=true";

}
    
answered by 01.09.2016 в 15:58