Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8313469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:29:56+00:00 2026-06-08T20:29:56+00:00

I have 2 jsf pages, each of them have a managed bean. I’m navigating

  • 0

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?

This is my code:

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>

Thank’s In Advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:29:58+00:00Added an answer on June 8, 2026 at 8:29 pm

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

    See also:

    • How to choose the right bean scope?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JSF page that is included in other JSF pages (basically a
If I have a JSF page that I want to link to where I
I have two input components on my page . Each of them has a
I currently have a table displayed on one of my jsf pages, bound to
I have used Tomahawk <t:selectOneRadio> in my jsf page. I have reserved one boolean
I have several jsf pages. I need to add dynamic breadcrumbs to the header.xhtml.
I have problem with setting proper charset on my jsf pages. I use MySql
Suppose i have JSF page <h:body> <h:form id=formID prependId=false> <h:outputText id=randomID value=#{randomNumber.random}/> <h:commandButton id=buttonID
i have a jsf page which displays an image from an url http://ichart.finance.yahoo.com/z?s=^NSEI&t=1d&q=l&l=on&z=l&p=s&a=v&p=s i
I have a JSF page that displays a RichFaces Treeview, from a TreeNodeImpl model

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.