admin管理员组文章数量:1353627
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 ponent/event that can do this instead of using java script.
Thanks for your help.
<h:mandButton 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
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 ponent/event that can do this instead of using java script.
Thanks for your help.
<h:mandButton 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
Share Improve this question asked Aug 18, 2010 at 1:29 lawardylawardy 1532 gold badges3 silver badges10 bronze badges 1- 1 Very good question. Would like to see a ponent for this (javascript firing an event after the page is loaded) in Primefaces... I think it does not exist at the moment. I'm going to link your question in the support forum. – egbokul Commented Aug 18, 2010 at 5:53
2 Answers
Reset to default 5I think the PreRenderViewEvent is what you want.
http://javaserverfaces.java/nonav/docs/2.0/javadocs/javax/faces/event/PreRenderViewEvent.html
Though the docs don't show it, the preRenderViewEvent does work with f:event. I'll fix the docs presently.
PostAddToViewEvent is processed "During Restore View Phase, after a ponent 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.
本文标签: javaCalling JSF ManageBean after PageLoad using fevent postAddToViewStack Overflow
版权声明:本文标题:java - Calling JSF ManageBean after PageLoad using f:event postAddToView - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743934198a2564385.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论