JPro-one / JPro

The right place to report about bugs or suggest improvements for JPro.
https://www.jpro.one
9 stars 4 forks source link

Many issues related to webAPI.getURLQueryParams() #124

Closed ctoabidmaqbool closed 1 year ago

ctoabidmaqbool commented 2 years ago
  1. When first load page getURLQueryParams() return empty parms e.g. {} image

  2. When page is refresh then getURLQueryParams() return correct parms e.g. {category=xyz} image image

  3. When another page is opened e.g. /info?content=abc previous parms are showing e.g. {category=xyz} image

Please Try to fix this error / issue

Note: Sample project: https://github.com/Maqbool-Solutions-SMC-Pvt-Ltd/jpro-web-url-parms-test

FlorianKirmaier commented 2 years ago

The WebAPI only shows the parameters of the start of the application. If you are using jpro-web (or now named jpro-routing), you can access the changed query-parameters by parsing the URL of the page in the route. But we are currently also redesigning the framework - to directly provide the query parameters as a Map (and many many more improvements)

ctoabidmaqbool commented 1 year ago

Hi! Devs, It's a long time of waiting period!

Still issue of webAPI.getURLQueryParams() is not resolved.

Is currently there is only way to get URL Query Parameters using JavaScript? Or there is anything I am missing?

In the above code clicking Get Parm button shows null value, if firstly this URL is opened e.g. 'https://localhost:8080'

package com.jpro.hellojpro;

import com.jpro.routing.LinkUtil;
import com.jpro.routing.Route;
import com.jpro.routing.RouteApp;
import com.jpro.routing.View;
import com.jpro.webapi.WebAPI;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

import static com.jpro.routing.RouteUtils.get;
import static com.jpro.routing.RouteUtils.redirect;

public class App extends RouteApp {
    private Stage pStage;

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

    @Override
    public void start(Stage pStage) {
        this.pStage = pStage;
        super.start(pStage);

//        SessionManager sessionManager = SessionManager.getDefault(getRouteNode(), getStage());
//        sessionManager.start();
    }

    @Override
    public Route createRoute() {
        return Route.empty()
                .and(redirect("/", "/info"))
                .and(get("/info", (r) -> new InfoPage(pStage)));
    }
}

class InfoPage extends View {
    private Stage pStage;

    public InfoPage(Stage pStage) {
        this.pStage = pStage;
    }

    @Override
    public String title() {
        return "Sample JPro Page";
    }

    @Override
    public String description() {
        return "This is a simple page where JPro testing done.";
    }

    @Override
    public Node content() {
        VBox root = new VBox(10);
        root.setAlignment(Pos.CENTER);
        root.setPrefSize(500, 1000);

//        Label lblText2 = new Label("Home");
//        LinkUtil.gotoPage(lblText, "/");

        Label lblText2 = new Label("Info with Parm");
        LinkUtil.setLink(lblText2, "/info?q=About");

        Button btnGetParm = new Button("Get Parm");
        btnGetParm.setOnAction(event -> {
            System.out.println("q: " + WebAPI.getWebAPI(pStage).getURLQueryParams().get("q"));
        });

        if (WebAPI.getWebAPI(pStage).getURLQueryParams().get("q") != null) {
            btnGetParm.fire();
        }

        root.getChildren().addAll(lblText2, btnGetParm);

        return root;
    }
}
FlorianKirmaier commented 1 year ago

The Request contains all the information you need.

.and(get("/info", (r) -> new InfoPage(pStage)));

The r parameter is the request. It contains all the query parameters and other information, which might be interesting to you.

Currently, the WebAPI only contains the initial query parameters - which is usually interesting for applications, which don't use the routing.

ctoabidmaqbool commented 1 year ago

Okay, Something like this codding solved out the my issues related to Get URL Query Parameters e.g. r.queryParameters()

package com.jpro.hellojpro;

import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.control.Label;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import one.jpro.routing.LinkUtil;
import one.jpro.routing.Route;
import one.jpro.routing.RouteApp;
import one.jpro.routing.View;
import simplefx.experimental.parts.FXFuture;

import static one.jpro.routing.RouteUtils.get;
import static one.jpro.routing.RouteUtils.redirect;

public class App extends RouteApp {
    private Stage pStage;

    @Override
    public void start(Stage pStage) {
        this.pStage = pStage;
        super.start(pStage);
    }

    @Override
    public Route createRoute() {
        return Route.empty()
                .and(r -> {
                    System.out.println("prams: " + r.queryParameters());
                    System.out.println("pram: q= " + r.queryParameters().get("q"));
                    System.out.println("pram: email= " + r.queryParameters().get("email"));

                    return FXFuture.unit(null);
                })
                .and(redirect("/", "/info"))
                .and(get("/info", (r) -> new InfoPage(pStage)));
    }
}

class InfoPage extends View {
    private Stage pStage;

    public InfoPage(Stage pStage) {
        this.pStage = pStage;
    }

    @Override
    public String title() {
        return "Sample JPro Page";
    }

    @Override
    public String description() {
        return "This is a simple page where JPro testing done.";
    }

    @Override
    public Node content() {
        VBox root = new VBox(10);
        root.setAlignment(Pos.CENTER);
        root.setPrefSize(500, 1000);

        Label lblText2 = new Label("Info with Parm");
        LinkUtil.setLink(lblText2, "/info?q=About&email=cto.ms@outlook.com");

        root.getChildren().addAll(lblText2);

        return root;
    }
}

I get these values in console when route contains values:

prams: Map(q -> About, email -> cto.ms@outlook.com)
pram: q= Some(About)
pram: email= Some(cto.ms@outlook.com)

The confusion is why r.queryParameters().get("q") returns Some(value) not simple value?

ctoabidmaqbool commented 1 year ago

prams: Map(q -> About, email -> cto.ms@outlook.com) pram: q= Some(About) pram: email= Some(cto.ms@outlook.com)

Okey!

System.out.println("pram: q= " + r.queryParameters().get("q").get());

Solve the issue, e.g. then Some(value) no longer will be returned rather only value will be returned.

FlorianKirmaier commented 1 year ago

For now, it's a Scala collection. It might change at some time, but it is what it is for now.