Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jsf linking to a view that uses a template

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>
like image 514
Frédéric Gobert Avatar asked Dec 27 '25 14:12

Frédéric Gobert


1 Answers

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:

  • When should I use h:outputLink instead of h:commandLink?
  • Communication in JSF 2.0 - Implicit navigation
like image 71
BalusC Avatar answered Dec 31 '25 19:12

BalusC



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!