Project

General

Profile

URL parameters chenging and ParameterMap

Added by Sergey Bryukov almost 12 years ago

Hello

1. user comes with URL http://localhost/?_=landing#/

appInstance->environmet().getParameter("_") returns "landing"

2. user enter http://localhost/?_=landing¶m1=888#/

getParameter("_") returns "landing"

getParameter("param1") returns "888"

3. Calling then setInternalPath("landing&param1=999#/") sets URL to the http://localhost/?_=landing%26param1=999%23/¶m1=888

Now I have two of param1. Also ParameterMap for this URL gives map like below:

'_' = 'landing&param1=999#/'

'param1' = '888'

Im not shure if I see correct bechaviour, but Wt reports 'using /?_= for internal path' but it set internal path not discribed way


Replies (10)

RE: URL parameters chenging and ParameterMap - Added by Koen Deforche almost 12 years ago

Hey,

When using '?' for internal paths, Wt will indeed use the '' parameter to encode the internal path in the URL, giving the behavior that you see.

You should not really use this for a production deployment, there is no reason to stick with these ugly URLS.

From what you show here, I don't see anything wrong ? You should not be reading the '_' parameter but work with internalPath() and setInternalPath().

Regards,

koen

RE: URL parameters chenging and ParameterMap - Added by Sergey Bryukov over 11 years ago

Hi, thanks for short explanation. Now I build path and params like

http://localhost:8080/?_=landing&p1=242&p2=qqqq&p3=8888

so that, Wt::Http::ParameterMap contains below parameters:

_ : landing

p1 : 242

p2 : qqqq

p3 : 8888

One more question. Whet I setInternalPath( "landing&p1=242" ) it swap '&' with '%26'. So that I see http://localhost:8080/?_=landing%26p1=242

but Wt::WApplication::instance()->environment().getParameterMap() doesn't pars URL corectly in case of '%26'

Sergey

RE: URL parameters chenging and ParameterMap - Added by Koen Deforche over 11 years ago

Hey,

landing&p1=242 doesn't sound like a typical internal path, these would typically only contain '/' to separate folders.

In fact, because '&' is a special token it escapes it, since it's not intended that this is interpreted as a parameter separator !

The idea is that setInternalPath() and internalPath() [e.g. in a new session] are compatible also for special characters which get escaped and un-escaped as needed.

Regards,

koen

RE: URL parameters chenging and ParameterMap - Added by Sergey Bryukov over 11 years ago

Hi Koen

would you be so kind give an example of URL. Im interesting in geting/updating params using /?_= for internal path

thanks Sergey

RE: URL parameters chenging and ParameterMap - Added by Jeff Flesher over 10 years ago

Sergey, did you ever figure this out?

I am stuck on this same problem.

RE: URL parameters chenging and ParameterMap - Added by Koen Deforche over 10 years ago

Hey,

I guess I'm not really understanding the question... Examples of internal paths are:

/examples

/examples/simplechat

These are in fact actual internal paths of the homepage:

http://www.webtoolkit.eu/wt

I guess that is not really your question, but I'm failing to see what is exactly your misunderstanding?

Regards,

koen

RE: URL parameters chenging and ParameterMap - Added by d3fault d3fault over 10 years ago

Koen, I think the problem most users (myself included) are running into is this: how are we intended to mix internal paths and HTTP GET parameters?

Before you say "don't, just use internal paths further", consider this use case:

A directory/file server

domain.com/directory?sort=date

If I were to use internal paths further and do "domain.com/directory/date", then I wouldn't be able to view a file named "date" in that directory.

I would be happy to use #date or ?sort=date, but using internal paths is not an option (unless... you have a solution?)...

And of course there's still the problem of htmlEncoding when setInternalPath is called :-/....

Thanks for the great framework,

d3fault

RE: URL parameters chenging and ParameterMap - Added by d3fault d3fault over 10 years ago

I know how to sort by date etc using only internal state, I watered down the example to make it clear. But there are lots of similar use cases where a bookmarkable URL is desired but can't be achieved without using either an HTTP GET param or one of those #anchor things, or else there are naming conflicts as in my directory example.

I tried using WAnchor(WLink(WLink::Url, "/directory?sort=date"), "sort by date", root()), as suggested in a mailing list thread ( http://permalink.gmane.org/gmane.comp.web.witty.general/9451 ), but that resulted in my constructor being called again when the anchor is clicked and internalPathChanged never being emitted :(

RE: URL parameters chenging and ParameterMap - Added by Koen Deforche over 10 years ago

Hey,

There is no problem with interpreting the initial parameters. If you want to represent an action like sorting in the URL, which is orthogonal on your path structure, then indeed internal paths will be hard to work with.

But you can encode this information into your internal paths components, like you suggest.

/directoryfilter.file

or as special internal path components:

/directory/filter.file

The main problem with allowing real parameters (?sort=date) is that there is no way to implement this in pre-HTML5 browsers. Wt's internal path architecture actually predates HTML5 so that would feel like a major breaking change in Wt.

Regards,

koen

RE: URL parameters chenging and ParameterMap - Added by Jeff Flesher over 10 years ago

Really it just come down to how you want to handle parameters, an example I did not test, but should work would be:

void MyClass::init()
{
    Wt::WApplication *app = Wt::WApplication::instance();
    app->internalPathChanged().connect(this, &MyClass::handlePathChange);
}

void MyClass::handlePathChange(const std::string& path)
{
    Wt::WApplication *app = wApp;
    std::string directoryPath = app->internalPathNextPart("/directory/");
    if (!directoryPath.empty())
    {
        if (directoryPath == "date")
        {
            // Sort by Date
        }
        if (directoryPath == "id")
        {
            // Sort by id
        }
    }
}
    (1-10/10)