-
1. Re: Adding external resources to component
boy18nj Mar 9, 2011 1:26 PM (in response to iref)Yes, you have to extract/write the new script in response writer.
Example-
@ResourceDependencies( {
@ResourceDependency(library="javascript", name="spinner.js"),
@ResourceDependency(library="javax.faces", name="jsf.js")
})
......
.......
public void encodeBegin(FacesContext context, UIComponent component){
String ajaxScript = MessageFormat.format(
"if(document.forms[''{0}''][''{1}''].value != '''') {2};",
formId, clientId, getChangeScript(context, spinner));
-
2. Adding external resources to component
nbelaevski Mar 20, 2011 7:28 PM (in response to boy18nj)Hi Jan,
How do you use @ResourceDependency? Please post your code.
-
3. Adding external resources to component
boy18nj Mar 20, 2011 8:56 PM (in response to boy18nj)Since you mentioned, you need to add external js to your component. What I understand here is you have your customized component,
the java class where you defined your component which encodes/decodes html markup code needs to define @ResourceDependency annotation, this helps to add external js to your html markup.
Otherwise if you wish to add external js to your .xhtml only, then use this code-
<a4j:loadScript src="resource://jquery.js" />
-
4. Adding external resources to component
iref Mar 21, 2011 5:27 AM (in response to nbelaevski)My code looks like this:
@ResourceDepedencies({
@ResourceDependency(name="jquery.js", target="head"),
@ResourceDependency(name="http://someurl.com/script.js" target="head")
})
public class MyRenderer extends RendererBase{
public encodeEnd(FacesContext context, UIComponent component) throws IOException{
//do some encoding
}
}
-
5. Adding external resources to component
nbelaevski Mar 21, 2011 5:53 AM (in response to iref)JSF 2 does not have support for such resources out of the box - check specification for more information. With RichFaces you can do the following: http://community.jboss.org/message/591506#591506
-
6. Adding external resources to component
nbelaevski Mar 21, 2011 5:54 AM (in response to boy18nj)Aman,
RF 4 does not include a4j:loadStyle and a4j:loadScript - they are deprecated in favor to analogous JSF tags.
-
7. Adding external resources to component
iref Mar 21, 2011 2:17 PM (in response to nbelaevski)Thanks guys, both of you. Does this work if my components are in different module than my web application (and included to webapp as dependency)? Or I have to add resource-mappings.properties to my component META-INF folder?
-
8. Adding external resources to component
nbelaevski Mar 21, 2011 2:22 PM (in response to iref)This resource should be on classpath, RichFaces is indifferet to where it is placed physically.
-
9. Adding external resources to component
iref Apr 16, 2011 10:51 AM (in response to nbelaevski)Nick,
thanks for help.
But I haven't figured it out. I created /META-INF/richfaces/resource-mapping.properties in my component project and I added property gmaps.js=http://maps.google.com/maps/api/js?sensor=true there. But when I add @ResourceDependency(name="gmaps.js", target="head") to my renderer JSF cant figure out mapping and I get "resource not found" warning in log. Is there something I am missing?
-
10. Adding external resources to component
nbelaevski Apr 17, 2011 6:39 AM (in response to iref)Have you added web.xml entry for static resource location?