I am working with JSF 2.0 and here is my form:
<h:form id="fff" onsubmit="reloadMap();">
<h:selectOneMenu value="#{rentCarPoolBean.state}">
<f:selectItems value="#{rentCarPoolBean.stateList}" id="stateList" />
<f:ajax event="change" render="cities stateSelected" onevent="showAlert"/>
</h:selectOneMenu>
<h:selectOneMenu id="cities" value="#{rentCarPoolBean.city}">
<f:selectItems value="#{rentCarPoolBean.cityList}"/>
</h:selectOneMenu>
<h:outputText value="#{rentCarPoolBean.state}" id="stateSelected" />
</h:form>
And the javascript function:
<script type="text/javascript">
function showAlert(data){
if (data.status == "complete")
alert(document.getElementById("stateSelected"));
}
</script>
What the above code does when selecting a state from the first drop-down list, it calls ajax and displays a drop-down list of "cities" and "stateSelected" outputText.
In addition, it calls the showAlert () javascript function.
What I want to do is call the javascript function after all the data has been returned and the drop down list and the output text are output.
But at present, the javascript function is called before the elements are rendered and a warning appears null. How can we make a javascript function at the end?
source
share