JSF 2 and Resource Servlet question

UI Components for JSF
User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

14 Jan 2010, 12:13

Hello,

Do we need for JSF 2 and PrimeFaces 2.0.0-SNAPSHOT the below fragments from GettingStarted?

Code: Select all

 <servlet>  
     <servlet-name>Resource Servlet</servlet-name>  
     <servlet-class>  
         org.primefaces.resource.ResourceServlet  
     </servlet-class>  
 </servlet>  
  
 <servlet-mapping>  
     <servlet-name>Resource Servlet</servlet-name>  
     <url-pattern>/primefaces_resource/*</url-pattern>  
 </servlet-mapping> 

Code: Select all

 <head>  
     <p:resources />  
 </head> 
I use Mojarra 2.0.2.

Best regards.
Oleg.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

14 Jan 2010, 12:53

In current PrimeFaces-2.0.0-SNAPSHOT iteration, Resource Servlet is required, p:resources is not.

Code: Select all

<h:head>
</h:head>
is enough to place resources so no need for p:resources. I've also tried to migrate ResourceServlet but JSF2's resource loader can't load css referenced images in PrimeFaces. So if css in jar has;

Code: Select all

background: (url:'image.gif');
background: (url:'../../image.gif');
it can't load it whereas PrimeFaces Resource Servlet can which is quite flexible for us to go on with.

In a servlet 3.0 environment like glassfish3, PrimeFaces Resource Servlet is auto registered, so no need to define explicitly.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

14 Jan 2010, 14:58

Yes, for css referenced images we need a servlet.

If we use JSF 2 resource loading style like

Code: Select all

<h:outputScript library="js" name="my.js" target="head"/>
what it will be handled by? I guess, by JSF 2 ResourceHandler and not by your Servlet because you can simple check url pattern ".../javax.faces.resource/...", ignore such request and give so control to ResourceHandler. Right?
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

14 Jan 2010, 15:43

Those will be handled by FacesServlet, PrimeFaces only loads it's own resources but uses JSF 2 APIs to place them on page using h:head.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

14 Jan 2010, 15:50

cagatay.civici wrote:Those will be handled by FacesServlet, PrimeFaces only loads it's own resources but uses JSF 2 APIs to place them on page using h:head.
Yes, I have understood that. You have /primefaces_resource/* servlet-mapping.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

14 Jan 2010, 16:11

Cagatay,

If you write for your images in components default css

Code: Select all

background (url: '.../javax.faces.resource/image.gif.jsf');
then it should work without your ResourceServlet. I don't see here any problems. You should include "/javax.faces.resource/" befor image name and ".jsf" at the end. That's all.

Clear, that is uncomfortable write styling in custom css for us, developers, but would be an alternative way for image references.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

14 Jan 2010, 16:20

Even better I could have used;

Code: Select all

background (url: '#{resource['yui/assets/images/image.png']}');
Problem is there are almost one hundred references like this and if we update any javacript library version, we have to do this all over again. I've spent two full days on this issue and could not find a way without changing css. So we'll stick with our resource servlet for now.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

15 Jan 2010, 10:18

Hi Cagatay,

I didn't understand that with javascript updates. What is the difference between

Code: Select all

background (url: 'yui/assets/images/image.png');
and

Code: Select all

background (url: '#{resource['yui/assets/images/image.png']}');
? If path or image name have been changed you have to adjust css in both cases.

- Oleg.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

15 Jan 2010, 16:21

When loading a css, JSF2 parses #resource stuff and replaces it with actual url.

Code: Select all

background (url: '#{resource['yui/assets/images/image.png']}');
becomes something like;

Code: Select all

background (url: '/contextPath/javax.faces.resources/yui/assets/images/image.png.jsf');
We can't change every single css as approximately there're 100+ references like these in compressed one line css files of yui, jquery and primefaces widgets. I've tried that and gave up as other problems occured.

Some jquery plugins like fileupload, uses javascript to point to a resources so it's even worse.

We don't have these problems with PrimeFaces as no css change is required to make things work.

User avatar
Oleg
Expert Member
Posts: 3805
Joined: 02 Oct 2009, 09:41
Location: Germany, Black Forest

15 Jan 2010, 23:00

Yes, I'm aware of JSF 2 replacement of #resource... I thought you have already changed all css referenced images (and maybe JS referenced) by adding /primefaces_resource/. Because they must somehow go through your servlet. So, and I thought you could replace now /primefaces_resource/ by /javax.faces.resources/ and add .jsf. :-)

In reality we are happy of course with ResourceServlet. No problem.
PrimeFaces Cookbook (2. edition): http://ova2.github.io/primefaces-cookbook/ Learning Angular UI Development with PrimeNG: https://github.com/ova2/angular-develop ... th-primeng Blog: https://medium.com/@OlegVaraksin

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 41 guests