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 6777997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:12:52+00:00 2026-05-26T16:12:52+00:00

I’working on a enterprise application that uses JSF 2.0, with Netbeans 7.0 and Glassfish

  • 0

I’working on a enterprise application that uses JSF 2.0, with Netbeans 7.0 and Glassfish 3.1
I have a managed bean that is ViewScoped. this is the declaration of the class:

@ManagedBean(name = "myBean")
@ViewScoped
public class MyMBean implements Serializable {

Inside its @PostConstruct, it has the following:

String id = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id");    
if (id == null) {
    try {
        FacesContext.getCurrentInstance().getExternalContext().redirect("home.xhtml");
        FacesContext.getCurrentInstance().responseComplete();
    } catch (Exception e) { }
    return;
}

if I go to the page that uses this managed bean, and the id is null, everything works fine, and I get redirected to home page.
The problem is that when I navigate to a different page that does NOT use this managed bean (lets say for example “otherpage.xhtml”) the PostConstruct method is executed, and it shouldn’t! And it gets worse: since the url of this other page doesn’t have the “id” parameter, the bean tries to redirect to home page; and I get a IllegalStateException.

Any idea of why a viewscoped managed bean is constructed when navigating to a page that does not use it?

Edit:
If in order to navigate to “otherpage.xhtml” I use the commandlink in “home.xhtml”, 6 extra beans are created.
But, if instead of using the link, I type the url in the browser; it works fine. No extra bean is created. Maybe there’s something wrong in how I implemented the link. This is the code:

<h:form>
    <h:commandLink value="Go to other page" action="otherPage" />
</h:form>

And this is the navigation rule in faces-config:

 <navigation-rule>
        <from-view-id>*</from-view-id>
        <navigation-case>
            <from-outcome>otherPage</from-outcome>
            <to-view-id>/views/otherPage.xhtml</to-view-id>
            <redirect/>
        </navigation-case>
</navigation-rule>

Is there anything wrong there?

Thanks!
Damian

  • 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-05-26T16:12:52+00:00Added an answer on May 26, 2026 at 4:12 pm

    You surely have a #{myBean} somewhere in the view or one of its templates/include/tag/composite files, or as a @ManagedProperty of the beans referenced by the view. Putting a breakpoint in the (post)constructor and investigating the stacktrace should give enough insights who/what has triggered the bean’s construction.


    Unrelated to the concrete problem, the ExternalContext#redirect() already implicitly calls FacesContext#responseComplete(), you don’t need to call it yourself. See also the method’s javadoc.


    Update: a <h:commandLink> submits its parent POST <form> to the current page (and thus creates all its related beans!) and then depending on the navigation outcome, it will forward/redirect to the result page. You shouldn’t be using commandlinks/commandbuttons for plain page-to-page navigation. Use <h:link> instead.

    <h:link value="Go to other page" outcome="views/otherPage" />
    

    You can eventually also get rid of that <navigation-case>. If you really insist in keeping that navigation case, then use outcome="otherPage" instead.

    See also:

    • When should I use h:outputLink instead of h:commandLink?
    • Communication in JSF 2.0 – Implicit navigation
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have a French site that I want to parse, but am running into
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I know there's a lot of other questions out there that deal with this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.