OmniFaces CombinedResourceHandler does not combine JavaScript resources - jsf

I would like to use the OmniFaces CombinedResourceHandler to stream resources in one go.
I registered it in faces-config.xml without any additional configuration parameters as described in CombinedResourceHandler documentation.
While it works fine with CSS resources, it does nothing with JavaScript resources. Here are my tests:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com /jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:o="http://omnifaces.org/ui">
<h:head>
<title>CombinedResourceHandlerTest</title>
<h:outputStylesheet name="css/bootstrap-3.3.5/bootstrap.css"/>
<h:outputStylesheet name="css/main.css" />
<h:outputScript name="js/jquery/jquery.min.js"/>
<h:outputScript name="js/bootstrap-3.3.5/bootstrap.min.js"/>
</h:head>
<h:body>
<f:view>
<h2>CombinedResourceHandlerTest</h2>
</f:view>
</h:body>
Output:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="j_idt2">
<title>CombinedResourceHandlerTest</title>
<script type="text/javascript" src="/testApp/javax.faces.resource/js/jquery/jquery.min.js"></script>
<script type="text/javascript" src="/testApp/javax.faces.resource/js/bootstrap-3.3.5/bootstrap.min.js"></script>
<link type="text/css" rel="stylesheet" href="/testApp/javax.faces.resource/eNpLLi7WT8rPLykuKUos0DXWM9YzRfD1kouLa4BYPzcxMw_EAQCLpxEP.css?ln=omnifaces.combined&v=1480321351184">
</head>
Tried with attribute target="head":
<h:head>
<h:outputScript name="js/jquery/jquery.min.js" target="head"/>
</h:head>
...
Output: (scripts are completly missing):
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="j_idt2">
<title>CombinedResourceHandlerTest</title>
<link type="text/css" rel="stylesheet" href="/testApp/javax.faces.resource/eNpLLi7WT8rPLykuKUos0DXWM9YzRfD1kouLa4BYPzcxMw_EAQCLpxEP.css?ln=omnifaces.combined&v=1480321351184">
</head>
...
</html>
The scripts are also missing when i move them on the top of the body:
<h:body>
<h:outputScript name="js/jquery/jquery.min.js" target="head"/>
....
</h:body>
After a look into the source i also tried with
<o:deferredScript name="js/jquery/jquery.min.js"/>
After inspecting the output for this case, I saw that the combinend script only contains the first script in order and the console shows "ReferenceError: OmniFaces is not defined":
<body>
<script type="text/javascript">OmniFaces.DeferredScript.add('/testApp/javax.faces.resource/eNpLL81JLE7OsMoq1s8qLE0tqoRSermZeXpZxQDDagwa.js?ln=omnifaces.combined&v=0');</script>
</body>
And I noticed, that even jsf.js is not included when having the CombinedResourceHandler active. the browser console tells "mojarra is not defined".
What am I doing wrong? Thanks in advance!
My environment is: Mojarra 2.2.12, Omnifaces 2.5.1, Tomcat 8.

I reproduced a very similar issue last weekend. The cause boiled down to that Mojarra was initialized twice on a Tomcat 8 server and thus corrupted the one and other. You can confirm this by looking at the server log and notice that among others Mojarra version, OmniFaces version and PrimeFaces version are logged twice.
Please doubleverify if you have only one Mojarra instance and that you do not have the ConfigureListener entry in web.xml like below, as it's by default autoregistered already.
<!-- You MUST remove this one from web.xml! -->
<!-- This is actually a workaround for buggy GlassFish3 and Jetty servers. -->
<!-- When leaving this in and you're targeting Tomcat, you'll run into trouble. -->
<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>
See also:
Configuration of com.sun.faces.config.ConfigureListener
How to properly install and configure JSF libraries via Maven?

For anyone else who runs into this issue I was also running into this issue using Jboss EAP 7.1.
I accidentally had the OmniFacesCombinedResourceHandler declared in a faces-config.xml in a Web Fragment JAR and in the faces-config.xml of the web application itself. Having this declared twice caused the same symptoms as the issue listed above. Once I removed it from the webapp faces-config.xml it started working.
I raised the issue on the OmniFaces issues to possibly detect and raise an error if this situation occurs: https://github.com/omnifaces/omnifaces/issues/504

Related

QuickBooks Online API - Add Connect Button

