查看范围的Bean preRenderView方法被多次调用 [英] View Scoped Bean preRenderView method being called multiple times
问题描述
我的 Mojarra 2.1.6 网络应用程序有问题,我正在使用@ViewScoped
托管bean开发它,每个bean都附加到一个xhtml页面.该页面正在接收一些 view params ,并以这种方式初始化bean之后:
I have a problem with my Mojarra 2.1.6 web-application, I'm developing it using @ViewScoped
managed beans and each bean is attached to an xhtml page. This page is receiving some view params and after initializing the bean in that way:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui"
template="/templates/general_template.xhtml">
<ui:define name="metadata">
<f:metadata>
<f:viewParam id="user" name="user"
value="#{navegableUserData._ParamUser}" />
<f:viewParam id="NavIndex" name="NavIndex"
value="#{navegableUserData._QueueIndex}" />
<f:event type="preRenderView"
listener="#{navegableUserData.initialize}" />
</f:metadata>
<h:message for="user" />
</ui:define>
<ui:define name="general_content">
<p:outputPanel autoUpdate="false" id="Datos_Loged" name="Datos_Loged"
layout="block">
<h:form id="SystemUserForm">
<ui:include
src="/system/manage_user/content/edit_user/system_user_data/system_user.xhtml">
<ui:param name="manager" value="#{navegableUserData}" />
</ui:include>
</h:form>
</p:outputPanel>
</ui:define>
如您所见,我的页面嵌套在一个通用模板中,如下所示:
As you can see, I have my pages nested into a general template which looks like that:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui">
<h:head>
<meta http-equiv="Pragma" CONTENT="no-cache"></meta>
<meta http-equiv="cache-control" content="no-cache"></meta>
<meta http-equiv="Expires" CONTENT="-1"></meta>
<meta http-equiv="Content-Type"
content="text/html; charset=ISO-8859-15" />
<h:outputStylesheet library="css" name="prime_styles.css" />
<h:outputScript library="js" name="prime_translations.js" />
</h:head>
<h:body>
<ui:insert name="metadata" />
<o:importConstants
type="com.company.system.view.beans.NavigationResults" />
<!-- More stuff -->
当我发出 ajax 请求(例如Primefaces表过滤)时,会出现
问题.尽管不再创建我的支持bean,但再次调用了 <f:event type="preRenderView" listener="#{navegableUserData.initialize}" />
.
Problem comes when I make an ajax request such as a Primefaces table filtering. Although my backing bean is not being created again, <f:event type="preRenderView" listener="#{navegableUserData.initialize}" />
is being called again.
我正在基于视图参数进行数据加载,并且需要仅在首次呈现页面时才执行该方法.我一直非常小心地使用<c:xxx>
标记,并认为这不是问题,因为我仅在常规模板中使用了它们,而我的view Beans属性未附加到它们.另外,我的所有页面都遇到这个问题,所以我认为这不是特定后备bean的问题.
I'm doing a data loading based into view params and need that method to execute only when the page is rendered first time. I have been very careful using <c:xxx>
tags and think that's not the problem because I used them only in general template and my view beans properties are not attached to them. Also I have this problem with all my pages, so I think it is not an issue of an specific backing bean.
推荐答案
如果仅在ajax请求期间发生这种情况,请尝试以下操作:
If this occur only during ajax request, try the following:
public void initialize() {
if (!FacesContext.getCurrentInstance().isPostback()) {
// -----------
// -----------
}
}
与BalusC建议有关:
Related as BalusC suggested:
这篇关于查看范围的Bean preRenderView方法被多次调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!