2017-01-13 17 views
0

私は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> 

+0

どちらが呼び出されていないのですか? 'oncomplete =" myFunction() "'?それから、直接その中の平凡な警告を試みてください。それも呼び出されなければ、javascriptに関連しない問題があります。あなたの問題を打ち破ろう! – Kukeltje

+1

"a4j:commandLinkでjavascript関数を呼び出したい。"しかし、あなたは 'rich:inplaceSelect'を使ってコードを与えました。それは何ですか? –

+0

私はalert()もmyFunction()を呼び出すことができません。 – 5A9U

答えて

0

はセミコロンを追加します。

oncomplete="myFunction();" 
+0

違いがあるかどうか試しましたか?私の知る限り、それは – Kukeltje

+0

うん。私は同じ問題を抱えていました。そのような時間の無駄 –

+0

確かにそれはプレーンなjsf f:ajaxの問題ですか? – Kukeltje

関連する問題