gpt4 book ai didi

jsf-2 - 如何在 facelet 页面中包含外部 javascript 文件?

转载 作者:行者123 更新时间:2023-12-04 05:46:25 30 4
gpt4 key购买 nike

在使用如下 Facelet 模板的 Facelet 页面中:

<h:head>
<h:outputScript name="custom.js" library="javascript" target="head"/>
</h:head>
<ui:composition template="../../WEB-INF/Template.xhtml">

</ui:composition>

你如何包含一个自定义的 javascript?在上面的代码中,我的 custom.js 被忽略了,因为
ui:composition facelet 标签。

我不想通过将我的 javascript 放入我的页面来弄乱我的页面,所以我将它外部化到我的资源中
文件夹。

但是我如何实现我的目标?

更新:

我基本上有这个按钮,我想在我的 primefaces 按钮的 oncomplete 事件上添加自定义 javascript。
<p:commandButton value="Save"
actionListener="#{memberManagedBean.save}"
oncomplete="handleSaveNewMember(xhr, status, args)"
update=":memberListForm:membersTable"
process="@form" />

但是我没有把我的代码放在里面,而是将它外部化到我的 custom.js
function handleSaveNewMember(xhr, status, args) {
/*More Code*/
addMemberDlg.hide();
}

但是查看为我的按钮生成的 HTML,我的自定义 javascript 代码不包括在内,只添加了函数名称。
<button id="createupdateform:j_idt18" oncomplete:function(xhr, status, args){handleSaveNewMember(xhr, status, args);}});return false;" type="submit"><span class="ui-button-text">Save</span></button>

为什么会这样?

更新 2

您应该在 ui:define facelet 标签内而不是在 ui:composition 内插入脚本。
<ui:composition template="../../WEB-INF/Template.xhtml">
<ui:define name="content">
<h:outputScript name="showmembers.js" library="javascript" target="head"/>
</ui:define>
</ui:composition>

最佳答案

你可以把它放在你的<ui:composition里面

<ui:composition template="../../WEB-INF/Template.xhtml">
<h:outputScript name="custom.js" library="javascript" target="head"/>
</ui:composition>

或地点 <h:outputScript在您的 Template.xhtml

反正 <h:head>最好放在您的 Template.xhtml只要...

关于jsf-2 - 如何在 facelet 页面中包含外部 javascript 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10630218/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com