Pregunta

Im having some problems with redirections. Im using primefaces and JSF 2.1. The thing is that JSF 2.1 doesn't have navigations rules and searching for an answer i found that I can put "faces-redirect=true". The problem is that that doesnt worked and i dont know why. The browser keeps telling me "No se puede encontrar el caso de navegación coincidente del ID de vista '/Autenticacion/login.xhtml' para la acción {1}' con el resultado '{2}'" Something like i dont have a navigation case for "/Autenticacion/login.xhtml" for the first action with the second result. With JSF 2.1 does not create a faces-config.xml file i create it and I added the rule for that action but the problem persists.

These are my files:

LOGIN BEAN

@ManagedBean(name="controlLogin")
@SessionScoped
public class ControladorLogin implements Serializable{

   public String logIn(){
       //actions
       return "index" //algo tryed index.xhtml or index?faces-redirect=true
   }

PRIMEFACES COMMANDBUTTON

<p:commandButton action="#{controlLogin.logIn}" value="Loguearse" ajax="false"/>

I also try with a commandLink

<p:commandLink action="#{controlLogin.logIn}" value="Loguearse" ajax="false"/>

FACES-CONFIG.XML //IF IS NOT NECESARY I CAN DELETE IT

<navigation-rule>
    <from-view-id>/Autenticacion/login.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{controlLogin.logIn}</from-action>
        <from-outcome>index</from-outcome>
        <to-view-id>/index.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

So if anyone can help me to do this redirection...thanks!!

¿Fue útil?

Solución

Indeed, in JSF 2.x you don't have to define navigation rules. You don't need faces-config.xml at all, just in some special cases which are not covered with annotations (eg. custom ExceptionHandlerFactory).

Using return "index?faces-redirect=true" is completely fine. faces-redirect=true means that you redirect from one xhtml to another instead of default forward.

Difference between forward and redirect

In this case just make sure that your index.xhtml page is in the same directory as the page from which you try to access it.

Otherwise if the index page is located in another directory then you have to specify absolute path with forward slash / in the beggining like this: "/indexFolder/index?faces-redirect=true".

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top