3

i wanted to use the navigation-rule feature of my faces-config.xml (JSF 2.0) but I have some problems with it. I have three files (index.xhtml,index2.html,index3.xhtml) and they look like this:

   <!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:ui="http://java.sun.com/jsf/facelets"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

<f:loadBundle basename="resources.application" var="bundle"/>

<head>
    <title><h:outputText value="#{bundle['welcome.title']}" /></title>
</head>

<body>
<h3>1</h3>
<h:form>

<h:commandButton action="next2" id="nextpagelink" value="Next Link">Next</h:commandButton>
</h:form>
</body>
</html>

(index.xhtml, the others look similar with different actionnames and other h3-field)

My faces-config.xml has the following entries related to navigation-rules:

<faces-config
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">
    <application>
        <message-bundle>resources.application</message-bundle>
        <locale-config>
            <default-locale>en</default-locale>
        </locale-config>
    </application>

    <navigation-rule>
  <display-name>index.xhtml</display-name>
  <from-view-id>/index.xhtml</from-view-id>
  <navigation-case>
      <from-outcome>next2</from-outcome>
   <to-view-id>/index2.xhtml</to-view-id>
  </navigation-case>
 </navigation-rule>

 <navigation-rule>
  <display-name>index2.xhtml</display-name>
  <from-view-id>/index2.xhtml</from-view-id>
  <navigation-case>
      <from-outcome>next3</from-outcome>
   <to-view-id>/index3.xhtml</to-view-id>
  </navigation-case>
 </navigation-rule>


 <navigation-rule>
  <display-name>index3.xhtml</display-name>
  <from-view-id>/index3.xhtml</from-view-id>
  <navigation-case>
      <from-outcome>next1</from-outcome>
   <to-view-id>/index.xhtml</to-view-id>
  </navigation-case>
 </navigation-rule>
</faces-config>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>DemoProject</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
  </servlet-mapping>
</web-app>

However when i click on the link in the index.xhtml file nothing happens. I don't get to the next page index2.xhtml as I thought

Tim
  • 733
  • 5
  • 12
  • 19
  • 1
    Any reason you don't use implicit navigation without verbose XML config files? Btw: your problem lies somewhere else. The code shown as far looks fine. So either you aren't showing the minimum code which reproduces the same problem in **your environment** or you aren't running the code you think you're running. – BalusC Aug 17 '10 at 13:31
  • You mean declaring the link via h:outputLink? I could try this As far as the code is concerned: I tried the navigation code in my real project and it didn't work so I set up a new Dynamic Web Project in Eclipse with JSF 2.0, copied and renamed the generated index.xhtml file and set up the above navigation rules. Nothing more, nothing less. – Tim Aug 17 '10 at 13:44
  • 1
    No. Just ``. It'll implicitly go to `filename.xhtml`. For real assistance, you should provide the minimum code and environmental details which reproduces the problem. The above doesn't. It looks fine and should work fine. Maybe you've cut too much off from the *actual* code for posting here. You shouldn't do that. You might have unawarely fixed the problem with exactly that cutoff. – BalusC Aug 17 '10 at 13:51
  • I've now listed all the code above. It is just a real small demo project I've set up to test the navigation rules. No java-classes,css, ..exist in this project – Tim Aug 17 '10 at 14:48
  • 1
    Sorry, I still can't reproduce this. Only thing which I've changed is ripping off those resource bundle declarations since I don't have those files here and they are irrelevant to the problem. – BalusC Aug 17 '10 at 17:47

2 Answers2

9

There are a lot of reasons for commandlink/button navigation not working, the common ones being:

  1. h:form is missing.
  2. h:form is nested inside another h:form.
  3. Validation or conversion error has occurred.

There are more, but that's as far not relevant yet I think. The code in your question is not the actual code. It looks fine and should work fine (if you add the <html> tag with correct xmlns declarations).

If in vain, I suggest to debug the POST request. What JSF phases were entered/executed? What code got executed and what not?

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1

Try adding redirect to the navigation URL, eg. action="next2?faces-redirect=true" or a <redirect /> element to the navigation case. But basically h:commandLink is a POSTing component, not a GETting one. Better to use h:outputLink in this case IMHO.

egbokul
  • 3,944
  • 7
  • 36
  • 54
  • 1
    This won't fix the actual problem. It just turns POST into GET using PRG pattern. However, the POST/navigation apparently hasn't taken place at all, so there's already nothing to turn into a GET. – BalusC Aug 17 '10 at 13:28