0

I'm new using jsf framework, and i speak intermediate english, so i hope you can understand my problem. I have this situation:

this is the content in my file abmEstaciones.xhtml

            <ui:define name="contenido">
    <div class="box">
        <div class="box-header">
            <h3 class="box-title">Lista de Estaciones</h3>
        </div>
        <!-- /.box-header -->
        <div style="margin-top: 3%; margin-bottom: 2%;">
            <h:message for="Alta" style="color:green; font-weight: bold;" />
            <h:form id="Alta">
                <h:commandLink styleClass="btn btn-success"
                    action="#{estacionMbReq.visualizarAltaEstacion}">
                    <i class="fa fa-plus-circle"></i>
                    <span class="menu-title">Agregar</span>
                </h:commandLink>
            </h:form> 
        </div>
        <div class="box-body table-responsive">

            <h:outputText value="No hay estaciones" style="color:red; font-weight: bold;" rendered="#{empty estacionMbReq.listaEstaciones}" />
            <h:dataTable id="example1" rendered="#{not empty estacionMbReq.listaEstaciones}" value="#{estacionMbReq.listaEstaciones}"
                var="estacion" styleClass="table table-bordered table-striped">

                <h:column>
                    <f:facet name="header">Nombre</f:facet>
                #{estacion.nombre}
            </h:column>
                <h:column>
                    <f:facet name="header">Total Estacionamientos</f:facet>
                #{estacion.totalEstacionamientos}
            </h:column>
                <h:column>
                    <f:facet name="header">Cant. Estacionamientos libres</f:facet>
                #{estacion.cantEstacionamientosLibres}
            </h:column>
                <h:column>
                    <f:facet name="header">Estado</f:facet>
                #{estacion.estado}
            </h:column>

                <h:column>
                    <f:facet name="header">Opciones</f:facet>
                    <h:form id="formOpcTabla" name="formOpcTabla">
                        <h:commandLink
                            action="#{estacionMbSess.visualizarModificarEstacion}"
                            styleClass="btn btn-primary">
                            <i class="fa fa-edit"></i> Editar
                            <f:param name="idEstacion" value="#{estacion.idEstacion}" />
                        </h:commandLink>
                        <h:commandLink styleClass="btn btn-danger"
                            action="#{estacionMbSess.borradoLogico}">
                            <i class="fa fa-eraser"></i> Eliminar
                        <f:param name="idEstacion" value="#{estacion.idEstacion}" />
                        </h:commandLink>
                    </h:form>
                </h:column>
            </h:dataTable>

        </div>
        <!-- /.box-body -->
    </div>
    <!-- /.box -->
</ui:define>

and this are the navigation rules in faces-config.xml

    <navigation-rule>
    <from-view-id>/abmEstaciones.xhtml</from-view-id>
    <navigation-case>
        <from-action>#{estacionMbReq.visualizarAltaEstacion}</from-action>
        <from-outcome>successVisualizarAltaEstacion</from-outcome>
        <to-view-id>/altaEstacion.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-action>#{estacionMbSess.visualizarModificarEstacion}</from-action>
        <from-outcome>successVisualizarModificarEstacion</from-outcome>
        <to-view-id>/modificarEstacion.xhtml</to-view-id>
    </navigation-case>
    <navigation-case>
        <from-action>#{estacionMbSess.borradoLogico}</from-action>
        <from-outcome>listarEstaciones</from-outcome>
        <to-view-id>/abmEstaciones.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

I'm trying to use two managed beans in the view, on the one hand "EstacionMbReq" with requestScoped annotation, and on the other hand "EstacionMbSess" with SessionScoped annotation. The problem is that when i click the "Editar" or "Eliminar" commandLinks, it executes the constructor of the managedBean with name "EstacionMbReq" instead of the managedBean that i specify: "EstacionMbSess".

Any help? is possible to use two managedBeans in the same view? thank you

  • Not sure if this helps you to solve your problem: [Can I use multiple managed bean in the same xhtml page?](http://stackoverflow.com/q/18919545/1065197) – Luiggi Mendoza Aug 20 '15 at 22:51
  • Also, I recommend you to avoid writing any business logic code in constructors, instead use a method decorated with `@PostConstruct`. Review the basics of the scopes of the variables in Java web [here](http://stackoverflow.com/q/16619015/1065197), JSF just reuses these concepts. – Luiggi Mendoza Aug 20 '15 at 22:55

1 Answers1

0

Constructor EstacionMbSess is executed only one time per HTTP user session, and was happened before processing click request. EstacionMbReq is created every time when you send request from this page.

sibnick
  • 3,995
  • 20
  • 20