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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:30:27+00:00 2026-05-16T23:30:27+00:00

Consider a page webapp/myPage.xhtml : … <h:form id=myForm> … <h:selectOneMenu id=… required=true value=#{myController.aValue}> <f:selectItems

  • 0

Consider a page webapp/myPage.xhtml:

...
<h:form id="myForm">
    ...
    <h:selectOneMenu id="..." required="true" value="#{myController.aValue}">
       <f:selectItems value="#{...}" var="..." itemValue="#{...}" itemLabel="#{...}"/>
    </h:selectOneMenu>
    ...
    <h:commandButton value="Go for it!" action="#{myController.goForIt(...)}"/>
    ...
</h:form>
...

The button action is bound to a controller method MyController.goForIt():

@ManagedBean(name = "myController")
@RequestScoped
public class MyController {
   public String goForIt(...){
      if (myCondition){
         try {
            FacesContext.getCurrentInstance().getExternalContext()
                        .redirect("http://www.myTarget.com/thePage.html");
         } catch (IOException e) {
           ...
         }
      }
      return "myPage.xhtml"   
   }
}

My first question is: Does the above makes sense? Is this a correct way of using redirect()?

I want to redirect the user to http://www.myTarget.com/thePage.html in case myCondition is true. If myCondition is false, he will have to stay on myPage.xhtml.

If so, I would like to understand better what happens… When using Live HTTP Headers in Firefox, I observe that when clicking the button

  1. a POST to webapp/myPage.xhtml occurs
  2. the server replies with 302 Moved Temporarily – Location: http://www.myTarget.com/thePage.html
  3. the browser GET’s http://www.myTarget.com/thePage.html

So far, Is this the expected behaviour?

What I find annoying now is that webapp/myPage.xhtml is called. More specifically, that the preRenderView-event is called here again. (I have a bit of code in the preRenderView-listener that should be executed only once.)

Does the above make sense? Does anybody see a way to improve this?

Thank you! J.

  • 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-16T23:30:28+00:00Added an answer on May 16, 2026 at 11:30 pm

    So far, Is this the expected behaviour?

    A redirect basically instructs the client to fire a new HTTP request on the URL as specified in the Location response header. So yes, the behaviour as you’re seeing is correct.

    However, your URL is wrong. It’s relative to the current request URL. So if the current URL is for example http://example.com/context/page.jsf, then this redirect will basically point to http://example.com/context/www.myTarget.com/thePage.html which is obviously wrong. When the new URL concerns a different domain, you should redirect to an absolute URL. In other words, prefix it with the http:// scheme.

    What I find annoying now is that webapp/myPage.xhtml is called.

    This should in theory not happen when the redirect has taken place. Try adding return null to the try block.

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

Sidebar

Related Questions

Consider the following jsf page: <h:body> <h:form id=SessionStartDialog> <table> <tr> <td class=label> <h:outputLabel value=Enter
Consider the following simple html page markup: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN
Consider the page as below (pseudocode) <header> <search> <form> <input text> <input submit> </form>
Consider a page with the following code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Strict//EN
Consider this page @ http://www.bloodbone.ws/screwed.html I need to be able to have the a.grow
Consider a hiddenfield in the page HfId <input type=hidden id=HfId/> How to assign,clear and
I hava a HTML page on server. consider an article example is loaded in
Consider the following markup: <!DOCTYPE html> <html> <head> <title>Test Page</title> <link href=screen.css rel=stylesheet />
Consider the following Mechanize form object #<Mechanize::Form {name f1} {method POST} {action f.php} {fields
Consider a web page having grid-view connected to SqlDataSource having all permission to insert

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.