0

I'm having trouble with a JSF test application and PrimeFaces components, and can't find the error.

I started out with a template file (layoutTempl.xhtml) defined by:

....
<h:body>
    <p:layout fullPage="true" >
        <p:layoutUnit position="north" size="95" >
            <ui:insert name="menubar" >
                MenuBar
            </ui:insert>          
        </p:layoutUnit>          
        <p:layoutUnit position="west" resizable="false" size="250">
            <ui:insert name="tree" >
                ProjectTree
            </ui:insert>             
        </p:layoutUnit>
        <p:layoutUnit position="center">
            <ui:insert name="main" >
                MainContent
            </ui:insert>           
        </p:layoutUnit>
        <p:layoutUnit position="south" size="45">
            <ui:insert name="footer" >
                Footer
            </ui:insert> 
        </p:layoutUnit>
    </p:layout>       
</h:body>
....

This template is used in two pages (indexContent.xhtml):

....
<body>
    <ui:composition template="./layoutTempl.xhtml">
        <ui:define name="menubar">
            MenuBar
        </ui:define>
        <ui:define name="tree">
            Project Tree
        </ui:define>
        <ui:define name="main">
            <ui:include src="index.xhtml"/>
        </ui:define>
        <ui:define name="footer">
            Footer
        </ui:define>
    </ui:composition>
</body>
....

and (abcContent.xhtml):

....
<body>
    <ui:composition template="./layoutTempl.xhtml">
        <ui:define name="menubar">
            MenuBar
        </ui:define>
        <ui:define name="tree">
            Project Tree
        </ui:define>
        <ui:define name="main">
            <ui:include src="abc.xhtml"/>
        </ui:define>
        <ui:define name="footer">
            Footer
        </ui:define>
    </ui:composition>       
</body>
....

The included files index.xhtml contain:

....
<h:body>
    <ui:composition >
    Hello from BareTest
    <br /><br />
    <h:form id="myform">
        <p:selectOneMenu id="scroll2"
                         value="#{listTestBean.selectedMyObject}" >
            <f:selectItems value="#{listTestBean.myObjects}"/>
            <p:ajax event="change" listener="#{listTestBean.valueChanged}"/>
        </p:selectOneMenu>
        <br/><br/>
    </h:form>
    </ui:composition>
</h:body>
....

while abc.xhtml contains:

....
<h:body>
    <h2>We got at abc page!</h2>
    <br /><br />
    <h:form id="abcForm">
        <p>#{listTestBean.selectedMyObject}</p>
        <p:commandLink id="Ajax" ajax="true" action="indexContent?faces-redirect=false">  
            <h:outputText value="Main page (link)" />
        </p:commandLink>
    </h:form>
</h:body>
....

The request scoped managed bean listTestBean contains getter and setter methods and the valueChanged method. The valueChanged method holds:

....
try {
        FacesContext.getCurrentInstance().getExternalContext().redirect("abcContent.xhtml");
} catch (IOException ioe) {
    System.err.println("listTestBean.valueChanged: IOException");
}
....

which is basically a redirect to the abcContent page.

However, when I select an item from the selectItem component the abcContent.xhtml page is not rendered, with the specified layoutTempl?

That I don't understand at all, sorry! It's probably something trivial but I can't solve it!

Regards

g.verhaag
  • 139
  • 3
  • 11
  • Are you saying the page is rendered without the template or not rendered at all? Also what is the url pattern in you web.xml? – zulqarnain Jul 01 '13 at 11:39
  • It is rendered but WITHOUT the template! URL pattern looks like: `/faces/*`! – g.verhaag Jul 01 '13 at 11:43
  • Your page may not be seeing the template. Check the path and load the page directly and see. – zulqarnain Jul 01 '13 at 11:51
  • But why is the index page rendered correctly with the layoutTempl? When I add faces/ before `abcContent.xhtml..` the page is rendered correctly, but the GlassFish server now throws a waring `WARNING: JSF1015: Request path '/faces/abcContent.xhtml' begins with one or more occurrences of the FacesServlet prefix path mapping '/faces'`. – g.verhaag Jul 01 '13 at 12:36
  • Why the use of the `` tags in `abcContent.xhtml` ? – Eric C. Jul 01 '13 at 15:13
  • No idea, I took it from an example I use in another web application, in which this redirect from the bean works! – g.verhaag Jul 01 '13 at 15:25
  • Still having issues ? – Andy Jul 03 '13 at 03:48

4 Answers4

0

try

<p:commandLink ajax="false" action="indexContent?faces-redirect=false"> 

you don't need ajax for the redirect.

Przemek
  • 623
  • 2
  • 11
  • 24
  • take a look at this [JSF PrimeFaces p:commandLink won't redirect to new page?](http://stackoverflow.com/questions/4900531/jsf-primefaces-pcommandlink-wont-redirect-to-new-page) – Przemek Jul 01 '13 at 14:09
0

Please put the full relative url of the template and not template="./layoutTempl.xhtml". What this means is that load the template from the current directory. If the template and page is in the same directory just put the template name removing ./ Check out this templates tutorial:

http://www.mkyong.com/jsf2/jsf-2-templating-with-facelets-example/

zulqarnain
  • 1,695
  • 1
  • 16
  • 33
0

In abcContent.xhtml you have

<ui:define name="main">
    <ui:include src="abc.xhtml"/>
</ui:define>

but abc.xhtml is defined as

<h:body>
    <h2>We got at abc page!</h2>
    <br /><br />
    <h:form id="abcForm">
     ...
    </h:form>
</h:body>

with no <ui:composition>. You are using XHTML, if you provide bad markup then the JSF will not be interpreted correctly. If you are using an IDE you will not get a warning when you use ui:include. You can verify this yourself by opening the browser and clicking View Source Code on abcContent.xhtml. You will notice that some portion of the page still contain JSF code (e.g. h:body). Fix abc.xhtml and try again.

<h:body>
    <ui:composition>
        <h2>We got at abc page!</h2>
        <br /><br />
        <h:form id="abcForm">
         ...
        </h:form>
    </ui:composition>
</h:body>
Andy
  • 5,900
  • 2
  • 20
  • 29
0

This is a late response but in my experience, that happens when the file path is

"abcContent.xhtml"

instead of

"faces/abcContent.xhtml"

You could probably even test it out in the address bar of your browser.

Also, that doesn't mean your file is in a folder called "faces". It's just the url pattern specified in web.xml

myQwil
  • 442
  • 3
  • 11