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

The Archive Base Latest Questions

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

I have a JSF 1.2 / Seam 2.2.2 application. I have button and on

  • 0

I have a JSF 1.2 / Seam 2.2.2 application. I have button and on click of the button, I run validations on the objects in current page, query for some dependent objects and run validation. If the validation passes, then I need to redirect the user to the new page. Otherwise, I need to display validation errors in the same page. Below code works fine and error message is displayed. But how to I redirect to a new page?

<h:messages id="errorMsg" errorClass="errorMessages" />
<a4j:commandButton action="#{myController.shouldRedirectToNewPage()}"
                value="Button" styleClass="button" />

public void shouldRedirectToNewPage() {
    //Run validation on objects in the current page
    //Query for dependent objects and run validation
    if(validationFails) {
       facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR,
          "ERROR MESSAGE", null)); 
       return;
   }
}
  • 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:22:01+00:00Added an answer on May 26, 2026 at 4:22 pm

    Either use ExternalContext#redirect():

    public void shouldRedirectToNewPage() throws IOException {
        // ...
    
        if (validationFails) {
            facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR MESSAGE", null));
        } else {
            facesContext.getExternalContext().redirect("otherpage.jsf");
        }
    }
    

    or return a navigation case string the usual way:

    public String shouldRedirectToNewPage() {
        // ...
    
        if (validationFails) {
            facesContext.addMessage(null, new FacesMessage(FacesMessage.SEVERITY_ERROR, "ERROR MESSAGE", null));
            return null;
        } else {
            return "otherpage";
        }
    }
    

    with the following in faces-config.xml:

    <navigation-case>
        <from-outcome>otherpage</from-outcome>
        <to-view-id>/otherpage.jsf</to-view-id>
        <redirect/>
    </navigation-case>
    

    (note the <redirect/>, this makes it a redirect instead of a (default) forward)


    Unrelated to the concrete problem, doing validation inside the action method isn’t necessarily the best practice. It should be done by a Validator. If it throws a ValidatorException, then the action method simply won’t be invoked.

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

Sidebar

Related Questions

Ok simple question. I have a JSF application, containing a login page. The problem
I have a JSF page that has a h:form that has some textfields and
i have a JSF/Seam Page and added a new not HTML Interface. I reused
I have a seam web application and for one page I have an hardcoded
Have JSF 1.2 two pages(one.xhtml and other.xhtml), that are included to the current page
I have a JSF/Seam web app which has a page with a form which,
For my current project I'm working with JSF, Seam and Hibernate and I have
Is there any documentation about introducing jBoss seam to an old Hibernate/JSF project? Have
I have a JSF application that uses mostly Richfaces. I would like to introduce
i have a JSF web application. I use Beans as Spring Beans (not JSF

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.