0

I am trying to get SweetAlert to work in JavaFx WebView.

I have a Web Application which uses SweetAlert in place of the default browser alert. Everything works fine when viewed through a conventional browsers.

Now I want to have have the same Web App run through JavaFx WebView.

The Problem is: The SweetAlert Confirm dialog box is not working in the JavaFx WebView.

This is the Ajax with the SweetAlert Code:


    $(document).on('click', '#confirmOverage', function(e){
            e.preventDefault();
            $(this).attr("disabled",true);

            var overageID = $(this).attr('overageValue');

            if(overageID !== ""){
                swal({
                    title: "Are You Sure ?",
                    text: "Do you really want to confirm this overage deposit ?",
                    icon: "info",
                    buttons: true,
                    dangerMode: true,
                    closeOnClickOutside: false,
                })
                .then((willDelete) => {
                    if (willDelete) {
                        $.ajax({
                            url: '<?=$fn;?>',
                            method: 'POST',
                            dataType: 'text',
                            data: {
                                oi: overageID
                            },
                            success: function(successResponse){
                                if(successResponse !== "" && successResponse.includes("SUCCESS:") === true){
                                   successResponse = successResponse.replace("SUCCESS: ",""); 

                                    swal({
                                        title: "SUCCESS !",
                                        text: successResponse,
                                        icon: "success",
                                        closeOnClickOutside: false,
                                    });
                                }
                                else{
                                    if(successResponse.includes("SORRY !") === true){
                                        successResponse = successResponse.replace("SORRY !","");
                                    }
                                    else if(successResponse.includes("SORRY!") === true){
                                        successResponse = successResponse.replace("SORRY!","");
                                    }
                                    else if(successResponse.includes("Sorry!") === true){
                                        successResponse = successResponse.replace("Sorry!","");
                                    }
                                    else if(successResponse.includes("Sorry,") === true){
                                        successResponse = successResponse.replace("Sorry,","");
                                    }
                                    swal({
                                        title: "SORRY !",
                                        text: successResponse,
                                        icon: "error",
                                        closeOnClickOutside: false,
                                    });
                                }
                            }
                        });                  
                    }
                    else{
                        $(this).attr("disabled",false);
                    }
                });
            }
            else{
                swal({
                    title: "SORRY !",
                    text: "The Overage Parameter is required. Please Check and try again. Thank you",
                    icon: "error",
                    closeOnClickOutside: false,
                }); 
                $(this).attr("disabled",false);
            }
        })

This is the JavaFx WebView Code :

import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import javafx.stage.Stage;



public class main extends Application{

    String url = "https://www.url.com/index.php";

    public static void main(String[] args){
        Application.launch(args);
    }


    @Override
    public void start(Stage stage) throws Exception{

        WebView myWebView = new WebView();
        WebEngine engine = myWebView.getEngine();        
        engine.load(url);
        engine.getConfirmHandler();

        VBox root = new VBox();
        root.getChildren().addAll(myWebView);

        Scene scene = new Scene(root);
        stage.setTitle("SCHOOL MANAGEMENT SYSTEM");
        stage.setScene(scene);
        stage.show();

    }

}

Please, what is wrong and what is the correct way of doing this ?

Any help is appreciated. Thank you

MACWILCY
  • 1
  • 2
  • I normally download the js file and follow [this](https://stackoverflow.com/questions/19083070/javafx-webview-load-local-javascript-file). I don't see where you are loading the js library. – SedJ601 Jul 04 '19 at 14:03
  • Also, have a look at [this](https://stackoverflow.com/questions/19418626/javafx-search-and-highlight-text-add-search-bar-for-loaded-web-page). – SedJ601 Jul 04 '19 at 14:04
  • @Sedrick I appreciate your response, viewed the two links, none provided the solution I needed. The Second Link came close. I mine own case, the web app already have a functional SweetAlert, The problem is how to get the JavaFX WebView recognize the SweetAlert when a link is clicked. – MACWILCY Jul 04 '19 at 21:34

1 Answers1

0

I have finally solved the problem.

I think the issue wasn't with the JavaFx WebView.

I changed SweetAlert promise call:

.then((willDelete) => {
     if (willDelete) {
        ......
        ......
     }
 });

To This

.then(function(proceed) {
    if (proceed) {
      .......
      .......
    }
 });

That solved the problem.

This might help someone in the future

MACWILCY
  • 1
  • 2