-
1. Re: Custom RichFaces components requiring scripts?
nbelaevski Dec 20, 2010 6:21 PM (in response to shadowcreeper)Hi,
It should work by overriding getScripts(). Check that you have not overriden methods HeaderResourcesRendererBase.encodeToHead(FacesContext, UIComponent, ProducerContext) and HeaderResourcesRendererBase.getHeaderScripts(FacesContext, UIComponent).
-
2. Re: Custom RichFaces components requiring scripts?
shadowcreeper Dec 21, 2010 3:36 PM (in response to nbelaevski)My class is not overriding the encodeToHead or getHeaderScripts methods mentioned above and overriding getScripts does nothing.
I can override those methods with nothing but a System.out.println and super call to prove that none of those 3 methods are getting called.
My overriden methods decode(FacesContext,UIComponent) and encodeEnd(FacesContext,UIComponent) all call the super. Is there something else I need to call to trigger the HeaderResourcesRendererBase to know that it needs to render some header resources?
Also, I am using RichFaces 3.3.3.Final and JSF2 (Mojarra) under Tomcat 6.0.29
Thanks
-
3. Re: Custom RichFaces components requiring scripts?
nbelaevski Dec 21, 2010 5:04 PM (in response to shadowcreeper)Maybe custom resource name is mistyped/wrong?
-
4. Re: Custom RichFaces components requiring scripts?
shadowcreeper Dec 21, 2010 5:13 PM (in response to nbelaevski)I don't understand what you mean by "mistyped/wrong" but I'm guessing it isn't, due to the fact that the component is rendered on the page and works fine. It just doesn't ever call getScripts() or getHeaderScripts(FacesContext,UIComponent), etc.
It still calls encodeBegin and encodeEnd and preEncodeBegin, decode, etc. But since the scripts aren't loaded in the head, IE occasionally has problems running the scripts due to the javascript methods not existing yet. If I hardcode an a4j:loadscript tag in the head of the jsf page or put my setup code from encodeEnd in something like "Event.observe( window, 'load', mySetupCode );" they consistently work. But this makes the script load once for each element on the page rather than just once in the head.
-
5. Re: Custom RichFaces components requiring scripts?
shadowcreeper Dec 21, 2010 5:18 PM (in response to nbelaevski)Could I perhaps see a very simplified example of something that extends CalendarRenderer and adds a script successfully (any script via an external link will do fine).
-
6. Re: Custom RichFaces components requiring scripts?
nbelaevski Dec 21, 2010 5:23 PM (in response to shadowcreeper)BTW, check what scripts loading strategy is used.
-
8. Re: Custom RichFaces components requiring scripts?
nbelaevski Dec 21, 2010 6:05 PM (in response to shadowcreeper)So, that's the reason of such behavior.
-
9. Re: Custom RichFaces components requiring scripts?
shadowcreeper Dec 21, 2010 6:16 PM (in response to nbelaevski)Thank you. Removing that from web.xml makes getScripts and encodeToHead get called. Is there any explanation why LoadScriptStrategy of ALL doesn't call getScripts at all?
I looked at the docs but they don't seem to mention anything except to imply that NONE won't load any scripts. No explanation of what DEFAULT and ALL are supposed to do.
-
10. Re: Custom RichFaces components requiring scripts?
shadowcreeper Dec 21, 2010 7:35 PM (in response to nbelaevski)Upon further research I see that ALL includes all RichFaces script resources in 2 js files. And it appears that DEFAULT includes only the scripts necessary for the current page/ajax update. This all happens within ViewResources.processHeadResources(FacesContext).
Is there a supported (clean) way to add my scripts when using LoadScriptSrategy of ALL? Or will I have to implement my own ViewHandler to wrap the org.ajax4jsf.application.AjaxViewHandler or the org.ajax4jsf.application.ViewHandlerWrapper?
Thanks.
-
11. Re: Custom RichFaces components requiring scripts?
shadowcreeper Dec 21, 2010 7:57 PM (in response to shadowcreeper)Upon further examination, this doesn't seem possible without a bunch of ugly hacks.
And now that I know what the issue is, I see there is already a ticket for it:
https://issues.jboss.org/browse/RF-7675
Thanks again.