Retrieve external URL from backend and perform a redirection after clicking on the <p:button> element

I have a task that I am working on where I need to display a button. The target URL for this button is obtained by making a SOAP request to an external third party (Single Sign In) which provides the sign-in URL. I want to ensure that my page's load time is not affected by this request, so I am looking to implement the SOAP request asynchronously when the button is clicked. This will then open the URL in a new tab or window. Here is what I have tried so far:

<p:button id="ssi" target="_blank" href="#{backbean.soaprequest}" value="button name" widgetVar="ssiButton" onclick="ssiButton.disable()" />

However, this approach still waits for the SOAP request to complete before rendering the page.

I have also experimented with other solutions but have not made any progress.

I would greatly appreciate any help or suggestions you can offer. Thank you!

Answer ā„–1

Here is a helpful way to do it:

Click on the button below:

<p:commandButton value="Login" 
                 actionListener="#{backbean.soaprequest()}" 
                 oncomplete="handleComplete(xhr, status, args)" />

Method soaprequest():

public void soaprequest() {
    //perform your request here, replace the link with your login URL
    RequestContext context = RequestContext.getCurrentInstance();  
    context.addCallbackParam("url", "http://google.com");//replace this with your link  
}

Javascript Function:

function handleComplete(xhr, status, args) {  
  window.location = args.url;     
} 

We hope this solution works for you.

Answer ā„–2

My xhtml section contains the following code snippet:

<p:outputPanel autoUpdate="true" layout="inline">
     <p:button id="ssibutton" target="_blank" href="#{backbean.link}" value="Button"/>
</p:outputPanel>

<p:remoteCommand  name="soap_request"
     process="@this"
     update="ssibutton"
     actionListener="#{backbean.url}" />

<script type="text/javascript">
    $(document).ready(function() {soap_request();});            
</script>

In the Backbean class:

private String url;

public Backbean(){
     url = " ";
}

public String getLink(){
     return url;
}

public void url(ActionEvent event){
     //Perform SOAP request to retrieve URL
     this.url;
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Remove the "href" from Zend2 navigation functionality

When using Zend2 navigation from an array passed in Zend\Navigation\Navigation, everything works smoothly if child items are opened on parent item mouse hover. However, undesirable actions occur when they are opened on mouse click, as the user is ...

Is it still relevant to use ng-repeat track by in AngularJS 1.6?

Is using track by in Angular 1.6 with ng-repeat still considered beneficial? Does it contribute to better performance? ...

Discord.js Error: Unable to access undefined properties for 'username'

victim is a variable containing the user's ID input. Despite confirming it as a valid user ID on the server, I encounter the error 'cannot read properties of undefined' This is my first time using client.users.cache.get(victim).username in ...

How to store an imported JSON file in a variable using TypeScript

I am facing a challenge with a JSON file that stores crucial data in the following format { "login": { "email": "Email", "firstName": "First name", "lastName": "Last name", ...

Unable to see the tokens on the connect four board when using Javascript and HTML

I'm currently developing a game of connect four using javascript, html, and css. I'm encountering an issue with the refreshGrid() function in game.js. At the moment, when I run my html file, I only see an empty board. The function is meant to ena ...

Leveraging the power of Ajax, jQuery, and JSON within the CakePHP

In the realm of cakephp 1.3, I am seeking to breathe life into a <div> within my form (*.ctp) by populating it with data retrieved from a mysql table. Despite delving into numerous examples on this platform, none seem to reveal the full picture. The ...

Tips for Implementing Show and Hide Functionality in JavaScript

I have a piece of cshtml code similar to the following: <span class="p1"> Breaking India: Western Interventions in Dravidian and Dalit Faultlines is a book authored by Rajiv Malhotra and Aravindan Neelakandan, arguing ...

Guide to implementing nested asynchronous calls using a foreach loop

I am eager to enhance my skills and gain a better understanding of how to improve this code. While the current code is functioning, I suspect there may be an issue that needs addressing. Here's the concept: 1: Initially, I send the first HTTP request ...

Issues within jQuery internal workings, implementing improved exception handling for fn.bind/fn.apply on draggable elements

I've been experimenting with wrapping JavaScript try/catch blocks as demonstrated on this link. It functions properly, essentially encapsulating code in a try/catch block to handle errors like so: $.handleErrors(function(e){ console.log("an erro ...

Tips for accessing image data generated by the Bootstrap File Input plugin

I have a div that utilizes the Bootstrap File Input plugin to select, show, change, and cancel images. The image data is generated dynamically by the plugin. <div class="fileinput fileinput-new" data-provides="fileinput"> <div class="fileinpu ...

The viewport width in NextJS does not extend across the entire screen on mobile devices

I'm currently tackling a challenge with my NextJS Website project. It's the first time this issue has arisen for me. Typically, I set the body width to 100% or 100vw and everything works smoothly. However, upon switching to a mobile device, I not ...

The challenge of populating information within a Datalist

In my code snippet, I have a JavaScript function that is used to populate a Datalist: function PopulateDropDown(facility) { $.ajax({ url: '/Rentals/Base/GetContactsForFacility?selectedFacility=' + facility, data: { facility: ...

Is there a Ruby gem similar to Readability that anyone can recommend?

Readability is a nifty JavaScript tool that magically transforms a cluttered HTML page into a more user-friendly format. I'm on the hunt for a Ruby implementation or something along those lines - does anyone know of a library that offers similar funct ...

Cross-site communication with Ajax using both POST and GET requests

As a beginner in JavaScript, I'm facing challenges with implementing ajax POST and GET requests. While I can successfully do it using Google Postman as shown here https://i.sstatic.net/Cegxj.pnghttps://i.sstatic.net/ovJT0.png, the problem arises when ...

Tips for retrieving the user-input value from an HTML text field

Exploring the world of JS, I set out to create a basic calculator after just one week of lessons. However, I hit a roadblock when trying to extract user-input values from my HTML text fields. Here's a snippet of my html: <div class="conta ...

Testing for ajax failure using Q-Unit in a unit test

While utilizing jQuery's $.when method to manage ajax callbacks, I am also implementing mockjax for simulating various responses in my unit tests. One of these responses results in a status error of 500. Unfortunately, when catching this error using Q ...

Disable form submission in MVC using a JavaScript function

In my project, there is an upload.ascx file that will be loaded inside a Jquery Popup. The upload.ascx file contains a File Upload control that uploads .xlsx and .xls files. To validate the file uploads and prevent unnecessary files from being uploaded, I ...

Tips for retaining spaces in a multiline string when setting a helm value using cdktf

Currently, I am utilizing CDKTF to facilitate the deployment of the datadog helm chart into a kubernetes cluster. My objective is to assign a specific value to confd, however, the issue arises when the spaces in my typescript multiline string do not mainta ...

What are the steps needed to establish a distinct data scope in AngularJS along with the application of filters?

Iā€™m currently practicing my skills in AngularJS and I have been experimenting with creating reusable components. At this stage, I have successfully created a component using the directive method. However, I now have some doubts that I need clarification ...

Unable to attach an event listener to an element fetched from an API

I'm currently in the process of developing a trivia web application using an API, and my goal is to incorporate an event listener onto the button which corresponds to the correct answer. This way, when users click on it, a message will appear confirmi ...