가 나는 XHTML 페이지를하고 난 A4J에서 자바 스크립트 함수를 호출 할 : CommandLink는합니다. 이유는 모르겠지만 javascript 메서드가 호출되지 않습니다. 나는 "ui : define"을 사용하여 .js 파일에 함수를 작성하려고 시도했지만, 여전히 그 메소드를 호출 할 수는 없습니다. 이것은 라이프 사이클에 빠지지 않기 때문에 무언가입니까? 다음과 같이jsf에서 javascript 함수를 호출하는 방법은 무엇입니까?
XHTML의 페이지는 다음과 같습니다 당신이 자바 스크립트 함수를 호출
<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()"'? 그런 다음 직접 경고를 시도하십시오. 그 중 하나가 호출되지 않은 경우, 자바 스크립트 관련되지 않은 문제가 있습니다. 문제를 해결하십시오! – Kukeltje
"a4j : commandLink에서 javascript 함수를 호출하고 싶습니다." 그러나 당신은 우리에게'rich : inplaceSelect'라는 코드를주었습니다. 그럼 뭐야? –
안녕하세요, 심지어 myFunction()조차 alert()을 호출 할 수 없습니다. – 5A9U