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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:38:18+00:00 2026-05-19T12:38:18+00:00

From an action in my bean, I’m trying to redirect to another page expecting

  • 0

From an action in my bean, I’m trying to redirect to another page expecting a view parameter. What is the recommended way to do this in JSF2?

E.g., say my source page is:
http://localhost/page1.xhtml

it has a commandButton that calls an action:

<h:commandButton value="submit" action="#{myBean.submit}" />

where my bean looks like:

@ManagedBean
@RequestScoped
public class MyBean {

private int id;

public String submit() {
    //Does stuff
    id = setID();
    return "success";
}

And now, I want the ‘submit’ action’s return to navigate to
http://localhost/page2.xhtml?id=2

I’ve tried to do this with a view-param in my navigation case, but with odd results. The faces-config snippet looks like the following:

<navigation-rule>
    <from-view-id>/page1.xhtml</from-view-id>
    <navigation-case>
        <from-outcome>success</from-outcome>
        <to-view-id>/page2.xhtml</to-view-id>
        <redirect>
            <view-param>
                <name>id</name>
                <value>#{myBean.id}</value>
            </view-param>
        </redirect>
    </navigation-case>
</navigation-rule>

The weird behaviour being, even though myBean is set to request scoped, it only calls myBean.getId() the first time I load my application, and reuses that same value for all subsequent calls, producing incorrect view parameters for page2.

So I’m looking for either a better way to do this, or a reason/solution for why the view-param is not being requested from my bean each time.

  • 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-19T12:38:18+00:00Added an answer on May 19, 2026 at 12:38 pm

    The unintuitive thing about passing parameters in JSF is that you do not decide what to send (in the action), but rather what you wish to receive (in the target page).

    When you do an action that ends with a redirect, the target page metadata is loaded and all required parameters are read and appended to the url as params.

    Note that this is exactly the same mechanism as with any other JSF binding: you cannot read inputText’s value from one place and have it write somewhere else. The value expression defined in viewParam is used both for reading (before the redirect) and for writing (after the redirect).

    With your bean you just do:

    @ManagedBean
    @RequestScoped
    public class MyBean {
    
    private int id;
    
    public String submit() {
        //Does stuff
        id = setID();
        return "success?faces-redirect=true&includeViewParams=true";
    }
    
    // setter and getter for id
    

    If the receiving side has:

        <f:metadata>
            <f:viewParam name="id" value="#{myBean.id}" />
        </f:metadata>
    

    It will do exactly what you want.

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

Sidebar

Related Questions

Possible Duplicate: pass data from Action To Another Action I have a view in
I want to send parameter from action to view which is not it's view,
To pass a hidden parameter from a JSF 2.0 Managed BEan action handler to
Is there a way in Spring I can access some session bean from another
I am calling a page from another with a prerender view event in an
I want to modify a view from Action Helper in Zend Framework in preDispatch()
I used TempData to pass data from an action to another,but when i refresh
Is there any way of providing a file download from a JSF backing bean
* Unable to find matching navigation case with from-view-id '/home.xhtml' for action 'MemoServlet' with
I am trying to load a value into a field on a view from

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.