-1

There is this strange situation I'm fighting on. I have 3 pages, les call them A, B and C. Every page has its own Managed Bean in request scope: MB1, MB2 and MB3, respectively. When I enter on A, MB1 is created. From A, I call a window.showModalDialog to open B and every time B its opened MB2 is created. The strangeness starts when I call page C from B with window.showModalDialog, and MB3 gets created once. This behavior is driving me insane, because I have done things like this and its the first time this is happening.

I must also say that MB1 and MB2 have the @KeepAlive annotation (similar to use the a4j:keepAlive tag component, and MB3 is a clean managed bean.

I'm open to any ideas to solve the problem. I'm currently working with JSF 1.2, RichFaces 3.3.3 and JBoss EAP 5.1.

Thanks for your time and sorry for my bad english!

EDIT 1: The source code for pages A, B and 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>

page 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>

page C (a simple jsf page which does nothing):

<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>

If you need anything else to check the problem, just ask for it and I'll post it as soon as I can. By te way, sorry for not write anything in the last 8 hours I was sleeping =(.

EDIT 2: I have reviewed this issue in other web explorers, and the result was that the problem it only appears in the spiteful IE8 :(. Any ideas what to do to prevent this odd behavior?

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • Could you share the source code? – Adrian Mitev Feb 02 '12 at 05:12
  • How do you know that MB3 is created only once ? – prajeesh kumar Feb 05 '12 at 05:40
  • @prajeeshkumar Because when I go to page 3 it shows the same information. In the constructor of MB3 I add this logic to get some data from a session variable which is set in MB2. Plus, I change this session var in MB2 when I select a radio button and before pageB shows pageC or get closed by this button Select (which was not posted in pageB code) and returns to MB1, where info is showed correctly. – Luiggi Mendoza Feb 05 '12 at 16:35

1 Answers1

0

After surfing in the web, I found this article which helped me. I followed that configuration and now my pages A, B and C works.

EDIT: My problem was just an IE 8 configuration. But there was another issue on a PageXBean with the RichFaces 3.3.3 @KeepAlive tag. When I opened pageX.jsp with the showDialog js function, the first time it worked nice, but from the second onwards it showed an error and the managed bean constructor was not even called. This was driving me insane because there was no clue about it, until my co-worker gave with the point. I'll show you the problem in depth:

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 class:

@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...
}

So, at first fiew there was no problem, BUT the thing was that the value of CLASS_X was the same as the managed bean:

public class UConstants {
    public static class SessionVars {
        public static String CLASS_X = "pageX";
    }
}

This was the root of our problems. When he changed the value to CLASS_X = "pageX2" everything started to work normally.

Hope this helps anyone.

Community
  • 1
  • 1
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • How exactly would it solve the problem for all other website visitors? Are you going to show some warning message that they have to change their browser settings in order to get your website to work? – BalusC Feb 07 '12 at 00:09
  • @BalusC sorry to edit my question after all this time. There was no warning in the browser, just the odd behavior but it was a IE8 configuration. I described a major problem and the solution. – Luiggi Mendoza Feb 16 '12 at 15:45