I am using richfaces 4.0 final. I have a page where I am including another facelet using
<ui:include src="#{bean.selectedPage}" />
The String selectedPage is set on a button click. When button is clicked, the page is changed and panel surrounding the above code is re-rendered using "render" attribute. The facelet has a datatable. eg:
<rich:dataTable>
<f:facet name="header">
<rich:columnGroup>
<rich:column>
<h:outputText value="hello" />
</rich:column>
</rich:columnGroup>
</f:facet>
</rich:dataTable>
The css for this datatable is not included. Could someone help me resolve this issue ? I have added all required jars. This following is a snippet of my web.xml
<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.skin</param-name>
<param-value>blueSky</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>*.html</url-pattern>
</servlet-mapping>
The strange part is the skin is loaded for other components like <a4j:commandButton /> . Issues appear only for datatable.
I have faced this before. AFAIK, richfaces loads the CSS for components on demand. Since your page is loaded dynamically, Richfaces never loads the css cause it never knows. (mentioning hard coded page name,framework already knows what component's css to render,and so it does, as you mentioned in your comment).
The only solution I could find for this was to include a rich:dataTable in your parent page (i.e. the page in which you are including this facelet with <ui:include>) and set its style to display:none. This way the framework includes the rich:dataTable css before-hand.
I know its not a perfect solution, but I couldn't find a better one!
Related
This question already has answers here:
Set default home page via <welcome-file> in JSF project
(3 answers)
Closed 6 years ago.
I'm trying to let a welcome page displaying after running a dynamic web project.
When googling I found a lot of tutorials but I can't found the solution.
I share:
The structure of my project (I want that the page welcome.xhtml will displayed by default).
The file web.xml is:
<?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_3_0.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>HiSpring</display-name>
<welcome-file-list>
<welcome-file>welcome.xhtml</welcome-file>
</welcome-file-list>
<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>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</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>/faces/*</url-pattern>
</servlet-mapping>
</web-app>
Once clicking on HiSpring > Run As > Run on Server, I should have
This url: http://localhost:8080/HiSpring/faces/welcome.xhtml. However, I got http://localhost:8080/HiSpring/.
Could you please tell me what I missed; Thanks in advance.
According to your web.xml tomcat would look for /welcome.xhtml and has no clue that this might be in /faces/welcome.xhtml. The URL is fine (if welcome.xhtml is in /)
There might be a more elegant JSF version (I'm not much of a JSF guy) - some possible solutions that come to my mind would be
map the faces servlet to *.xhtml do remove the /faces/ part from path (you judge if this is proper JSF - comment if it's not and I'll remove this part)
create a separate explicit redirection, e.g. through a (stupidly simple) index.html (of course, declare index.html as another welcome file) like the following sample:
<html>
<head><title>Redirection</title>
<meta http-equiv="refresh" content="2;URL=/faces/">
<!-- 2 means 2 seconds delay. Change as you like -->
</head>
<body>
<p>redirecting to application. Click here if it doesn't work</p>
</body>
</html>
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 6 years ago.
When I go to http://localhost:8081/installer/index.xhtml via IE11 or Firefox45, I see only Setup Wizard and no JSF components. The HTTP status code is 200. I do not have any errors on Tomcat 7.
It is running without problem on JSF 1.2. I am only not sure about web.xml file.
Thanks in advance. Can you advise me what can be wrong, please?
EDITED
When I changed extension from .xhtml to .faces, I got an useful exception on Tomcat output, thanks.
Please check the servlet mapping in web.xml
<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>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
Now which url you are running like here servlet is called when i will run http://localhost:Port/Path/PageName.jsf but when i will try to run http://localhost:Port/Path/PageName.xhtml it will not work. Or I have to us like this http://localhost:Port/faces/Path/PageName.xhtml
What is the difference between creating .xhtml or .jsp .or .jsf for JSF pages
JSF Facelets: Sometimes I see the URL is .jsf and sometimes .xhtml. Why?
I need an editable drop down menu with rich faces. Here is my code.
<rich:select enableManualInput="true" defaultLabel="start typing for select">
<f:selectItem itemLabel="label1" itemValue="iv1"/>
<f:selectItem itemLabel="label2" itemValue="iv2"/>
</rich:select>
The above code does not display an editable drop down menu. It only displays an input text box with items listed below it. When I start typing in the text box, the list disappears.
Screenshot:
What is causing this problem? I tried this with richfaces 4.3.2 and 4.3.4. Both gave me same problem.
Turns out I had incorrect settings in web.xml. The following configuration works:
<context-param>
<param-name>org.richfaces.enableControlSkinning</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>classic</param-value>
</context-param>
I have a screen which is implemented in JSF2 and I have validations on some of the fields, and when an error appears for a field that has no
<h:message for="fieldName" />
it always appear on the end of the screen with no style
I want to hide the messages summary even if I don't handle those validations
I guess they are just warnings that you see when your project stage is set to Development.
In web.xml file, change:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
to:
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Production</param-value>
</context-param>
and the messages disappear.
It is a feature of JSF 2 that shows you diagnostic messages when you are on Development stage. Actually you should changed that value in web.xml only when you want to put the project in production.
I have a JSF project and I already have an index.xhtml page which is working fine. When I try to add another XHTML page, for some reason it is not connected to my session scoped managed bean. I add the code in my new page but it doesn't work like my index.xhtml. I even copy and pasted the code from index and it still does not work. Any thoughts?
Here is some of the code I have in my new page:
Amount: <h:inputText value="#{transactionBean.amount}" style="color: Yellow; background: Teal;"/>
Price <h:inputText value="#{transactionBean.pricePaid}" style="color: Yellow; background: Teal;"/
Here 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">
<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>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
You've mapped the faces servlet on /faces/* instead of *.xhtml. This means that you need to include /faces path in the URL to get the faces servlet to run.
So, you should not open the page by
http://localhost:8080/SharePortfolioJSF/companies.xhtml
but instead by
http://localhost:8080/SharePortfolioJSF/faces/companies.xhtml
Much better, however, is to just use *.xhtml as URL pattern of the faces servlet, so that you don't need to fiddle with virtual paths.
<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>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
(note that your <session-timeout> of 30 minutes is the default already, just remove it)
From the comments:
Your second page isn't processed by the faces servlet. Your url pattern for the faces servlet is /faces/*. So all requests must contain the prefix /faces in order to get processed by the servlet.
It should work if you call your page with the following URL:
http://localhost:8080/SharePortfolioJSF/faces/companies.xhtml