-
1. Re: loadScript question
sergeysmirnov Apr 16, 2008 5:56 PM (in response to mars1412)Your first statement is correct. The description of the second one sounds too limited.
Why only in the richfaces jars? Anyone. However, if I say "from any jar", it will be a limited description as well.
If you have /js/myjavascript.js in your webroot,
src="resource:///js/myjavascript.js" will work as well as src="/js/myjavascript.js".
The webroot is on of the place where resource:// takes resource from.
You can use "resource://" not only with a4j:loadScript or a4j:loadStyle. Any JSF components that have an attribute with path to resource are suitable.
For example:
<h:graphicImage value="resource:///images/foo.gif" /> takes the picture as well as <h:graphicImage value="/images/foo.gif" />
Sure, it is not the miracle. However, you can NOT say:
<h:graphicImage value="/WEB-INF/secretStore/images/bar.gif" />
<h:graphicImage value="resource:///WEB-INF/secretStore/images/bar.gif" /> will work
resource:// locates resources in the classpath
So, if you want to store your pictures in the jar file or/and in the WEB-INF/classes, you can do it. Just use resource:// to access to them.
What if you want to create image dynamically from the java class?
resource:// allows to have an access to it.
For example, if your class com.mycompany.graphic.UniChart.java implements InternetResource interface, you can say:
<h:graphicImage value="resource://com.mycompany.graphic.UniChart" /> to draw something excited dynamically and put down on the page. -
2. Re: loadScript question
mars1412 Apr 17, 2008 4:43 AM (in response to mars1412)wow! - thanks for the detailed answer.
maybe this should go into the docs.
I now understand what went wrong in my case:
I tried to use http://tinymce.moxiecode.com/ in my project.
I tried to load the tinyMCE javascript like this:<a:loadScript src="resource:///tiny_mce/tiny_mce.js" />
which does not work as expected.
problem is, that the tiny_mce.js tries to get the baseURL of the script and then load some additional java-script resources (plugins, langpack, ..)
when I use resource, the base url will be smth. like this:http://localhost:8080/twentyfouract/a4j_3_2_0.SR1-SNAPSHOTtiny_mce
and thus, tinyMCE tries to load additional resources like this:http://localhost:8080/twentyfouract/a4j_3_2_0.SR1-SNAPSHOTtiny_mce/langs/de.js
which will not work and gives this exception on the webservers console:10:33:04,553 ERROR [[default]] Servlet.service() for servlet default threw exception org.ajax4jsf.resource.ResourceNotFoundException: Resource not registered : tiny_mce/langs/de.js at org.ajax4jsf.resource.ResourceBuilderImpl.getResource(ResourceBuilderImpl.java:389) at org.ajax4jsf.resource.ResourceBuilderImpl.getResourceForKey(ResourceBuilderImpl.java:333) at org.ajax4jsf.resource.InternetResourceService.serviceResource(InternetResourceService.java:152) at org.ajax4jsf.resource.InternetResourceService.serviceResource(InternetResourceService.java:141) at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:481) at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60) at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
when only looking at the exception text, it was no clear to me why this file is not found, as the path semms to be ok: tiny_mce/langs/de.js
using this to load the script:<a:loadScript src="/tiny_mce/tiny_mce.js" />
solves the problem, because now tinyMCE will find the correct baseURL:http://localhost:8080/twentyfouract/tiny_mce
and request the correct resource:http://localhost:8080/twentyfouract/tiny_mce/langs/de.js
thanks