[ACCEPTED]-Execute managebean method from javascript onload event-jsf-2
In theory the following should do it.
<h:body>
<f:ajax event="load" listener="#{bean.onload}" />
</h:body>
with
public void onload(AjaxBehaviourEvent event) {
// ...
}
However, this 8 is not supported for some reason. I've ever 7 posted an issue report about that.
The following works, but 6 it's in essence a hack.
<h:head>
<title>JSF 2.0 onload hack</title>
<script>
window.onload = function() {
document.getElementById('hidden:link').onclick();
}
</script>
</h:head>
<h:body>
<h:form id="hidden" style="display:none">
<h:commandLink id="link">
<f:ajax event="click" listener="#{bean.onload}" />
</h:commandLink>
</h:form>
</h:body>
If you happen to 5 use PrimeFaces, then you can use its <p:remoteCommand>
with 4 autoRun
set to true
.
<h:body>
<h:form>
<p:remoteCommand name="onload" action="#{bean.onload}" autoRun="true" />
</h:form>
</h:body>
Or if you're using OmniFaces, then you 3 can use its <o:commandScript>
<h:body>
<h:form>
<o:commandScript name="onload" action="#{bean.onload}" />
<h:outputScript target="body">onload()</h:outputScript>
</h:form>
</h:body>
The <h:outputScript target="body">
renders the <script>
in the end 2 of the <body>
. The upcoming OmniFaces 2.2 will 1 remove this need by new autorun
attribute.
<h:body>
<h:form>
<o:commandScript name="onload" action="#{bean.onload}" autorun="true" />
</h:form>
</h:body>
in jsf2.0 you can use the f:ajax tag in 4 almost any other jsf tag e.g
<h:selectOneRadio id="myComponent" value="#{someBean.inputMethod}">
<f:selectItem itemValue="#{someBean.A}" itemLabel="A" />
<f:selectItem itemValue="#{someBean.B}" itemLabel="B" />
<f:ajax event="click" action=#{someBean.someMethod} />
</h:selectOneRadio>
In this example 3 the someMethod is excuted in the javasript 2 onClick event for the "myComponent" selectOneRadio
Not 1 sure if this is what you are after ....
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.