Take the 2-minute tour ×

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:commandButton id="button" value="Go to form Browse" action="form">
                  <f:param name="name" value="#{indexBean.name_id}" />                                       

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:


The redirect tag is a new add-on which enabled the JavaScript init function.

share|improve this question
you have "<h: body" in your code or is it a typo in the question? –  Damian May 15 '12 at 13:43
it is h:body without the space. –  srd.pl May 15 '12 at 13:45
how are you navigating? using a navigation rule in faces-config.xml? or returning a String in the action method? or with commandButton/commandLink action attribute? –  Damian May 15 '12 at 13:45
add comment

1 Answer

up vote 1 down vote accepted

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.

share|improve this answer
I needed to change some other stuff but it works - Thanks as usual BalusC - great support. –  srd.pl May 15 '12 at 15:33
You're welcome. –  BalusC May 15 '12 at 15:38
add comment

Your Answer


