我正在努力爭取這種奇怪的情況。我有3個頁面,它們稱它們爲A,B和C.每個頁面在請求範圍中分別有自己的Managed Bean:MB1,MB2和MB3。當我在A上輸入時,會創建MB1。從A中,我調用window.showModalDialog來打開B,每次B打開它的MB2被創建。當我使用window.showModalDialog從B調用頁面C時,奇怪開始,並且MB3被創建一次。這種行爲令我瘋狂,因爲我已經做了這樣的事情,並且第一次發生這種事情。請求範圍中的受管Bean保持創建狀態
我也必須說,MB1和MB2有@KeepAlive註釋(類似於使用a4j:keepAlive
標籤成分,MB3是乾淨的託管Bean。
我歡迎任何想法來解決這個問題。我目前正在與JSF 1.2,RichFaces的3.3.3和JBoss EAP 5.1工作
感謝您的時間和我的英語不好對不起
編輯1:!爲網頁A,B和C的源代碼:
page 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 :(。任何想法做些什麼來防止這種奇怪的行爲?
你能分享源代碼嗎? – 2012-02-02 05:12:17
你怎麼知道MB3只創建一次? – 2012-02-05 05:40:54
@prajeeshkumar因爲當我轉到第3頁時,它顯示了相同的信息。在MB3的構造函數中,我添加了這個邏輯以從MB2中設置的會話變量中獲取一些數據。另外,當我選擇一個單選按鈕並在pageB顯示pageC之前,或者通過此按鈕選擇關閉(它不在pageB代碼中發佈)並返回到信息顯示正確的MB1時,我在MB2中更改此會話變量。 – 2012-02-05 16:35:15