JAWR overrides load of unbundled files - jawr

We are using JAWR to bundle CSS and Javascript. It has tremendously decreased the number of hits and bytes downloaded. However, we recently ran into a problem that caused css files that were not "under its control" to return a "not found" (404) code. We have a solution, but I'm wondering if there's a better one.
We defined a CSS bundle for the standard set of css files, and use to load it. We've also got a few non-standard css files, including a pair that define a "legacy" layout. They are loaded with . Finally, the JAWR servlet serving CSS was bound to the url-pattern "*.css" in web.xml. With this configuration, any request for a css file from a tag returned a 404 code. We were unable to find a combination of JAWR property settings that would fix the problem.
The solution we came up with was to modify the JAWR servlet configuration in web.xml, adding the "mapping" parameter:
<servlet>
<servlet-name>CssServlet</servlet-name>
<servlet-class>net.jawr.web.servlet.JawrServlet</servlet-class>
<init-param>
<param-name>configLocation</param-name>
<param-value>/jawr.properties</param-value>
</init-param>
<init-param>
<param-name>type</param-name>
<param-value>css</param-value>
</init-param>
<init-param>
<param-name>mapping</param-name>
<param-value>/jawrcss/</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
We changed the url-pattern for the CssServlet to "/jawrcss/*". With this change, css files loaded from the unmodified tags are not touched by JAWR. We lose JAWR's compression abilities for these files, though.
My guess is that in order to have JAWR properly process these files, we need to change the tags to tags, at which point JAWR's "orphan" processing will do the right thing. This is problematic for (at least) a couple of reasons. (1) We're using a shared code base and "cannot" modify some of the files because the others sharing those files aren't using JAWR. (2) Some files load css dynamically using JavaScript, and I don't see how to combine that with the JAWR support.
So, what is/are my question/s?
Is there a way to have JAWR handle (compress, at least) CSS files loaded from tags? (The main question.)
Is there a way to use JAWR with Javascript-loaded CSS?

For javascript loaded CSS (or JS for that matter), you can use JAWR's script loader(explained here - http://jawr.java.net/docs/plain_html.html). Keep in mind that there is a trade-off using script loader(last paragraph of above mentioned page describes that)
Regarding your question 1), by tags you mean which tags ? JSP tags ?

