3

Hi this is my folder structure:

-Web Pages
 -WEB-INF
   -template.xhtml
 -gebruiker
   -index.xhtml
 -index.xhtml

and now I'm trying to link from index.html to gebruiker/index.xhtml

I do this as follows:

index.xhtml:

<h:form>
    <h:commandButton value="gebruiker" action="#{labelController.gebruiker()}"/> 
</h:form>

bean:

public String gebruiker(){
        return "gebruiker/index";
    }

And if I run this I get a IO.FileNotFoundException without any useful detail...

I know the problem is because the index.xhtml in gebruiker folder uses a template it looks like this:

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./WEB-INF/template.xhtml">

    <ui:define name="title">
        Project Label Configurator
    </ui:define>

    <ui:define name="body">
        GEBRUIKER PAGINA
    </ui:define>

</ui:composition>

When I use plain xhtml instead of composition tags, the mapping works.

Anyone knows why?

my web.xml:

<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>/faces/*</url-pattern>
    </servlet-mapping>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Frédéric Gobert
  • 188
  • 1
  • 2
  • 8

1 Answers1

2
template="./WEB-INF/template.xhtml"

Remove that period.

template="/WEB-INF/template.xhtml"

Otherwise it's looking for /gebruiker/WEB-INF/template.xhtml file. The period as 1st character stands for "start at current folder" while the slash as 1st character stands for "start at root".


Unrelated to the concrete problem, you seem to be implementing page-to-page navigation. I strongly recommend to use just GET requests for this, not POST requests. That's more SEO and user friendly.

<h:link value="gebruiker" outcome="gebruiker/index" />

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • You're welcome. As to the uninformative exception message; if I am not mistaken, a similar bug was fixed in one of the latest releases of Mojarra. Which version are you using? It's currently already at 2.1.4. – BalusC Nov 10 '11 at 22:07
  • Sry man thought I accepted it by clicking on "this answer is useful". Thanks for the tip btw, in class we learned to do it with post methods, but using method it's not only gonna be more user friendly, but I'll also have less kinda stupid methods in my managed bean :) – Frédéric Gobert Nov 11 '11 at 00:00
  • Ah, it's a course? Well, good luck. Hope that your teacher learns you the right things. – BalusC Nov 11 '11 at 00:06