h:outputScript with target=“head” not working with Primefaces 3.5

只谈情不闲聊 提交于 2019-12-22 14:15:32

问题


I have a JSF application with some scripts inserted using target="head" attribute, but after including Primefaces 3.5 to the classpath, these scripts stop rendering.

Here is the page code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:ui="http://java.sun.com/jsf/facelets" 
      xmlns:h="http://java.sun.com/jsf/html" 
      xmlns:f="http://java.sun.com/jsf/core">
 <h:head> 
 </h:head>
   <h:body>
       <h:outputScript  target="head">
          function a(){};
        </h:outputScript>
 </h:body>
</html>

Removing the target attribute renders the script ok, but in the body, not in the head...

Any clues? Thanks & Regards.


回答1:


Since PrimeFaces 3.0, there is a new HeadRenderer which allows customizable resource ordering. See also this blog. This has overriden the standard JSF head renderer. This is at its own okay, but apparently it failed to properly recognize inline scripts with target of head. This is clearly a bug in PrimeFaces head renderer. Your best bet is to report this issue to PF guys.

In the meanwhile, if you aren't making use of that new PrimeFaces feature at all, then just put Mojarra's own HeadRenderer back as default head renderer by adding the following entry to faces-config.xml:

<render-kit>
    <renderer>
        <component-family>javax.faces.Output</component-family>
        <renderer-type>javax.faces.Head</renderer-type>
        <renderer-class>com.sun.faces.renderkit.html_basic.HeadRenderer</renderer-class>
    </renderer>
</render-kit>

Note: in case you're using MyFaces instead of Mojarra, obviously reference MyFaces own one instead.



来源:https://stackoverflow.com/questions/17582476/houtputscript-with-target-head-not-working-with-primefaces-3-5

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