I'm using JSF and When adding connect button to my index.html in Google Chrome as follows;
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ipp=""
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:p="http://primefaces.org/ui">
<f:view>
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<script type="text/javascript"
src="https://appcenter.intuit.com/Content/IA/intuit.ipp.anywhere.js">
intuit.ipp.anywhere.setup({
menuProxy: 'http://com.example/dispatch/BlueDotMenu',
grantUrl: 'http://com.example/dispatch/RequestOAuthToken' });
</script> </h:head>
</f:view>
</html>
I get the follwoing error;
The value of the attribute "xmlns:ipp" is invalid. Prefixed namespace bindings may not be empty.
Is there a namespace value I can use?
I've got a workaround for JSF here. Worked for me.
You need to rewrite a bit the JavaScript file that QBO provides for the button and menu functionality.
You can download it from here.
If you have implemented all the OAuth and stuff, then you just need to add the tags without 'ipp' prefix. Just insert like this:
<connectToIntuit></connectToIntuit>
<blueDot></blueDot>
No namespaces needed. JSF will just ignore unknown tag and the JS have the ability to insert html and events into it.
I've downloaded easyUI JS as well from here. Insert the JS-es you've downloaded like this:
<script type="text/javascript" src="#{request.contextPath}/js/jquery/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="#{request.contextPath}/js/intuit.ipp.anywhere.js"></script>
It is required to insert jQuery version not less than 1.4.4.
The last thing left is the call of 'setup' js-function:
<script>
intuit.ipp.anywhere.setup({
menuProxy: '#{request.scheme}://#{request.serverName}#{request.contextPath}/qb_blueDotMenu.jsf',
grantUrl: '#{request.scheme}://#{request.serverName}#{request.contextPath}/qb_requestToken.jsf'
});
</script>
where qb_blueDotMenu.jsf - is the servlet that render BlueDotMenu and
qb_requestToken.jsf - is the RequestTokenServlet that gets the OAuth request token like show in QuickBooks Sample App.
Let me know if you got questions.
This is probably late, but I had the same issue and solved it by displaying the ipp:connectToIntuit button with
<h:outputText value="#{bean.ippConnect}" escape="false" />

Can't loading css in JSF

I'm using the JSF 2.2. I can't add .css in my .xhtml page.
Code in .xhtml
<h:head>
<title>Login Page</title>
</h:head>
<h:body>
<h:outputStylesheet library="resources/css" name="style.css" id="cascade1"/>
Also I tried declare it into a <h:head> with the same result.
FireBug is seeing this resource but it is showing message:
Reload the page to get source for .../javax.faces.resource/style.css.xhtml;...
There is no need to use the library attribute:
<h:outputStylesheet name="css/style.css" />
This way, the JSF servlet expects the style.css file to be in /resources/css path.

Customising Richfaces skins in JBoss 7 through CSS overriding

In my richfaces 4.2.0 application, all the pages use the same template:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>MY APPLICATION</title>
<link href="/myapp/resources/css/stylesheet.css" rel="stylesheet" type="text/css"/>
</h:head>
<h:body class="form" >
<div id="page">
.....
</div>
</h:body>
The file stylesheet.css is used to define some global styles as well as to override some richfaces classes. My application uses automatic skinning (org.richfaces.enableControlSkinning = true) as well: in brief, stylesheet.css has been designed to override everything produced by RF which was not looking as desired.
Everything worked fine under JBoss 6 because the RF styles (ECSS) were imported before stylesheet.css and hence got overridden. Under JBoss 7 (EAP 6) happens exactly the contrary, so stylesheet.css has simply no effect.
Do you know if (and how :)) I could influence this behavior?
Thanks a lot
After making some researches on the Web I found out that a good practice should be to place the custom css (using h:outputStylesheet) at the end of the page (or better of the template). This way they are imported at the end of the head section of the generated HTML.
The only way I have found reliably to work is to add an !important behind each overridden RichFaces rule. But this is rather dirty.

JSTL c:forEach is not working in Facelets

