9 Replies Latest reply on Mar 4, 2015 8:59 PM by shmu80

    ui:include does not working

    shmu80

      Hi,

       

      The ui:include is not working in my project. I was struggling with this since a week ago, and it just a starting of my project. Hopefully somebody may give me some advice.

      Thanks a lot.

       

      Below is my project file organization

      proj_arch.JPG

       

      Source code for main.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:f="http://java.sun.com/jsf/core"

            xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:rich="http://richfaces.org/rich" xmlns:a4j="http://richfaces.org/a4j"

            xmlns:c="http://java.sun.com/jsp/jstl/core">

       

          <h:head>

              <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

              <link href="./../resources/css/default.css" rel="stylesheet" type="text/css" />

              <link href="./../resources/css/cssLayout.css" rel="stylesheet" type="text/css" />

              <title>Testing</title>

          </h:head>

       

          <h:body>

              <h:outputStylesheet library="css" name="application.css" />

              <div id="top" class="top">

                  <ui:insert name="top">Top</ui:insert>           

                  <ui:include src="templates/template.xhtml" />

              </div>    

              <div class="left-menu">

                  <ui:include src="templates/include/sideNavi.xhtml" />

              </div>

              <div id="content" class="center_content">

                  <ui:insert name="content">Content</ui:insert>

              </div>

          </h:body>

      </html>

       

       

      sideNavi.xhtml

      <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html"

                      xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:a4j="http://richfaces.org/a4j"

                      xmlns:rich="http://richfaces.org/rich" xmlns:c="http://java.sun.com/jsp/jstl/core">

          <rich:panelMenu style="width:200px" itemMode="ajax" groupMode="ajax"

                          groupExpandedLeftIcon="triangleUp"

                          groupCollapsedLeftIcon="triangleDown"

                          topGroupExpandedRightIcon="chevronUp"

                          topGroupCollapsedRightIcon="chevronDown" itemLeftIcon="disc"

                          itemChangeListener="#{nav.updateCurrent}">

              <rich:panelMenuGroup label="Group 1">

                  <rich:panelMenuItem label="Item 1.1" name="Item_1_1" />

                  <rich:panelMenuItem label="Item 1.2" name="Item_1_2" />

                  <rich:panelMenuItem label="Item 1.3" name="Item_1_3" />

              </rich:panelMenuGroup>

          </rich:panelMenu>

      </ui:composition>

       

      When I run the project in tomcat 7, the display is same as below. While I view the source, the source code is able to refer to the file properly.

      display.JPG

      View Source for main.xhtml

      viewsource.JPG

       

      View source, click from the link templates/include/sideNavi.xhtml

      viewsource_sidenavi.JPG

        • 1. Re: ui:include does not working
          michpetrov

          Hi,

           

          your files are not going through the Faces servlet, you're not supposed to be seeing the components in the source code - all is supposed to be translated into HTML. What does your web.xml look like?

          1 of 1 people found this helpful
          • 2. Re: ui:include does not working
            shmu80

            This is my web.xml

             

            <?xml version="1.0" encoding="UTF-8"?>

            <web-app version="3.0" 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-app_3_0.xsd">

               

                <display-name>Test Project</display-name>

             

                <context-param>

                    <param-name>javax.faces.PROJECT_STAGE</param-name>

                    <param-value>Development</param-value>

                </context-param>

             

                <context-param>

                    <param-name>javax.faces.SKIP_COMMENTS</param-name>

                    <param-value>true</param-value>

                </context-param>

               

                <!-- Plugging the "Blue Sky" skin into the project -->

                <context-param>

                    <param-name>org.richfaces.SKIN</param-name>

                    <param-value>blueSky</param-value>

                </context-param>

             

                <!-- Making the RichFaces skin spread to standard HTML controls -->

                <context-param>

                    <param-name>org.richfaces.CONTROL_SKINNING</param-name>

                    <param-value>enable</param-value>

                </context-param>

               

                <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>*.jsf</url-pattern>

                </servlet-mapping>

                <servlet-mapping>

                    <servlet-name>Faces Servlet</servlet-name>

                    <url-pattern>*.xhtml</url-pattern>

                </servlet-mapping>

                <servlet-mapping>

                    <servlet-name>Faces Servlet</servlet-name>

                    <url-pattern>/faces/*</url-pattern>

                </servlet-mapping>

               

                <!-- Resource Servlet - serves static resources and resources for specific components -->

                <servlet>

                    <servlet-name>Resource Servlet</servlet-name>

                    <servlet-class>org.richfaces.webapp.ResourceServlet</servlet-class>

                    <load-on-startup>1</load-on-startup>

                </servlet>

                <servlet-mapping>

                    <servlet-name>Resource Servlet</servlet-name>

                    <url-pattern>/org.richfaces.resources/*</url-pattern>

                </servlet-mapping>

               

                <!-- Resource Mapping - resources will be served compressed and packed in production -->

                <context-param>

                    <param-name>org.richfaces.resourceMapping.enabled</param-name>

                    <param-value>true</param-value>

                </context-param>

             

                <session-config>

                    <session-timeout>30</session-timeout>

                </session-config>

             

                <welcome-file-list>

                    <welcome-file>faces/index.jsp</welcome-file>

                </welcome-file-list>

             

                <login-config>

                    <auth-method>BASIC</auth-method>

                </login-config>

             

            </web-app>

            • 3. Re: ui:include does not working
              michpetrov

              I don't think *.xhtml should be used for the servlet, try visiting the pages as .jsf instead of .xhtml

              1 of 1 people found this helpful
              • 4. Re: ui:include does not working
                shmu80

                After I modify the index.jsp to following code <jsp:forward page="templates/main.jsf" /> instead of <jsp:forward page="templates/main.xhtml" />.

                Now the page keep showing java.lang.NullPointerException.

                Appreciate if you can advice.

                Capture.JPG

                • 5. Re: ui:include does not working
                  michpetrov

                  JSP is not compatible with RichFaces 4, don't use that. Make main.jsf the welcome file.

                  • 6. Re: ui:include does not working
                    shmu80

                    It still return me Null Pointer Exception after I modify main.jsf as welcome file.

                    • 7. Re: ui:include does not working
                      shmu80

                      I refer to the sample code from showcase project provided by Richfaces. It is using page forward from index.jsp to index.xhtml, but it is working well.

                      I just wondering why my project will encounter this issue compare with the showcase project.

                      • 8. Re: ui:include does not working
                        michpetrov

                        Can you share the project? It might be easier to find the issue if I try to deploy it myself.

                        • 9. Re: ui:include does not working
                          shmu80

                          Hi,

                          It is working at this moment after I remove following code in web.xml.

                          <servlet-mapping>

                                  <servlet-name>Faces Servlet</servlet-name>

                                  <url-pattern>*.xhtml</url-pattern>

                              </servlet-mapping>

                           

                          Make main.xhtml as welcome file instead of main.jsf.

                          <welcome-file-list>

                                  <welcome-file>faces/templates/main.xhtml</welcome-file>

                              </welcome-file-list>

                           

                          I hope this is permanently fix my issue, and may not trigger some problem for my following development work.

                           

                          Thank you.