JSF administró el objeto de destrucción de frijoles al navegar a un mb diferente

I have 2 jsf pages, each of them have a managed bean. I'm navigating out of the second page to the first one , and want to destroy the entity object inside of it. my problem is that after i set it to null , It still going into the getDetails method which creates a new entity..

how can I prevent it from going to the getDetails method when exiting this page? how can I destroy this entity correctly? am I doing somthing wrong?

Este es mi codigo:

public class page2MB {

@EJB
private page2SessionBean page2SessionBean;
private Page2 page2;

public page2MB() {
}

public Page2 getDetails()
{
    if(page2 == null)
    {
        Map requestParams = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();   
        page2 = new Page2();  
        page2.setPage2PK(new Page2PK(Short.parseShort((String)requestParams.get("param1")),
                                          Short.parseShort((String)requestParams.get("param2"))));            

        page2 = page2SessionBean.find(page2);    
    }        
    return page2;
}

public String exit() 
{       
    try
    {
        page2 = null;
        return "page1";
    }
    catch(Exception exp)
    {                      
        exp.printStackTrace();
        return "";
    } 
    finally
    {

    }
}    
}

page2.xhtml:

<f:view>
       <h:form>                              
            <h:panelGrid columns="2">                
                <h:inputText id="page2PKfield1" value="#{page2MB.details.page2PK.field1}"/>                                                                   
                <h:inputText id="page1MBfield1" value="#{page1MB.details.field1}"/>                                                   
                <h:inputText id="page2MBfield2" value="#{page2MB.details.page2PK.field2}"/>                                            
                <h:inputText id="field2Desc" value="#{page2MB.details.field2Desc}"/>                    
            </h:panelGrid>                                
            <h:commandButton id="exit"   value="יציאה" action="#{page2MB.exit}" immediate="true"></h:commandButton>                                     
        </h:form>
    </f:view>

Gracias de antemano.

preguntado el 31 de julio de 12 a las 12:07

¿Por qué no puedes usar un @ViewScoped ¿frijol? -

@eljunior: beacuse it has to be session scoped. I have more actions on this page which requires to be in session scoped mode.. -

1 Respuestas

beacuse it has to be session scoped. I have more actions on this page which requires to be in session scoped mode.

Don't mix data which belongs in different scopes in a single bean in the broadest possible scope. Create separate beans in different scopes which are proper for the data the bean holds and inject the one bean in the other bean using @ManagedProperty.

@ManagedBean
@SessionScoped
public class SessionBean {

    private Object sessionData;

    // ...
}
@ManagedBean
@ViewScoped
public class ViewBean {

    @ManagedProperty("#{sessionBean}")
    private SessionBean sessionBean;

    private Object viewData;

    // ...
}

Also don't do the business job in getters. Rather do it in the @PostConstruct método.

Ver también:

Respondido el 20 de junio de 20 a las 10:06

Thank's for the answer, I've chaned the bean to view scoped, y agregó el @PostConstruct and also started using the @ManagedProperty. I just have one more problem - when I'm navigating to the page2.xhtml (by using return "page2") I see page2 with the correct values but it is not rtl like it's supposed to be and also I can't view it's source. what am I missing? - user590586

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.