views:

76

answers:

1

Hi Guys,

I am writing an app using JSF 2.0.

For one of the page, there is a section of the page that takes a long time to display.

To improve the user experience, I am thinking to load the page first and then automatically do an Ajax call back to the JSF manage bean object once the page is loaded successfully after 1st load.

I am thinking to use f:event with type postAddView.

<h:outputText id="dummyId">
    <f:event type="postAddToView" listener="#{mngBean.doSomething}" />
</h:outputText>

However it seems like f:event postAddToView is still being processed before the page is displayed for the first time.

The other options that I have explore is to create a hidden button and get javascript to trigger it. It works however I am just wondering if there is a nice JSF component/event that can do this instead of using java script.

Thanks for your help.

<h:commandButton id="dmyButton" 

value="#{mngBean.getSomething}" actionListener="#{mngBean.doSomething}" style="display: none" type="submit">

Java Script

<script language="JavaScript">
 $(document).ready(function() {
  if (document.getElementById('form:dmyButton').value == 'true') {
   document.getElementById('form:dmyButton').click();
  }

 });
</script>

Thanks for all your help in advance

A: 

PostAddToViewEvent is processed "During Restore View Phase, after a component has been added to a view." (according to Java Server Faces 2.0 - The Complete Reference) which means it is really early in the lifecycle (Restore View is the first lifecycle phase).

I don't think that any PhaseListener will help you in this case, since they all run on the server side, not on the client side.

However, <f:ajax> can be applied to <h:body>, with event="load". I tried it, but it didn't really work, <f:ajax> wrapping <h:body> nothing happened, the other way around I got Unable to attach <f:ajax> to non-ClientBehaviorHolder parent error.

Gabor Kulcsar