11 Replies Latest reply on Jan 8, 2009 6:17 PM by Michael zazzali

    Richfaces and Facelets not working

    Michael zazzali Newbie

      I have tried a few different configurations and am unable to get facelets to work with my companies current application.

      I tried putting this in the web.xml

      <context-param>
       <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
       <param-value>com.sun.facelets.FaceletViewHandler</param-value>
       </context-param>

      When I do the above though my whole app fails to find any jsf files and I can't navigate to any pages.

      This is our web.xml without the view handler
      <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
       http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
       <display-name>trak</display-name>
      
      <!-- *********** W E L C O M E ****************************************************** -->
       <welcome-file-list>
       <welcome-file>index.jsf</welcome-file>
       </welcome-file-list>
      
      
      <!-- *********** J S F ************************************************************** -->
       <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>
      
       <login-config>
       <auth-method>BASIC</auth-method>
       </login-config>
      
       <context-param>
       <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
       <param-value>client</param-value>
       </context-param>
      
      <!-- *********** S P R I N G F R A M E W O R K *********************************** -->
       <context-param>
       <param-name>contextConfigLocation</param-name>
       <param-value>/WEB-INF/application-context-web.xml</param-value>
       </context-param>
      
       <listener>
       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
       </listener>
      
      <!-- *********** R I C H F A C E S ********************************************** -->
       <context-param>
       <param-name>org.richfaces.SKIN</param-name>
       <param-value>DEFAULT</param-value>
       </context-param>
       <filter>
       <display-name>RichFaces Filter</display-name>
       <filter-name>richfaces</filter-name>
       <filter-class>org.ajax4jsf.Filter</filter-class>
       </filter>
       <filter-mapping>
       <filter-name>richfaces</filter-name>
       <servlet-name>Faces Servlet</servlet-name>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
       <dispatcher>INCLUDE</dispatcher>
       </filter-mapping>
       <!-- Path to resource property files. -->
       <context-param>
       <param-name>resourcePath</param-name>
       <param-value>/WEB-INF/classes/resources</param-value>
       </context-param>
      
       <context-param>
       <param-name>customComCalGif</param-name>
       <param-value>/trak/pages/images/cal.gif</param-value>
       </context-param>
      


      And this is the include section of the jsf page I am working on
      <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
      <%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>
      <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
      <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
      <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
      <%@ taglib uri="http://com.comanche.web.components" prefix="jrc" %>


      As well as the a4j:include section
      <%-- -------------------- --%>
       <%-- Begin Wizard Content --%>
      
      
       <f:facet name="header">
       <h:outputText value="Using a4j:include for Wizard-like behaviour" />
       </f:facet>
      
       <h:form id="form1">
       <a4j:include viewId="/pages/proto/wstep1.xhtml" />
       </h:form>
       <%-- -------------------- --%>
       <%-- End Wizard Content --%>


      the wstep1.xhtml is the same one in the example code.
      The output then looks like this:
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:rich="http://richfaces.org/rich">
      
       <div style="position:relative;height:140px;width:500px">
       Test Text
       <h:panelGrid rowClasses="s1row" columns="3" columnClasses="wfcol1,wfcol2,wfcol3">
       <h:outputText value="First Name:" />
       <h:inputText id="fn" value="#{profile.firstName}" label="First Name" required="true" />
       <rich:message for="fn" />
      
       <h:outputText value="Last Name:" />
       <h:inputText id="ln" value="#{profile.lastName}" label="Last Name" required="true" />
       <rich:message for="ln" />
      
       <h:outputText value="Company:" />
       <h:inputText id="comp" value="#{profile.company}" label="Company" required="true" />
       <rich:message for="comp"/>
       </h:panelGrid>
       <div class="navPanel">
       <a4j:commandButton id="wizardNext" value="Next >>" style="float:right" action="next"/>
       </div>
       </div>
      </ui:composition>
      

      Also I noticed that If I do a regular include
      <%@ include file="/pages/proto/wstep1.xhtml" %>


      It outputs this
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:a4j="http://richfaces.org/a4j"
       xmlns:rich="http://richfaces.org/rich">
      
       <div style="position:relative;height:140px;width:500px">
       Test Text
       <table>
      <tbody>
      <tr class="s1row">
      <td class="wfcol1">First Name:</td>
      <td class="wfcol2"><input id="frmMain:fn" type="text" name="frmMain:fn" /></td>
      <td class="wfcol3"><span id="frmMain:j_id_jsp_1545479442_75"></span></td>
      </tr>
      <tr class="s1row">
      <td class="wfcol1">Last Name:</td>
      <td class="wfcol2"><input id="frmMain:ln" type="text" name="frmMain:ln" /></td>
      <td class="wfcol3"><span id="frmMain:j_id_jsp_1545479442_78"></span></td>
      </tr>
      <tr class="s1row">
      <td class="wfcol1">Company:</td>
      <td class="wfcol2"><input id="frmMain:comp" type="text" name="frmMain:comp" /></td>
      <td class="wfcol3"><span id="frmMain:j_id_jsp_1545479442_81"></span></td>
      </tr>
      </tbody>
      </table>
      
       <div class="navPanel">
       <input id="frmMain:wizardNext" name="frmMain:wizardNext" onclick="A4J.AJAX.Submit('j_id_jsp_1545479442_0','frmMain',event,
      {'parameters':{'frmMain:wizardNext':'frmMain:wizardNext'}
      ,'actionUrl':'/trak/pages/admin/bizRuleMgmt.jsf?javax.portlet.faces.DirectLink=true'} );return false;" value="Next >>" style="float:right" type="button" />
       </div>
       </div>
      </ui:composition>


      Thank you for any help you can give me.
      Hope I didn't give an overload of information to you.

        • 1. Re: Richfaces and Facelets not working
          Sergey Smirnov Master

           

          "ethnarch" wrote:

          ......
          And this is the include section of the jsf page I am working on
          <%@ taglib uri="http://richfaces.org/a4j" prefix="a4j" %>
          <%@ taglib uri="http://richfaces.org/rich" prefix="rich" %>
          <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
          <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
          <%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>
          <%@ taglib uri="http://com.comanche.web.components" prefix="jrc" %>

          ....


          Did you really include a section with JSP syntax into xhtml pages or this is just a typo in the post?



          • 2. Re: Richfaces and Facelets not working
            Michael zazzali Newbie

            Yes there is, I have never worked with jsf before and this was some existing code that I have been working on. The page has a file ending of .jsp.
            This is the doc type

            <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

            Which makes me think that it's xhtml even though the file ending is jsp. Currently they are not using facelets in the application at all I just added the library.

            If the taglibs should be done as xml namespaces then how should I fix the document.

            using something like this won't work because facelets is not working and it won't process the ui:composition tag correctly. It will just output it as text into the html.
            <ui:composition xmlns="http://www.w3.org/1999/xhtml"
             xmlns:ui="http://java.sun.com/jsf/facelets"
             xmlns:h="http://java.sun.com/jsf/html"
             xmlns:f="http://java.sun.com/jsf/core"
             xmlns:a4j="http://richfaces.org/a4j"
             xmlns:rich="http://richfaces.org/rich">













            • 3. Re: Richfaces and Facelets not working
              Michael zazzali Newbie

              Actually though after looking it up the taglib imports are completely valid in jsf so I believe this is correct. The a4j:include page is xhtml it's the same one that is provided in the online demo.

              • 4. Re: Richfaces and Facelets not working
                Sergey Smirnov Master

                It is good if you believe in completely validness of the taglib import. However, if you decide to use facelets, you need to avoid using JSP at all, because facelets do not support JSP in general.

                So far, I see you try to mix both JSP and XHTML syntax on the same page. This need to be corrected first.
                RichFaces work with JSP view handler as well as XHTML view handler. richfaces-demo uses facelets, so the XHTML is used in the examples.

                To avoid complexity with your fist example, try to create a simple facelets application without RichFaces. Refer the facelets doc for that. Then you can easly add the RichFaces part.

                • 5. Re: Richfaces and Facelets not working
                  Nick Belaevski Master

                  Hello,

                  I guess this:

                  <context-param>
                   <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
                   <param-value>.xhtml</param-value>
                   </context-param>
                  is a missing part.

                  • 6. Re: Richfaces and Facelets not working
                    Michael zazzali Newbie

                    SergeySmirnov-
                    It's not a jsp it's a JavaServerFaces page, and the taglib tag is valid on a "JavaServerFaces" page.

                    I would be fine with moving the whole page to xhtml or even using a simpler example. As I said before the configuration I currently have does not work. The facelets tags are not rendered.

                    For instance a ui:composition tag will render as ui:composition when I view the source from my browser.

                    JSF and XHTML should work together fine however when I insert the following code in web.xml.

                    <context-param>
                     <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
                     <param-value>com.sun.facelets.FaceletViewHandler</param-value>
                     </context-param>


                    it breaks all the other jsf pages and I get an error that it cannot find the page. This is the same across all pages in the application.

                    If I can get past this then I would gladly switch this whole page to xhtml.

                    nbelaevski---
                    Same as above I still receive the problem where the application can't find any pages I navigate to. Thanks for the suggestion. I am sure this is something ridiculously simple I am missing.


                    • 7. Re: Richfaces and Facelets not working
                      Ilya Shaikovsky Master

                      So after Nick's suggestion if this parts started to work:..?

                      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                       xmlns:ui="http://java.sun.com/jsf/facelets"
                       xmlns:h="http://java.sun.com/jsf/html"
                       xmlns:f="http://java.sun.com/jsf/core"
                       xmlns:a4j="http://richfaces.org/a4j"
                       xmlns:rich="http://richfaces.org/rich">
                      


                      And b.t.w. yes you could read in the guidelines that taglibs is valid for any java server faces page. But.. you should also take into consideration that this guidelines contains - "we will use samples based on JSP in this book". Facelets uses xhtml syntax in general. You could look through their guide for details. Without this point - your example will not works even without Rich Faces. It has no difference for RF framework if facelets or JSP used.

                      • 8. Re: Richfaces and Facelets not working
                        Michael zazzali Newbie

                        ilya_shaikovsky-

                        So after Nick's suggestion if this parts started to work:..?

                        no, my app is no longer able to find any of the jsp or jsf pages. Something is breaking which gives back a page could not be found error.


                        I think you might have touched on the problem. Is it possible to have some pages in the application be jsp and some of them be xhtml, or is it all or nothing?

                        I am going to do some more tests, I was getting an error at one point. With code similar to nick's suggestion.
                        The markup in the document preceding the root element must be well-formed

                        I am going to try converting a page to XHTML and hopefully the page begins working. This means we will have to convert the whole app to xhtml. I would be surprised if there is not a way to use both formats alongside of each other.

                        BTW, thanks for the help I feel like I have a place to start from now.

                        • 9. Re: Richfaces and Facelets not working
                          Michael zazzali Newbie

                          After adding these lines in the web.xml

                           <context-param>
                           <param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
                           <param-value>com.sun.facelets.FaceletViewHandler</param-value>
                           </context-param>
                           <context-param>
                           <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
                           <param-value>.xhtml</param-value>
                           </context-param>
                          

                          I get this error when going to the apps front page
                          HTTP Status 404 - /trak/index.jsf
                          
                          --------------------------------------------------------------------------------
                          
                          type Status report
                          
                          message /trak/index.jsf
                          
                          description The requested resource (/trak/index.jsf) is not available.
                          
                          
                          --------------------------------------------------------------------------------
                          
                          Apache Tomcat/6.0.14
                          


                          Then if I try to go directly to an xhtml page it finds the file but asks me to download it

                          This is what the downloaded file looks like which is the same as it is on the server.
                          <ui:composition xmlns="http://www.w3.org/1999/xhtml"
                          
                           xmlns:ui="http://java.sun.com/jsf/facelets"
                          
                           xmlns:h="http://java.sun.com/jsf/html"
                          
                           xmlns:f="http://java.sun.com/jsf/core"
                          
                           xmlns:a4j="http://richfaces.org/a4j"
                          
                           xmlns:rich="http://richfaces.org/rich">
                          
                           <div style="position:relative;height:140px;width:500px">
                           Test Text
                           <h:panelGrid rowClasses="s1row" columns="3" columnClasses="wfcol1,wfcol2,wfcol3">
                           <h:outputText value="First Name:" />
                           <h:inputText id="fn" value="#{profile.firstName}" label="First Name" required="true" />
                           <rich:message for="fn" />
                          
                           <h:outputText value="Last Name:" />
                           <h:inputText id="ln" value="#{profile.lastName}" label="Last Name" required="true" />
                           <rich:message for="ln" />
                          
                           <h:outputText value="Company:" />
                           <h:inputText id="comp" value="#{profile.company}" label="Company" required="true" />
                           <rich:message for="comp"/>
                           </h:panelGrid>
                           <div class="navPanel">
                           <a4j:commandButton id="wizardNext" value="Next >>" style="float:right" action="next"/>
                           </div>
                           </div>
                          </ui:composition>
                          


                          • 10. Re: Richfaces and Facelets not working
                            Jan Frederik Naujoks Newbie

                            First of all: your issue is NOT with richfaces, it is a misconfiguration of facelets, so this forum is not the correct place.

                            For a solution:

                            http://wiki.java.net/bin/view/Projects/FaceletsFAQ#How_do_I_use_Facelets_and_JSP_in

                            it explains how to use facelets and jsp in one application, which is, as far as I understand, what you try to achieve.

                            One brief note: do NOT register the facelets view handler in faces-config.xml as described in the FACELETS faq, use the context param in web.xml, otherwise: look at facelets faq.

                            btw: you may be using jsf pages as you call it, if you use jsp syntax it is still not xhtml compliant, and still a jsp.

                            From http://java.sun.com/javaee/5/docs/tutorial/doc/bnagy.html

                            "The JSP elements in a JSP page can be expressed in two syntaxes, standard and XML, though any given file can use only one syntax. A JSP page in XML syntax is an XML document and can be manipulated by tools and APIs for XML documents. This chapter and Chapters Chapter 7, JavaServer Pages Standard Tag Library through Chapter 9, Scripting in JSP Pages document only the standard syntax. The XML syntax is covered in Chapter 6, JavaServer Pages Documents."

                            In short: jsp with jsp syntax, even if jsf taglibs are used != xml != xhtml
                            facelets requires welformed x(ht?)ml.

                            I am just a bit above an amateur in regards of jsp/jsf, but you should not lecture the richfaces dev's on what is what, they probably know better as we.

                            • 11. Re: Richfaces and Facelets not working
                              Michael zazzali Newbie

                               

                              First of all: your issue is NOT with richfaces, it is a misconfiguration of facelets, so this forum is not the correct place.

                              Sorry for posting in the wrong place, I didn't even know what my problem exactly was. I did in fact originally think it was a problem with my richfaces and facelets configuration. As I said this is a first try for me.

                              For a solution:

                              http://wiki.java.net/bin/view/Projects/FaceletsFAQ#How_do_I_use_Facelets_and_JSP_in

                              Actually it was after ilya_shaikovsky and nick's suggestion I realized I was looking in the wrong place. Most of the problems that I and I am sure other people run into is with the terminology with a new technology. I didn't know what to ask.

                              I am just a bit above an amateur in regards of jsp/jsf, but you should not lecture the richfaces dev's on what is what, they probably know better as we.

                              I did not intend to lecture anyone. I only stated that taglib's can be used in a jsf page. If I offended sergey then I am sorry.

                              All in all thanks toeveryone for helping me get a little closer to a solution.