문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top