I am trying to use a javascript on one of my JSF pages. Unfortunately the
<h:body onload="init('#{formBean.arrayAsString}')">
Is not called at all. I have discovered that if I add /redirect tag in the navigation case that navigate to the page, the function will load. Unfortunately that causes another problem since with the navigation I also pass important f:param so the formBean can read it. If I use the /redirect tag the param value is no longer available for reading.
How can I load the javascript init function without using the redirect tag? Or maybe I can somehow pass the f:param value with redirection but as far as I know this is not possible…
I below post the navigation method:
first .xhtml page:
<h:selectOneMenu id="selectMenu" value="#{indexBean.name_id}">
<f:selectItems value="#{indexBean.myModelValues}" />
<f:ajax event="valueChange" render="button" execute="@this"/>
</h:selectOneMenu>
<h:commandButton id="button" value="Go to form Browse" action="form">
<f:param name="name" value="#{indexBean.name_id}" />
</h:commandButton>
Bare in mind that this button is also re-rendered by a ajax event of a h:selectOneMenu to pass the selected value.
And the navigation case:
<navigation-rule>
<from-view-id>/index.xhtml</from-view-id>
<navigation-case>
<from-outcome>
form
</from-outcome>
<to-view-id>
/form.xhtml
</to-view-id>
<redirect/>
</navigation-case>
</navigation-rule>
The redirect tag is a new add-on which enabled the JavaScript init function.
That will happen if the action is invoked by ajax. Make it a non-ajax action.
Update: as per your question update, replace
<a4j:commandButton>by<h:commandButton>to make it a non-ajax action. By the way, in JSF 2 you do not need navigation cases anymore if the from outcome equals the to view ID already. Remove the whole<navigation-rule>, you don’t need it.