• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Tim Cooke
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
  • Piet Souris
Bartenders:
  • Stephan van Hulst

Expression Language inside javascript file

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All!!

I need to use Expression Language inside external javascript file. I'm using JSF 2.0.

I need to use this because I have to use messages I18n at javascript file.

I tried to use the follow, but not works:



However the follow it works inside external css file:




I included both (file JS and CSS) using Primefaces:


can someone help-me?

thanks





 
Saloon Keeper
Posts: 28212
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Raphael!

I have doubts that your EL in your CSS file really works. At least if it's a real CSS file retrieved by a real URL.

Neither CSS nor JavaScript files should be processing EL for the simple reason that they don't pass through an EL processor. In modern-day JEE, there's a Unified EL subsystem and it will deal with EL in JSF View Definition Language and with plain JSPs, but it isn't applied to non-JEE resources. In part because running EL on something like a binary image file would be a disaster!

Your CSS also has another issue. The FacesContext is not a permanent or long-term object. It exists only for the duration of the request process for the URL. If that URL wasn't routed to the FacesServlet, the FacesContext won't exist for that request.

So the only way you could get EL to work in either js or css files would be to brute-force include them as part of the source of a JSF page. If they're fetched as distinct URLs (such as via the <LINK> element, they won't go through the EL processor.

Last, but not least, there's the addressability issue. JavaScript runs on the client. Your properties live on the server. So it takes more than just EL if you want general access to them.

The outputScript and outputStyleSheet elements are new to JSF2 and the documentation I've found for them is pretty vile and looks to be more for the benefit of the tag implementor than it is for people who are actually using the tag. But as far as I'm aware, these elements do NOT route their respective resources through the FacesServlet, they just generate JSF-friendly HTML. Primarily that means that the output URLs know about the servlet context path without making you supply it explicitly.
 
Raphael Guimenes
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello tim, thank you for your help.

But i'm doubt about your comments on p:outputScript and p:outputStylesheet.

I analysed the page rendered (html created by server) and i saw the follow:

Tags PrimeFaces:


Tabs Primefaces after rendered in the html:



Note that after rendered was created a link for the JSF resources. And same link was created for archive with extension xhtml and not with js

Because of this i belive that EL works inside this JavaScript and CSS (this i tested and it works).

What do you think?

Thank you again.
 
Tim Holloway
Saloon Keeper
Posts: 28212
198
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Those aren't PrimeFaces tags. Tags in the "h" namespace come from the Core JSF2 tagset.

But you're right. If it went to all the trouble of constructing an "xhtml" URL, it should be passing through something.

The one thing that doesn't ring quite true, however, is that an ".xhtml" URL doesn't get routed to the FacesServlet, normally. Instead, you'd request a ".jsf" URL and the FacesServlet would break it down, locate the .xhtml resource that matched the basename, and process that. So I'm not quite sure what's going on here. I need to try these critters myself. I missed hearing about them, and have been using the RichFaces equivalents, instead. Until JSF2 came out, that was the only way to do this kind of stuff, so that's what I've been coding.

Assuming that the JavaScript is going through the EL processor, the one caveat there is that the expansion will be done by EL, not dynamically. I doubt that it matters in your case, though.
 
and POOF! You're gone! But look, this tiny ad is still here:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic