Best way for JSF to defer parsing of JavaScript?

我是研究僧i 提交于 2019-12-04 11:14:47

Use <h:outputScript target="body">. It will then end up in the very end of <h:body>. It namely defaults to "current" location in the view (another target value is head which will then make the script to end up in the <h:head>, even when the script is specified somewhere in the <h:body>).

<h:outputScript name="js/foo.js" target="body" />

If you want to apply this for 3rd party scripts as well, you'd need to create a custom SystemEventListener hooking on PreRenderViewEvent which does exactly that with help of UIViewRoot#getComponentResources() and UIViewRoot#addComponentResource().

Don't know if that counts (you can call it a workaround),

But you can always include some js files in external xhtml page wich will be included in your main page with ui:include which will be wrapped by <h:panelGroup id="externalPageWrapper" render="#{myBean.renderExternalPage}" and with little help of js/jquery you can execute .click() on some hidden h:commandButton with f:ajax that will change the renderExternalPage to true and render the externalPageWrapper that will load that xhtml page and all the js files that were included inside it...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!