0

I'm working on a little webtool for practice and navigation rules have been brought to my attention. So i looked at a couple of web tutorials and tried it myself and it's not working for me. It won't redirect to the desired page.

faces-config.xml (only the part that should matter)

    <navigation-rule>  
    <from-view-id>/kursleiter.xhtml</from-view-id>  
        <navigation-case>   
            <from-action>#{verifyCredentials.save}</from-action>
            <from-outcome>ok</from-outcome>   
            <to-view-id>/teilnehmer.xhtml?faces-redirect=true</to-view-id>  
        </navigation-case>  
</navigation-rule>

The class that returns the value for <from-outcome>

public class verifyCredentials() {
    public String save(Klasse klasse, Module modul) {
    //do some other stuff
    return "ok";
    }
}

When this commandLink ist pressed, the redirect should happen

<p:commandLink actionListener="#{verifyCredentials.save(klasse, modul)}">#{modul.modulnummer} </p:commandLink>

Now, this brings a couple of questions to me:

  1. Would i need to add /faces/ in the <from-view-id>?
  2. Couldn't i just simply return the link to the desired page in my class?
  3. Did i make any logical mistakes that i'm too blind to see?

Thank you in advance - Reteras

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Reteras
  • 89
  • 2
  • 10

1 Answers1

7

There are two mistakes.

First, you're here mixing implicit with explicit navigation.

<to-view-id>/teilnehmer.xhtml?faces-redirect=true</to-view-id>

The faces-redirect=true query string parameter is only for implicit navigation as used below:

public String save(Klasse klasse, Module modul) {
    // ...
    return "/teilnehmer.xhtml?faces-redirect=true";
}

Note that this does not require any XML configuration! The implicit navigation feature is new since JSF 2.0. Perhaps you were reading/focusing on JSF 1.x resources instead of JSF 2.x ones while learning JSF 2.x. Pay attention to the date and versions mentioned in the learning resource.

In case you really need to configure this redirect via explicit navigation in XML, use <redirect> instead.

<navigation-case>
    <from-action>#{verifyCredentials.save}</from-action>
    <from-outcome>ok</from-outcome>
    <to-view-id>/teilnehmer.xhtml</to-view-id>
    <redirect />
</navigation-case>  

Second, you're mixing actionListener with action.

<p:commandLink actionListener="#{verifyCredentials.save(klasse, modul)}">

The actionListener doesn't support returning a navigation outcome. Use action instead.

<p:commandLink action="#{verifyCredentials.save(klasse, modul)}">

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you but that didn't quite do it sadly. I forgott to mention that i am using 2 save-Methods. One with parameters and one without. Do i need to add those parameters in my navigation case to point to this specific method? – Reteras Jul 13 '15 at 09:59