我有一個xhtml頁面,我想在a4j:commandLink中調用一個javascript函數。我不知道爲什麼,但JavaScript方法沒有被調用。我已經嘗試使用「ui:define」將函數寫入.js文件,但仍然無法調用該方法。這是因爲它沒有落入生命週期嗎?如何在jsf中調用javascript函數?
XHTML頁面如下:當你調用Java腳本函數
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:rich="http://richfaces.org/rich"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<script type="text/javascript">
function myFunction(){
alert("Hello World!");
}
</script>
</h:head>
<h:body>
<h:panelGrid columns="2">
<h:outputText value="Choose the produce type:" />
<rich:inplaceSelect value="#{selectedBean.currentType}"
valueChangeListener="#{selectedBean.valueChanged}"
defaultLabel="Click here to select">
<f:selectItems value="#{selectedBean.firstList}" />
<a4j:ajax event="change" reRender="items, label"
ajaxSingle="true" oncomplete="myFunction()"/>
<a4j:log></a4j:log>
</rich:inplaceSelect>
<a4j:outputPanel id="label">
<h:outputText value="Choose concrete product:"
rendered="#{not empty selectedBean.secondList}" />
</a4j:outputPanel>
<a4j:outputPanel id="items">
<rich:inplaceSelect value="#{selectedBean.currentItem}"
rendered="#{not empty selectedBean.secondList}"
defaultLabel="Click here to select">
<f:selectItems value="#{selectedBean.secondList}" />
</rich:inplaceSelect>
</a4j:outputPanel>
</h:panelGrid>
</h:body>
哪一個不叫? '的onComplete = 「myFunction的()」'?然後直接嘗試一個簡單的警報。如果這不被調用,則存在與JavaScript無關的問題。分解你的問題! – Kukeltje
「我想在a4j:commandLink中調用javascript函數。」但是你已經用'rich:inplaceSelect'給了我們代碼。之後怎麼樣了? –
嘿,我不能調用alert()甚至不myFunction()。 – 5A9U