如何在Primefaces UI中包含JSF的jQuery库? [英] How to include jQuery library for JSF with Primefaces UI?

查看:108
本文介绍了如何在Primefaces UI中包含JSF的jQuery库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在JSF模板页面中使用jQuery和jQuery UI,但是Primefaces有自己的jQuery,可以根据需要加载它.也就是说,如果页面中没有<p:xxx>标签,Primefaces将不会加载jQuery.

I need to use jQuery and jQuery UI in JSF template pages, however, Primefaces have its own jQuery which is loaded on demand. I.e., Primefaces won't load jQuery if there is no <p:xxx> tag in the page.

我可以使用一个虚拟表单来包含所有必需的库,如下所示:

I can have a dummy form to include all the required libraries like following:

    <h:form id="dummy" style="display: none;">
        A Dummy Form.
        <p:dataTable />
        <p:column />
        <p:commandLink />
        <p:commandButton />
        <p:dialog />
        <p:fileUpload />
        <p:tabView rendered="false">
            <p:tab title="" />
        </p:tabView>
        <p:message for="dummy" />
        <f:ajax event="click" />
    </h:form>

虽然可以,但是还有更好的解决方案吗?

though it works, but is there any better solution?

推荐答案

您可以使用outputScript标记隐式包括库:

You can include the library implicitly using an outputScript tag:

<h:outputScript library="primefaces" name="jquery/jquery.js"/>

有关更多信息,请参见此SO问题的答案.

See the answer to this SO question for more info.

这篇关于如何在Primefaces UI中包含JSF的jQuery库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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