You can use the mapping <init-param> for the servlet, and bind the servlet to that url.
Example from the Jawr servlet documentation:
...
<servlet>
<servlet-name>JavascriptServlet</servlet-name>
<servlet-class>net.jawr.web.servlet.JawrServlet</servlet-class>
<init-param>
<param-name>configLocation</param-name>
<param-value>/jawr.properties</param-value>
</init-param>
<init-param>
<param-name>mapping</param-name>
<param-value>/jsJawrPath/</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
...
<servlet-mapping>
<servlet-name>JavascriptServlet</servlet-name>
<url-pattern>/jsJawrPath/*</url-pattern>
</servlet-mapping>

Related

<ui:include> tag in JSF 2.0 not working

I am pretty new to JSF and facelets programming, I have followed the instructions in this link How to include another XHTML in XHTML using JSF 2.0 Facelets? to use the <ui:include> tags but strangely i see that the <ui:include> is not working on the page. The tag is showing as is on the rendered xhtml page.(sreenshot attached). My guess it that the ui tag lib is not being picked up. but am not sure where to check.
My config: WAS 8.5 with stock apache myfaces JSF 2.0 implementation.
You need to make sure that the ui: XML namespace is declared in any parent element as follows:
<anyelement ... xmlns:ui="http://java.sun.com/jsf/facelets">
You also need to make sure that the FacesServlet is in webapp's web.xml being mapped on an URL pattern of *.xhtml, given that you attempted to open it directly on /login.xhtml.
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
The FacesServlet is namely the one responsible for among others parsing that XHTML document and producing the HTML output based on it.

Applying PrimeFaces theme only for one JSF page

We should apply primefaces theme for a jsf page
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>bluesky</param-value>
</context-param>
I want to apply for one page this primefaces theme.How to do this?
If you add it as a context-param, it will be used for all pages. This is what you need to do:
1 - Get the jar of the bluesky theme and extract it to a folder. We'll use these files later.
2 - In the 'resources' folder create a subfolder called "primefaces-bluesky".
3 - In this folder, copy the file theme.css from the theme and also the 'images' folder.
4 - In the page in which you want to use the theme, include the stylesheet <h:outputStylesheet library="primefaces-bluesky" name="theme.css" />

Upgrade to facelets - Myfaces 2.0, Tomahawk, ajax4jsf - Facelets pages don't render

I migrated a jsf1 project to jsf2.
The webapp is based on Myfaces 2.1.8 , Tomahawk20-1.1.13 and ajax4jsf-1.1.1 - running on Tomcat 7. It all works well so I wanted to upgrade part of the pages to facelets and plug in Primefaces too.
The problem is that facelets pages do not render if I use jsf core tags - browser displays blank page, no errors in the logs either.
If the page is pure xhtml it renders fine. I know that this happens if the Faces servlet does not work at all but with a mapping of *.jsf it should first look for the .xhtml pages, right?Any help will be appreciated.
It seems that facelets and ajax4jsf cannot coexist.
If your pages have a .xhtml extension your web.xml should contain something like:
<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>
If you have *.jsf as url-pattern and your pages have a .xhtml extension, it's obvious that the pages don't get rendered. In other words, the url-pattern must match the pages to be rendered.

Not able to apply custom css applied for rich:dataTable header class

I am working on sample project of JSF 2.0 with richfaces 4.Probelm is richfaces skin are not applied to the components.
i want to use custom css for HeaderClass of Richdatatable but i am not able to show that. only inbuilt css are applied to headers. even for columnClasses also if i used only single value like this : columnClasses="JspContentForDataTable , its not showing i have to do columnClasses="JspContentForDataTable,JspContentForDataTable,JspContentForDataTable,JspContentForDataTable" for each column.
web.xml :
<context-param>
<param-name>org.richfaces.skin</param-name>
<param-value>ruby</param-value>
</context-param>
<context-param>
<param-name>org.ajax4jsf.VIEW_HANDLERS</param-name>
<param-value>com.sun.facelets.FaceletViewHandler</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>disable</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.LoadStyleStrategy</param-name>
<param-value>None</param-value>
</context-param>
<context-param>
<param-name>org.jboss.jbossfaces.WAR_BUNDLES_JSF_IMPL</param-name>
<param-value>true</param-value>
</context-param>
Please correct if i am doing anything wrong.
Help me out thanks in advanced.
The main reason why your styles are not getting applied to the element/component is that the style sheets are loaded earlier and then over-written by the default styles, to include the styles at run-time you have to import your style-sheets using tag
Eg:-
<h:outputStylesheet library="css" name="style.css" />
Remember to include the declaration in the <h:head> tag of your page.
For more detailed descriptions on loading a css at run-time using refer this link
Including css using h:outputStyleet
Okay I think I found your fix try this, there seems to be some problem while applying the css to your custom datatable.
Include this statement in your base file or current page.
For any custom component you add include the basic rich tag you include in that component that's causing you some issue as an non rendered component and it would work out just fine.
Eg:- For your current custom tag the basic rich component you might be using is an rich:dataTable right so add this component with a rendered="false" in your file where you use the component.
Like <rich:dataTable rendered="false"/> this would fix your issue fingers crossed not certain about why this happens but this should fix the issue.

Welcome page in JSF

How can I use a JSF page as welcome file? The FacesServlet is mapped on *.jsf and the <welcome-file> is set to index.xhtml. However, it does not show the JSF components. I tried to set the <welcome-file> to index.jsf, but this results in a HTTP 404 error.
I'm using Tomcat 6.0 and JSF 2.1.
Just rename <welcome-file> entry of index.xhtml to index.jsf and create an empty index.jsf file next to index.xhtml to fool the container that the file actually exist.
Alternatively, you can also just get rid of the .jsf extension altogether and use .xhtml all the way. This can be done by changing <url-pattern> of FacesServlet from *.jsf to *.xhtml.
Adding it to your welcome-file-list like this:
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
Does work, but you'll need Tomcat 7.
Another approach which also works with Tomcat 6 is adding a file called index.jsp with the following contents:
<jsp:forward page="/index.jsf"/>

Resources