I currently use mojarra javax.faces-2.2.8.jar and Apache Tomcat 6.0.26 Server.
I'm trying to add ajax behaviour to an input field(it's just for simplification).
Here is the simple facelets page(welcome.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:al = "http://xmlns.jcp.org/jsf/composite/AppearanceLibrary"
xmlns:h = "http://xmlns.jcp.org/jsf/html"
xmlns:ui = "http://xmlns.jcp.org/jsf/facelets"
xmlns:f = "http://xmlns.jcp.org/jsf/core">
<h:head/>
<h:body>
<h:form>
<h:outputLabel for = "login"
value = "login" />
<h:inputText id = "login" value = "#{authentication.submittedLogin}">
<f:ajax execute = "login" render = "out" />
</h:inputText>
<h:outputText id = "out" value = "#{authentication.submittedLogin}" />
</h:form>
</h:body>
</html>
Here is the HTML output:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"><head id="j_idt2"><script type="text/javascript" src="/JSFCars/javax.faces.resource/jsf.js.xhtml?ln=javax.faces&stage=Development"></script></head><body>
<form id="j_idt4" name="j_idt4" method="post" action="/JSFCars/welcome.xhtml" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="j_idt4" value="j_idt4" />
<label for="j_idt4:login">login</label><input id="j_idt4:login" type="text" name="j_idt4:login" onchange="mojarra.ab(this,event,'valueChange','j_idt4:login','j_idt4:out')" /><span id="j_idt4:out"></span><input type="hidden" name="javax.faces.ViewState" id="j_id1:javax.faces.ViewState:0" value="o5U6o+AhXUBnlwlaf5BbfJsXNxEe0OmBn+vyQUuLH1If1Hk802YaE1PT+ACraIlE+2rJMXEMJcDEgtaxMDURnPR0EFkR0Pdln4WoUMimfPxwbiCQCQcPfL+JDsPkyx+S6SvffiRyQFmz40B/lF5qtnt+AzzGhkYyuiuokiZVnJYv4hZBVhImLwKLm28dGvVh9qfnpnjngXm8cmAdIVULAY1sn1koFC2Bv702uBK0z9I6jHzMQFdPPCpBd5b+rri7R952i9cfi/CYGdcFSCq1yZGYL0s7E5Dshgaaikr5MVdJ4pRRQbiF60hypro+ZLavymy7G2pMukJNRaMhr7SxZffK13rGuCfpBXzXwdSeXZp2tMpWBhXJZ8gk/7rYzizmMgOTssZtj1inrPAgJdMSu2CJM2Q1xMV5wQSmSpU3bSHWdGknSMH4EGZsipKf8YCr3EsOSPD9khK8hlT5AmLm/iQ0j1xRHJny/6mIPJjVPPN/nD6AXBY+9bdt+SUPEKpT4u8in5ZulcG57t/9NUq/VA==" autocomplete="off" />
</form></body>
</html>
This is my deployment descriptor:
<?xml version = "1.0" encoding = "UTF-8"?>
<web-app xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
xmlns = "http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation = "http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id = "WebApp_ID"
version = "3.1">
<context-param>
<param-name>
javax.faces.STATE_SAVING_METHOD
</param-name>
<param-value>
client
</param-value>
</context-param>
<context-param>
<param-name>
javax.servlet.jsp.jstl.fmt.localizationContext
</param-name>
<param-value>
resources.application
</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<listener>
<listener-class>
com.sun.faces.config.ConfigureListener
</listener-class>
</listener>
<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>/welcome.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>welcome.xhtml</welcome-file>
</welcome-file-list>
</web-app>
Inside the browser's JavaScript console I got the message that this request http://localhost:8086/JSFCars/javax.faces.resource/jsf.js.xhtml?ln=javax.faces&stage=Development failed with 404(Not found). And as the result when I try to invoke the input field's ajax behaviour I get the following message: Uncaught ReferenceError: mojarra is not defined.
I'm aware that I should use <h:head> and <h:body>, otherwise the jsf.js wasn't included in first place. I've tried several browsers and the results were the same. Also I've tried the myfaces-core-2.0.2-bin jsf implementation.
I has found very similar question here. The problem was connected with the user defined filter which rejected the js request. But I
don't define any filters in the web deployment descriptor. Might there be any implicitly defined filter that blocks that request? Or are there any other ideas why something blocks that request?
Since the time I asked this question I installed "GlassFish Server Open Source Edition 4.1.2"
server and deployed the application on it(I included "javax.faces-2.2.8.jar" into project libraries,
but I think the server uses the internal "Mojarra 2.2.14" JSF implementation). As the way of testing
of the JSF implementation I tried using a template, a composite componet. <ui:composition>, <ui:define>
tags and custom library inclusion work as needed. authentication bean is created and perfectly initialized using faces-congig.xml. Then after it I removed everything not related to
the question and left only welcome.xhtml page. Again I got "404 Not found".
The solution is to remove everything connected to faces servlet from the web.xml.
The view of the rendered welcome.xhtml page after applying the solution
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/welcome.xhtml</url-pattern>
</servlet-mapping>
is very weird.... This would mean nothing but your welcome page is loaded via the Faces servlet. So the jsf.js which has an .xhtml extension in the name as well as you posted yourself isn't either. Fix the url pattern (or remove all the faces servlet references since the defaults are most often fine) and everything will work
Related
This question already has an answer here:
JSF returns blank/unparsed page with plain/raw XHTML/XML/EL source instead of rendered HTML output
(1 answer)
Closed 7 years ago.
I'm trying to follow this tutorial on jsf: https://netbeans.org/kb/docs/web/jsf20-intro.html
In the "Wiring Managed Beans to Pages" chapter you have to switch the HTML form element for an equivalent JSF HTML form component. But after I do so (simply commenting/uncommenting already present code) it isn't visible.
I've added xmlns:h="http://xmlns.jcp.org/jsf/html" to the html tag; I get no errors from the IDE; the form shows up in inspect element; I've also tried xmlns:h="http://java.sun.com/jsf/html" instead, but still nothing.
Here's my page:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="css/stylesheet.css" rel="stylesheet" type="text/css" />
<!--<h:outputStylesheet name="css/stylesheet.css" />-->
<title>Greeting</title>
</head>
<body>
<div id="mainContainer">
<div id="left" class="subContainer greyBox">
<h4>Hi, my name is Duke!</h4>
<h5>I'm thinking of a number
<br/>
between
<span class="highlight">0</span> and
<span class="highlight">10</span>.</h5>
<h5>Can you guess it?</h5>
<!-- <form action="response.xhtml">
<input type="text" size="2" maxlength="2" />
<input type="submit" value="submit" />
</form>-->
<h:form>
<h:inputText id="userNumber"
size="2"
maxlength="2"
value="#{UserNumberBean.userNumber}"/>
<h:commandButton id="submit" value="submit" action="response"/>
</h:form>
</div>
<div id="right" class="subContainer">
<img src="duke.png" alt="Duke waving" />
<!--<h:graphicImage url="/duke.png" alt="Duke waving" />-->
</div>
</div>
</body>
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">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</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>/faces/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
JSF-Tags like <h:form> and <h:inputText> being returned to the client (your browser) instead of being rendered as proper HTML are a sure sign that your whole setup is wrong. (A browser will duly ignore any tags that it doesn't understand, that's why you don't get to see any of the contents of the form.)
If you are mapping your URL pattern like so:
<url-pattern>/faces/*</url-pattern>
you should then remove the second welcome file entry
<welcome-file>index.xhtml</welcome-file>
because this can never work, because it does NOT match against the pattern, so the whole request is NOT processed by FacesServlet in which case the plain .xhtml file is served as-is!
(It even says so explicitly in the tutorial you are referring to, at the end of the "Adding JSF 2.x Support to a Web Application" section.)
I don't know how to continue, but I always get the "java.lang.RuntimeException: Cannot find FacesContext" for my new JSF 1.2 web application. I'm sure it's just some configuration I can't find.
The exception occurs with the first f: or h: tag. Already with the important <f:view> at the beginning.
My index.jsp
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<f:view>
<html>
<head>
<title>MyWebsite</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>
<body>
<div>MyContent</div>
</body>
</html>
</f:view>
My web.xml looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 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_2_5.xsd">
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jsp</param-value>
</context-param>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>720</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
And then I also have a faces-config.xml that should reference myBean I want to use afterward in the body of the page:
<?xml version='1.0' encoding='UTF-8'?>
<faces-config version="1.2"
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-facesconfig_1_2.xsd">
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
<managed-bean>
<managed-bean-name>myClassName</managed-bean-name>
<managed-bean-class>
com.company.className
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
What am I missing here?
java.lang.RuntimeException: Cannot find FacesContext
Thus, the JSF <f:xxx> and <h:xxx> tags are complaining that FacesContext cannot be found. The FacesServlet is the one responsible for creating the faces context. The faces servlet is invoked when the request URL matches its URL pattern, which is in your particular case *.jsf. So, when you open the index.jsp as http://localhost:8080/context/index.jsp, or are relying on the <welcome-file> setting, then you are not invoking the faces servlet and you would indeed get this exception.
You need to open the index.jsp as http://localhost:8080/context/index.jsf, or to set the welcome file entry to index.jsf in order to properly invoke the faces servlet, so that it can create the faces context which is required by the JSF components declared in the JSP page.
Note however that only fixing the welcome file isn't sufficient in this JSF 1.x + Tomcat environment. You also need to supply a physically existing, but completely empty index.jsf file next to the index.jsp file in the webcontent in order to fool Tomcat that index.jsf really exists as welcome file. It would otherwise show a 404 error because it checks the physical presence of the welcome file beforehand.
See also:
javax.faces.FacesException: java.lang.RuntimeException: Cannot find FacesContext
Unrelated to the concrete problem, I'm wondering why you're using JSP if you've apparently installed Facelets 1.x and registered its view handler. Facelets is far superior to JSP.
I am currently learning jsf. I have written A simple jsf application where my target is to navigate from one page to another page. However, I am unable to navigate at all.
In my code there are two jsp files; one is createcustomer.jsp and the other is viewCustomerDetails. After the user enters data in createcustomer.jsp and clicks on the button it should move to next page (where it will display entered data in previous page in this page).
Below is my code. Can anyone find where I'm going wrong?<
createCustomer.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%# taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%# taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<td>
<h1 style="background-color:blue;color:white;">Create a new Customer</h1>
</td>
</tr>
</table>
<f:view>
<table>
<tr><td>Name:</td><td><h:inputText value="#{customer.name}"></h:inputText></td></tr>
<tr><td>Address:</td><td><h:inputText value="#{customer.address}"></h:inputText></td></tr>
<tr><td>Phone Number:</td><td><h:inputText value="#{customer.phNumber}"></h:inputText></td></tr>
<tr><td>Email Address:</td><td><h:inputText value="#{customer.email_id}"></h:inputText></td></tr>
</table>
<table>
<tr><td></td></tr>
<tr><td></td></tr>
<tr><td><h:commandButton value="Create Customer" action="viewCustomerDetails" /></td></tr>
</table>
</f:view>
</body>
</html>
face-config.xml
<faces-config
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-facesconfig_2_0.xsd"
version="2.0">
<managed-bean>
<managed-bean-name>customer</managed-bean-name>
<managed-bean-class>com.app.view.Customer</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<navigation-rule>
<from-view-id>/createcustomer.jsp</from-view-id>
<navigation-case>
<!-- <from-action>#{customer.validate}</from-action> -->
<from-outcome>viewCustomerDetails</from-outcome>
<to-view-id>/viewCustomerDetails.jsp</to-view-id>
</navigation-case>
</navigation-rule>
</faces-config>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd" version="3.0">
<display-name>Customer</display-name>
<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>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<description>
This parameter tells MyFaces if javascript code should be allowed in
the rendered HTML output.
If javascript is allowed, command_link anchors will have javascript code
that submits the corresponding form.
If javascript is not allowed, the state saving info and nested parameters
will be added as url parameters.
Default is 'true'</description>
<param-name>org.apache.myfaces.ALLOW_JAVASCRIPT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>
If true, rendered HTML code will be formatted, so that it is 'human-readable'
i.e. additional line separators and whitespace will be written, that do not
influence the HTML code.
Default is 'true'</description>
<param-name>org.apache.myfaces.PRETTY_HTML</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.apache.myfaces.DETECT_JAVASCRIPT</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<description>
If true, a javascript function will be rendered that is able to restore the
former vertical scroll on every request. Convenient feature if you have pages
with long lists and you do not want the browser page to always jump to the top
if you trigger a link or button action that stays on the same page.
Default is 'false'
</description>
<param-name>org.apache.myfaces.AUTO_SCROLL</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
</web-app>
Apparently, based on your code snipplet you have no <h:form> tag defined. Components such as <h:commandButton> need to be defined inside of one to function properly. Encase the content of your <f:view> inside an <h:form> and try again.
I am new in JSF and EJB applications, hence I encounter problems even in the simple JavaEE applications. I am creating a simple JavaEE application in eclipse with JBoss with goal just to try some tags of JSF and the binding of them to Java Beans. I cannot find out why the following JSf code does not get nothing appear to the output page:
<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">
<f:loadBundle basename="resources" var="msg" />
<head>
<title><ui:insert name="pageTitle">Page Title</ui:insert></title>
<style type="text/css">
</style>
</head>
<body bgcolor="#ffffff">
<h:body>
<h:outputText value="#{hello.world}" />
<h:outputText value="TTT" />
</h:body>
</body>
</html>
Not only the value hello.world coming form Bean, but a simple text "TTT" does not appear as well. The code of the Bean is:
#ManagedBean
public class Hello {
final String world = "World";
/**
* Default constructor.
*/
public Hello() {
}
public String getWorld(){
return "Hello" + world;
}
}
The facelets-config.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<faces-config version="2.1" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xi="http://www.w3.org/2001/XInclude"
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-facesconfig_2_1.xsd">
<managed-bean>
<managed-bean-name>hello</managed-bean-name>
<managed-bean-class>com.al.jsftest.Hello</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config>
When I try the tag with a plain text, it comes out on the screen, but it does not work again with #{hello.world}, namely the binding to the Bean fails. As soon as I have a have I hint to how get the JSF tag give successfully output, I would appreciate hint regarding what I should take care of, in order to get the Bean bind to JSF?
UPDATE:
It seems to be the same problem with similar question, but my application is in Eclipse with JBoss, not in Netbeans with GlassFish. I add therefore my web.xml file, probably a modification in that is required, but I still cannot figure out it.
<?xml version="1.0" encoding="UTF-8"?>
<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_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>JsfTest</display-name>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<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>
You'll have to tell the server that your page should be loaded by the JSF-Servlet defined in your web.xml-file.
If I understand your sample right, you have a welcome file called index.xhtml which should be presented to the user with JSF by calling your website.
There is the problem:
All your pages won't be rendered by JSF unless you 'put them through' your defined JSF-Servlet.
Your servlet definition should look like this:
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern> /* !important */
</servlet-mapping>
And therefore you have two (there are more for sure :) ) ways to tell the server to load your page with the JSF-Servlet:
Tell your welcome-file to be loaded with the JSF-Servlet
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file> /* note the /faces/ prefix */
</welcome-file-list>
Extend your <url-pattern> inside the servlet-mapping
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
<url-pattern>*.xhtml</url-pattern> /*tell JSF to render all pages with xhtml-extension*/
</servlet-mapping>
Ther shouldn't be any difference between Netbeans+Glassfish and JBoss+eclipse but you should check if the JSF libraries are loaded by the server.
One last note:
You're configurating your Beans via faces-config.xml, that'll do the job but since JSF 2.x you're able to do the same inside your class via annotations, e.g.
#ManagedBean
#SessionScoped
public class TestBean {
// your stuff here
}
For me this is much easier and more readable.
Hope this helped, have Fun!
Edit:
After your comments I've tested your set-up: nothing wrong!
At first I've got an error because of the <f:loadBundle basename="resources" var="msg" /> which was not defined in my set-up but after deleting this line everything worked fine.
Nevertheless, I've made a small typo in my first list item so please check this again.
Your xhtml-skeleton looked fine for me and works in my test, so there shouldn't be anything wrong either.
Please check the following:
Are the JSF-libraries loaded either by the server or your application
Are there anymore Servlets defined inside your web.xml-file
What's the detailed error message
Cheers!
I created a new Dynamic Web Project and I added this time index.xhtml file using a "Blank Facelet Page" as template instead of "Common Facelet Page". I changed the url-pattern in my web.xml file as *.xhtml and it finally worked either by the full path name on the browser (\index.xhtml) or not. Following the same process with a "Common Facelet Page", I didn't manage to do it work. Strange.
I have also noticed, that after selecting "Common Facelet Page" and clicking next, a list of libraries appears and the user has the option to check some of them. I didn't check anything, maybe I should have.
I'm migrating from RF3.3.3, JSF1.2 and jboss 5 to JSF2/ RF4. We have a rich toolbar group with dropdown menus that is generated from a database table. I made the changes to web.xml, renamed the applicable components in the backing bean, but the toolbar will only show as text instead of dropdown menus and links.
web.xml:
<?xml version="1.0"?>
<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">
<context-param>
<param-name>org.richfaces.enableControlSkinning</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.enableControlSkinningClasses</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.resourceOptimization.enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>blueSky</param-value>
</context-param>
menu.xhtml - included in a template.xhtml with h:head and h:body tags:
<h:form id="mnMenu">
<rich:toolbar id="tb" >
<rich:toolbarGroup>
<s:link id="menuHomeId" view="/home.xhtml" value="Home" propagation="none"/>
</rich:toolbarGroup>
<rich:toolbarGroup binding="#{menuQueries.myBarGrp}" />
</rich:toolbar>
<!-- account for jsf bug? bug DOESN'T WORK -->
<rich:toolbar rendered="false"/>
<rich:toolbarGroup rendered="false"/>
<rich:dropDownMenu rendered="false"/>
<rich:menuGroup rendered="false"/>
<rich:menuItem rendered="false"/>
</h:form>
from backing bean - this method creates the toolbar group, it originally looked like this:
public HtmlToolBarGroup getMyBarGrp()
{
this.myBarGrp = new org.richfaces.component.html.HtmlToolBarGroup();
for (CtsPermissionHierarchyAltV each : this.getMainMenuList()) {
this.myBarGrp.getChildren().add(getDropDownMenu(each));
}
return this.myBarGrp;
}
I changed it to this, both generate the same output:
public UIToolbarGroup getMyBarGrp()
{
FacesContext ctx = FacesContext.getCurrentInstance();
this.myBarGrp = (UIToolbarGroup) ctx.getApplication().createComponent(ctx,
UIToolbarGroup.COMPONENT_TYPE, "org.richfaces.ToolbarGroupRenderer");
this.myBarGrp.setId("dynMenuGrp");
for (CtsPermissionHierarchyAltV each : this.getMainMenuList())
{
this.myBarGrp.getChildren().add(getDropDownMenu(each));
}
}
the getDropDownMenu and submenu methods are coded similarly.
I'm not getting any errors. FF firebug output for text that should be a dropdown menu looks like this:
<div id="mnMenu:Communications" class="rf-ddm-lbl rf-ddm-unsel ">
... more stuff
Pre-migration it looked like this:
<div id="mnMenu:Communications" class="rich-ddmenu-label rich-ddmenu-label-unselect">
... more stuff
Navigating through the firebug output I can see all the submenus - but they're all text references.
I see all my css files - they're showing up in body instead of head, but they're all there.
Did I miss something? What else can I check?
jboss 7.1.1 Seam 2.3.0 JSF2.1 RichFaces 4.2.2
Likely to be a resource problem. When you select one of the items in Firebug, do you see any matching CSS declarations (rf-ddm-lbl or rf-ddm-unsel)? Did you check for any 404 errors in using firebugs net tab?
BTW: CSS files should be referenced in the header.
Found the answer here. I needed to add
<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>
to web.xml. Not sure why it worked though, this solution is for containers using servlet2.5, and (as far as I know) I'm using servlet3.0.
claudegex your answer put me on the path to fix it - there actually were 404 errors. I'll mark this one correct after the bounty is over, you should get 1/2 of it.