简体   繁体   English

如何在Primefaces UI中包含JSF的jQuery库?

[英]How to include jQuery library for JSF with Primefaces UI?

I need to use jQuery and jQuery UI in JSF template pages, however, Primefaces have its own jQuery which is loaded on demand. 我需要在JSF模板页面中使用jQuery和jQuery UI,但是Primefaces有自己的jQuery,可以根据需要加载它。 Ie, Primefaces won't load jQuery if there is no <p:xxx> tag in the page. 即,如果页面中没有<p:xxx>标记,Primefaces将不会加载jQuery。

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? 虽然可以,但是还有更好的解决方案吗?

You can include the library implicitly using an outputScript tag: 您可以使用outputScript标记隐式包含该库:

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

See the answer to this SO question for more info. 有关更多信息,请参见此SO问题的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM