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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:10:28+00:00 2026-06-10T05:10:28+00:00

I have to perform two operations on button click. call a method in a

  • 0

I have to perform two operations on button click.

  1. call a method in a bean which will return a url and it will be set in some variable.

  2. after that I have to open that url in another tab. I am using the action attribute of CommandButton and it is setting the URL value correctly, but how do I open that url as pdf in a new tab. i.e “URL of pdf should open in a new tab”

Code sample as follows:

<div class="form-options">
    <h:commandButton value="Download Report" styleClass="btn btn-primary btn-icon buttonCustom" actionListener="#{reportBean.GenerateReport}">
    </h:commandButton>
</div>  
  • 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-10T05:10:29+00:00Added an answer on June 10, 2026 at 5:10 am

    Hope I unterstood you right. This worked for me:

    1. Provide the method generating the report and the URL in the actionListener-attribute of the commandButton (what you already did, according to your sample code).
    2. Provide the method returning the URL in the action-attribute of the commandButton (it will be called after the actionListener-method).
    3. For opening a new tab, add target="_blank in the parent <h:form> (taken from this questions answer)

    XHTML-Code:

    <h:form target="_blank">
        <h:commandButton value="Show Report" 
                         actionListener="#{reportBean.generateReport}"
                         action="#{reportBean.getUrl}" />
    </h:form>
    

    As this approach applies the target="_blank" to all non-ajax calls, here’s another way using Javascript:

    <h:form>
        <h:commandButton value="Show Report" 
                         actionListener="#{reportBean.generateReport}"
                         action="#{reportBean.getUrl}" 
                         onclick="this.form.target='_blank'"/>
    </h:form>
    

    Java-Code:

    public void generateReport(final ActionEvent evt) {
        // ... generating report and setting url-variable
    }
    
    
    public String getUrl() {
        return url;
    }
    

    If you have to forward to an external link, see this question

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

Sidebar

Related Questions

If I have two queries, which I will call horrible_query_1 and ugly_query_2 , and
I'm having some problems trying to perform a query. I have two tables, one
I have two buttons, and their click events perform an ajax operation. I need
I have one button. When i click on this button, it will show one
I have a model called RaceWeek. Two operations I want to perform: (1) I
You have two servers when you perform a SQL Server database mirroring You have
I have a web application that uses two databases. DB1 Users perform their CRUD
I have to perform a large number of replacements in some documents, and the
I will have to perform a spelling check-like operation in Python as follows: I
I am using sqlite in my iPhone app. I have some database operations, in

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.