h:outputScript,目标为"head"不适用于Primefaces 3.5 [英] h:outputScript with target="head" not working with Primefaces 3.5

查看:70
本文介绍了h:outputScript,目标为"head"不适用于Primefaces 3.5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JSF应用程序,其中使用target ="head"属性插入了一些脚本,但是在将Primefaces 3.5包含到类路径中之后,这些脚本停止了渲染.

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.

这是页面代码:

<!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>

删除target属性可以使脚本正常运行,但是可以在正文中而不是在头部...

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

有任何线索吗? 谢谢&问候.

Any clues? Thanks & Regards.

推荐答案

从PrimeFaces 3.0开始,有一个新的此博客.这已经覆盖了标准的JSF Head渲染器.这是可以的,但是显然它无法正确识别以head为目标的内联脚本.这显然是PrimeFaces头部渲染器中的错误.最好的选择是报告此问题给PF人员.

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.

同时,如果您根本不使用该新的PrimeFaces功能,则只需输入

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>

注意:如果您使用的是MyFaces而不是Mojarra,则显然应该引用MyFaces自己的.

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

这篇关于h:outputScript,目标为"head"不适用于Primefaces 3.5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