我正在为这种奇怪的情况而奋斗。我有3个页面,称之为A,B和C.每个页面在请求范围内都有自己的Managed Bean:MB1,MB2和MB3。当我进入A时,创建了MB1。从A,我调用window.showModalDialog打开B,每次B创建它打开的MB2。当我使用window.showModalDialog从B调用页面C时,奇怪性开始,并且创建MB3 一次。这种行为让我感到疯狂,因为我做过这样的事情,这是第一次发生这种情况。
我还必须说MB1和MB2有@KeepAlive注释(类似于使用a4j:keepAlive
标记组件,而MB3是一个干净的托管bean。
我愿意接受任何解决问题的想法。我目前正在使用JSF 1.2,RichFaces 3.3.3和JBoss EAP 5.1。
感谢您的时间,抱歉我的英语不好!
编辑1:页面A,B和C的源代码:
第A页:
<!-- The js function which calls page B -->
<script type="text/javascript">
function buscaDeposito() {
var blnResultado = false;
var sUrl = 'pageB.jsf';
var oDatos = new Object();
var args = 'dialogHeight: 450px; dialogWidth: 700px; edge: Raised; center: Yes; help: No; resizable: No; status: No';
if (window.showModalDialog(sUrl, oDatos, args)) {
blnResultado = true;
document.getElementById('frmFormaCobroLiqDocCartera:txtNroDeposito').value = oDatos.ReturnValue;
}
return blnResultado;
}
</script>
<!-- HTML/JSF fragment of page A -->
<table class="tabla" width="100%">
<tr>
<td style="width: 25%; text-align: right">
<h:outputText>Nro. de depósito no identificado</h:outputText>
</td>
<td style="width: 20%">
<h:inputText id="txtNroDeposito" styleClass="inputText" style="width: 100%"
readonly="true"
value="#{formaCobroLiqDocCartera.numeroDepositoNoIdentificado}" />
</td>
<td>
<a4j:commandLink id="lnkBuscaDNIDeposito"
onclick="if (!buscaDeposito()) return false;"
action="#{formaCobroLiqDocCartera.cargaDatosDeposito}"
reRender="pnlDeposito" limitToList="true">
<h:graphicImage value="/Resource/iconos/buscar-con-ayuda.png"
styleClass="pic" title="Buscar" />
</a4j:commandLink>
</td>
</tr>
</table>
第B页:
<script type="text/javascript">
window.returnValue = false;
// The js function which calls pageC
function veDetalleDeposito() {
//The function depositoSeleccionado checks if at least one
//radio button has been selected in the dataTable.
if (!depositoSeleccionado()) {
alert('Debe seleccionar un depósito.');
} else {
var sUrl = 'pageC.jsf';
var oDatos = new Object();
var args = 'dialogHeight: 280px; dialogWidth: 400px; edge: Raised; center: Yes; help: No; resizable: No; status: No';
window.showModalDialog(sUrl, oDatos, args);
}
}
</script>
<!-- The call to pageC in the oncomplete javascript because I must set a session
variable with the value of the selected row. -->
<a4j:commandLink id="lnkVeDetalle" oncomplete="veDetalleDeposito()">
<h:graphicImage value="/Resource/iconos/visualizar-registro.png" styleClass="pic"
title="Ver detalle de depósito" />
</a4j:commandLink>
<rich:dataTable id="dtDepositos" width="100%" headerClass="cabeceraDataTable"
binding="#{listaDepositoNoIdentificado.hdtDepositos}" rows="15"
value="#{listaDepositoNoIdentificado.lstDepositos}" var="deposito">
<rich:column width="5%" style="text-align:center">
<f:facet name="header">
<h:outputText value="Seleccione" />
</f:facet>
<h:selectOneRadio onclick="dataTableSelectOneRadio(this)"
valueChangeListener="#{listaDepositoNoIdentificado.setSelectedItem}">
<f:selectItem itemValue="null" />
</h:selectOneRadio>
</rich:column>
<!-- more columns here... -->
</rich:dataTable>
第C页(一个什么都不做的简单jsf页面):
<h:form style="font-family: sans-serif;">
<h2 class="tituloPagina">Detalle del Depósito No Identificado</h2>
<fieldset>
<legend class="legenda">Detalle del Depósito No Identificado</legend>
<table>
<tr>
<td>Tipo:</td>
<td>
<h:outputText value="#{detalleDeposito.deposito.tipo}" />
</td>
</tr>
<tr>
<td>Número:</td>
<td>
<h:outputText value="#{detalleDeposito.deposito.codigoDni}" />
</td>
</tr>
<!-- more data to present to the users. -->
</table>
</fieldset>
</h:form>
faces-config.xml中:
<managed-bean>
<managed-bean-name>formaCobroLiqDocCartera</managed-bean-name>
<managed-bean-class>com.abaco.presentacion.managedbean.PFormaCobroLiqDocCartera</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>listaDepositoNoIdentificado</managed-bean-name>
<managed-bean-class>com.abaco.presentacion.managedbean.PListaDepositoNoIdentificado</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
<managed-bean>
<managed-bean-name>detalleDeposito</managed-bean-name>
<managed-bean-class>com.abaco.presentacion.managedbean.PDetalleDeposito</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
如果你需要其他任何东西来检查问题,只需要它,我会尽快发布。很抱歉,在我睡觉的最后8个小时内没有写任何东西=(。
编辑2:我在其他网络浏览器中已经回顾了这个问题,结果是问题只出现在恶意的IE8中:(。有什么想法可以防止这种奇怪的行为吗?答案 0 :(得分:0)
在网上冲浪后,我发现this article帮助了我。我按照这个配置,现在我的页面A,B和C工作。
编辑:我的问题只是IE 8配置。但是在PageXBean上还有另一个问题,即RichFaces 3.3.3@KeepAlive
标记。当我使用showDialog
js函数打开pageX.jsp时,它第一次运行良好,但从第二次开始它显示错误,甚至没有调用托管bean构造函数。这让我疯了,因为没有任何关于它的线索,直到我的同事给出了这一点。我会向你展示这个问题的深度:
faces-config.xml中:
<managed-bean>
<managed-bean-name>pageX</managed-bean-name>
<managed-bean-class>com.abaco.presentacion.managedbean.PageXBean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
Bean类:
@KeepAlive(ajaxOnly=false)
public class PageXBean {
//some attributes...
public PageXBean() {
ClassX oClassX = new ClassX();
//set data into oClassX ...
try {
FacesContext objFC = FacesContext.getCurrentInstance();
Object request = objFC.getExternalContext().getRequest();
HttpServletRequest objServletRequest = (HttpServletRequest)request;
HttpSession objSesion = objServletRequest.getSession();
objSesion.setAttribute(UConstants.SessionVars.CLASS_X, oClassX);
} catch (Exception objEx) {
System.out.println("Problema al registrar variable de sesión: " +
objEx.getMessage());
}
}
//more methods and stuff...
}
所以,首先fiew没有问题,但问题是CLASS_X的值与托管bean相同:
public class UConstants {
public static class SessionVars {
public static String CLASS_X = "pageX";
}
}
这是我们问题的根源。当他将值更改为CLASS_X = "pageX2"
时,一切都开始正常工作。
希望这有助于任何人。