Getting EL in a Javascript file uploaded by @ResourceDependency

I am using the @ResourceDependency annotation in the JSF component to add Javascript and CSS files to my JSF page.

In my Javascript file, I need to reference another resource file (the .swf file, which is located in META-INF / resources, as required by JSF). I tried putting the expression #{resource['swf:file.swf']} EL into my javascript code, but it will not be resolved.

For exapmle for the following JS file on the server:

 var instance = new JSClass(); instance.setResourceUrl("#{resource['swf:file.swf']}"); 

The browser receives:

 var instance = new JSClass(); instance.setResourceUrl("#{resource['swf:file.swf']}"); 

which is wrong.

As long as I put the same EL in the CSS file, it gets right. For the following CSS file on the server:

 .instance-css-class { background: url("#{resource['swf:file.swf']}") } 

The browser receives:

 .instance-css-class { background: url("/webapp/javax.faces.resource/file.swf.jsf?ln=swf") } 

This is exactly what I need, but in the JS file.

Obviously, I can use CSS as a workaround for the problem (create a DOM element, attach a CSS class to it, and then read and parse the required style property). But is there a more elegant way to achieve this? Is this a bug in the JSF library (I am using Mojarra 2.0.3 with Jboss 6.1), or is there a reason for this behavior?

Please note that the above code is part of the tag library, so workarounds like those cannot be used.


Change It seems like a CSS workaround is not possible, as I see no way to get the CSS attribute from the CSS file. Thus, any (working) workaround would be gladly accepted.

+7
source share
1 answer

BalusC answered a similar question in detail here . Although the first solution is the easiest to implement, I would recommend you go with the third, which, in my opinion, is the right way.

0
source

All Articles