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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:18:07+00:00 2026-06-12T11:18:07+00:00

I am trying to get started with JSF 2.0. I am trying a basic

  • 0

I am trying to get started with JSF 2.0. I am trying a basic navigation example and it’s not working properly.

The file structure is the following:

enter image description here

I have configured the mapping in web.xml:

<!-- Change to "Production" when you are ready to deploy -->
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<!-- Welcome page -->
<welcome-file-list>
    <welcome-file>index.xhtml</welcome-file>
</welcome-file-list>

<!-- JSF mapping -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

And the index page has 2 buttons which take you to different pages when clicked

The faces-config.xml file defines some navigation cases:

<!-- Configuration of navigation rules -->  
<navigation-rule>
    <from-view-id>/index.xhtml</from-view-id> 
    <navigation-case>
        <from-outcome>success</from-outcome>
        <to-view-id>/pages/success.xhtml</to-view-id>
    </navigation-case>
     <navigation-case>
        <from-outcome>error</from-outcome>
        <to-view-id>/pages/error.xhtml</to-view-id>
    </navigation-case>
</navigation-rule>

E.g. the following button should take you to the success page (/pages/success.xhtml):

<p:commandButton id="addUser" value="Add" action="#{userMB.addUser}" ajax="false"/>

I have debugged this an the return value of addUser is definitely “success”.

The page switches to success.xhtml because I see the content is changed, but the browser URL points to index.xhtml….

At startup: URL is localhost:8080/PROJECT/ with no index.xhtml probably because we configured it as the welcome file. When we hit the button above, the URL becomes localhost:8080/PROJECT/index.xhtml

I believe I have messed up something with the mappings or the relative paths. I have found some advice that the only mapping should be the one with *.xhtml but I did not really understand why and how to address multiple subfolders of pages.

Any help is appreciated, thanks

  • 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-12T11:18:08+00:00Added an answer on June 12, 2026 at 11:18 am

    The page switches to success.xhtml because I see the content is changed, but the browser URL points to index.xhtml.

    This is normal behaviour. The HTML <form action> points to /index.xhtml and the form will thus be submitted to exactly that URL, but behind the scenes, the response is showing the content of /pages/success.xhtml.

    If you want a change in the URL, then you need to perform a redirect. You can do that by adding <redirect/> to the <navigation-case> in question.

    <navigation-case>
        <from-outcome>success</from-outcome>
        <to-view-id>/pages/success.xhtml</to-view-id>
        <redirect/>
    </navigation-case>
    

    See also:

    • What is the difference between redirect and navigation/forward and when to use what?

    Unrelated to the concrete problem, using navigation cases are soo JSF 1.x. Consider utilizing the new JSF 2.0 implicit navigation feature. This saves you from verbose XML hell.

    public String addUser() {
        if (...) {
            return "/pages/success.xhtml?faces-redirect=true";
        } else {
            return "/pages/error.xhtml?faces-redirect=true";
        }
    }
    

    I’d however recommend just adding faces messages and then redisplaying the very same page by returning void or null instead of navigating to a “success” or “error” page, that’s also how real web forms work. Unless you’re doing some “Hello World”, of course.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get started with scons . I have Python 3.0.1 and
i'm trying to get started with silverlight 2. i have a weird bug. every
I am trying to get started working with NHibernate. I went to download the
Trying to get started with subsonic but have a simple question about stored procedures
I am trying to get started with pic24's, specifically the PIC24FJ64GA002, and I have
I'm trying to get started with Amazon's EC2. I have to choose an image
I have some experience with NHibernate and I'm trying to get started with Castle
I'm trying to get started with spine.js following the steps here: http://spinejs.com/docs/started When i
I'm trying to get started working with sift feature extraction using (C++) OpenCv. I
I'm trying to get started with this library: 32feet I have a Broadcomm Bluetooth

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.