I have a @ViewScoped
bean with a simple testing method, my problem is when that when I open the page for the first time it's intialized correctly and everything is fine but when I browse to another page the pageOnLoad
method is still running and the console is printing out values.
Is this a normal behaviour of @ViewScoped
bean ? How to detect that the view has been changed and interrupt the method process?
@ManagedBean
@ViewScoped
public class GeneralBean implements Serializable{
private static final long serialVersionUID = 5832997040927489736L;
public void pageOnLoad() {
for (int i=0;i<999999;i++){
System.out.println(i);
}
}
}
my xhtml page:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
xmlns:of="http://omnifaces.org/functions" >
<h:head>
<script type="text/javascript">
$(document).ready(function() {
loadInitialList();
});
</script>
</h:head>
<h:body>
<h:form>
<p:remoteCommand name="loadInitialList" actionListener="#{generalBean.pageOnLoad}" update="generalForm" />
</h:form>
<h:form id="generalForm">
</h:form>
</h:body>
</html>