1

I cannot find out how navigate to page located in upper dir. Is it possible at all? here is my project structure:

enter image description here

question: how should line <ui:composition template="web2/web/index.xhtml"> looks like in the code of any page from folder main_pages to include index.xhtml and how to insert i.e. image from images folder (I can't get right path, io.exception still): onas.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!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:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      >
    <h:body>

        <ui:composition template="web2/web/index.xhtml">

            <ui:define name="centerContent">
                    <h:form>
                        <p:growl id="msg" showDetail="true" sticky="true" />
                        <p:panelGrid styleClass="myPanel">
                            <p:row>
                                <p:column>
                        <ui:param name="mainTag" value="Z chęcią odpowiemy" />
                <h2>Zapytaj</h2>
                        <h4>#{mainTag}</h4></p:column>
                            </p:row>
                            <p:row>
                                <p:column><p:inputTextarea styleClass="myTextArea" autoResize="true" value="#{mySendBean.mailContent}"/></p:column>
                                <p:column>
                        <h:commandButton actionListener="#{mySendBean.sendMail2()}" value="Wyślij" update="msg">
            </h:commandButton>
                                    </p:column>
                            </p:row>
                        </p:panelGrid>
                    </h:form>
            </ui:define>


        </ui:composition>

    </h:body>

</html>

when I change composition to be:

<ui:composition template="#{request.contextPath}/index.xhtml">

I get error:

/onas.xhtml @11,74 <ui:composition template="#{request.contextPath}/index.xhtml"> Invalid path : /web2/faces/index.xhtml

or if I add /faces/:

/onas.xhtml @11,74 <ui:composition template="#{request.contextPath}/faces/index.xhtml"> Invalid path : /web2/faces/index.xhtml
4pie0
  • 27,469
  • 7
  • 70
  • 110

1 Answers1

3

All paths in <ui:xxx> components are absolute to the webcontent root, which is the "Web Pages" folder. Also, you should prefer using absolute paths starting with / instead of relative paths.

So, this should do:

<ui:composition template="/index.xhtml">

The #{request.contextPath} is only necessary when you want to manually create an URL (for the enduser). The /faces is only necessary when you want to invoke the JSF mapping on it.

See also:


Unrelated to the concrete problem, it's recommended to put template files in /WEB-INF folder to prevent direct access.

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • tahnk you very much. I have changed it to be in my subpage, then it is load from main page, from menu and put into center content. however it looks like loading this page influences main page, because for example there is no css (that is still if I load subpage not from main_pages folder but from there where index is) and for example pictures are missing (which are declared in main page (index template) not in composition, how could it be? – 4pie0 Apr 16 '13 at 17:49
  • You're welcome. As to your new question: http://stackoverflow.com/questions/8367421/how-to-reference-resource-in-facelets-template/8368727#8368727 If you still stucks on that, please press `Ask Question` button. This is offtopic to the currently asked question. – BalusC Apr 16 '13 at 17:54