2
在爲使用的facelet模板這樣的一個facelet頁:如何在外部頁面中包含外部JavaScript文件?
<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放入其中來混淆我的頁面,所以我在我的資源文件夾 中將其外化。
但是我如何實現我的目標?
UPDATE:
我基本上有這樣的按鈕,我想添加自定義JavaScript我primefaces按鈕的onComplete事件。
<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
你應該插入腳本界面內:不定義用戶界面內Facelet標記:組成。
<ui:composition template="../../WEB-INF/Template.xhtml">
<ui:define name="content">
<h:outputScript name="showmembers.js" library="javascript" target="head"/>
</ui:define>
</ui:composition>
喜丹尼爾,感謝這一點,但你能幫我解決問題嗎?我已更新我的帖子。 –
我的答案是否解決了您的原始問題?關於你的新問題,你不應該看到你的handleSaveNewMember代碼附加到你的按鈕中,它的確定,它會在你的js文件中......在你支持的按鈕中只能看到對你發佈的函數名稱的引用,你可能需要點擊ctrl + F5一次刷新你的js – Daniel
嗨丹尼爾..對不起,我不確定我的問題是否真的回答,因爲我點擊按鈕時我的對話框不是很接近。什麼都沒有發生。我在想我的代碼沒有執行。 –