I have a file called test.xhtml i am trying to access a hash map using foreach in Facelets, but it is not displaying key value pair my code is as follows. How is this caused and how can I solve it?
<html xmlns:c="http://java.sun.com/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title>JSTL Simple Conditional Execution Example</title>
</head>
<h:body>
<f:view>
<c:forEach var="nameMap" items="${specificationAutogege.details}">
<p> ${nameMap.key}</p>
</c:forEach>
</f:view>
</h:body>
Is it possible to use JSTL in Facelets?
The HTML output is rendered as follows:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core">
<head>
<title>JSTL Simple Conditional Execution Example</title>
</head>
<body>
<c:forEach var="nameMap" items="{Versnellingsk=A very long text come here, Kleur=ZWART Two, Model=3008, Carrosiere=5 deures MPV, A very long text come here=Date Here, BrandShoert=E, Type=3008 Hybrid4 2.0 HDi, Merk=Peugeot, Bowjaar=2011 Shortgate}" varstatus="true">
<p/>
</c:forEach>
</body>
</html>
xmlns:c="http://java.sun.com/jstl/core"
This JSTL XML namespace URI is specific to Facelets 1.x. JSF 2.x ships with Facelets 2.x which has a different JSTL XML namespace URI:
xmlns:c="http://java.sun.com/jsp/jstl/core"
Since JSF 2.2 new XML namespace domain was introduced to remove old sun.com domain.
xmlns:c="http://xmlns.jcp.org/jsp/jstl/core"
See also:
Our JSTL wiki page
Which XML namespace to use with JSF 2.2
The xhtml extension suggests you're using JSF2 rather than JSF, hence you need to switch from using the ${} notation to #{} notation.
Hope that helps.

ERROR: tag handler class for "rich:modalPanel" (org.richfaces.taglib.ModalPanelTag) was not found on the Java Build Path

I am trying richface 4. It seems tags class are not setting on JAVA build path. I am getting this error for all rich component: "ERROR: tag handler class for * (org.richfaces.taglib.*) was not found on the Java Build Path"
For a4j component also, for all component i am getting same error "The tag handler class for "a4j:" (org.ajax4jsf.taglib.html.jsp.) was not found on the Java Build Path"
For richface4, i performed following actoin:
1) Added following jars:
annotations-4.0.0.Final.jar
cssparser-0.9.5.jar
guava-r08-gwt.jar
guava-r08.jar
jsf-api.jar
jsf-impl.jar
richfaces-components-api-4.1.0.Final.jar
richfaces-components-ui-4.1.0.Final.jar
richfaces-core-api-4.1.0.Final.jar
richfaces-core-impl-4.1.0.Final.jar
sac-1.3.jar
commons-beanutils-1.8.3.jar
commons-collections-3.2.1.jar
commons-digester-2.1-sources.jar
commons-digester-2.1.jar
commons-discovery-0.4.jar
jhighlight-1.0.jar
jsf-facelets-1.1.14.jar
web.xml is default generated and NO new element is added. As it is not required to change in RF4 (which is required in RF3.3).
JSP file is
<?xml version="1.0" encoding="ISO-8859-1" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" version="2.0">
<jsp:directive.page language="java"
contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" />
<jsp:text>
<![CDATA[ <?xml version="1.0" encoding="ISO-8859-1" ?> ]]>
</jsp:text>
<jsp:text>
<![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
</jsp:text>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>TESTING</title>
</head>
<body>
<f:view>
<h:form>
<a4j:commandLink
value="Opss! I forgot password"
reRender="forgetPasswordPanel"
oncomplete="#{rich:component('forgetPasswordPanel')}.show()">
</a4j:commandLink>
</h:form>
<rich:modalPanel id="forgetPasswordPanel" autosized="true" width="380">
<f:facet name="header">
<h:outputText value="Reset Password"/>
</f:facet>
</rich:modalPanel>
</f:view>
</body>
</html>
</jsp:root>
i further investigated this issue and found that taglib(tld file) doesn't contain tag-class for many rich and a4j component and richFace4.1 jar does not have corrosponding java class for them (which is in richFaces 3.3 jars).
Am i missing some jars ? What else should i do to work with richface4 ?
You seem to be trying to upgrade a RichFaces 3.3 web application to RichFaces 4.1. You need to do many more changes than only replacing the JAR files. You can find the exact migration steps in their own documentation: RichFaces 3.3.x to 4.x migration guide.
For example, JSP is been deprecated and replaced by Facelets, you'd need to rewrite your JSPs to be XHTMLs. The <rich:modalPanel> is been replaced by <rich:popupPanel>, you need to find and replace all those tags accordingly. The reRender attribute is been replaced by update attribute. Etcetera. Also that jsf-facelets-1.1.14.jar which is of Facelets 1.x should be removed from the /WEB-INF/lib. JSF 2.x libraries already ships with the right Facelets 2.x implementation bundled.
See also:
Migrating from JSF 1.2 to JSF 2.0

Resources