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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:38:22+00:00 2026-05-24T23:38:22+00:00

When i use command button to redirect to pages, inside my project, u just

  • 0

When i use command button to redirect to pages, inside my project, u just need to give the name of the page with no extention, followed by ?faces-redirect=true in the action attribute and i will get redirected.

But what if i want to get redirected to an external page(example:www.google.com)?

I tried in many ways:

http://www.google.com, google.com, http://google.com

but i failed.

This is what i did:

<h:form>
            <h:commandButton 
                action="#{mainPageBB.goToLink}" value="#{msgs.clickhere}"/>
        </h:form>

and then the backing bean:

@Named("mainPageBB")
@RequestScoped
public class MainPageBB {

    @EJB
    private ILinkManagerEJB linkManagerEJB;


    public String goToLink() {      
        String link = linkManagerEJB.retrieveLink();
        if(link != null) {
                    System.out.println(link);       
            return link.trim() + "?faces-redirect=true";
        }
        return null;
    }

Note: the value returned by retrieveLink(); is always http://www.google.com(100% sure)

I get no errors at all in the console, the page just refreshes. Also i am sure the first if clause validates to true, so i see no reason for it to jump to return null.

Update

I tried with external context, but i get a 404 because it appends the current url to the link string:

public String goToRandomLink() {        
        String link = linkManagerEJB.retrieveRandomLink();
        if(link != null) {      
            ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
            try {
                externalContext.redirect(link.trim());
            } catch (IOException e) {               
                e.printStackTrace();
            }           
        }
        return null;
    }
  • 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-24T23:38:23+00:00Added an answer on May 24, 2026 at 11:38 pm

    Use ExternalContext.redirect()

    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    externalContext.redirect(link.trim());
    

    and if you know the link already just use

    <a href="#{someBean.someLink}">#{msg.someMessage}</a>

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

Sidebar

Related Questions

I have a page with a dynamically created command button. I need to dynamically
When I use the Command in a Button control the event handler which joined
I have a bunch of Seam form pages; each has a command button that
I'm trying to use the navigation command framework in WPF to navigate between Pages
I am trying to bind the command of a button inside a datacontext to
I am working on a project in which I want to use the command
How can I use command line arguments in a creationComplete event handler? It seems
You can use command lsof to get file descriptors for all running processes, but
i use the command line in windows to compile and then execute my java
We use the command line to pass on system properties to the Java virtual

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.