Hello Stokes,
the behaviour of variables is based on the URI specification
(http://gbiv.com/protocols/uri/rfc/rfc3986.html).
This spec definies precisely each part of an Uri, give them a name and a
list of allowed characters.
For example :
- a segment can contain alphabetical characters, digital characters,
and the "=" character...
- a query is "like" a segment except that it can contain "/" and "?"...
That makes the difference!
Given the following Uri template : "/foos/{fooid}?{fooQuery}".
If the "fooid" and "fooQuery" variables are defined as segments (which
is the default type), the following Url will be matched :
"/foos/123?key=value".
We all agree that this query is "normal".
However, the following query is also correct but will not be matched the
Uri template : "/foos/123?key=value?key2=value?"...
If you think that your queries will be "normal", just keep the default
variable type, otherwise change it to "TYPE_URI_QUERY".
Best regards,
Thierry Boileau
Thierry Boileau <thboileau <at> gmail.com> writes:
Ooops,
I forget : you also need to set the "equals" mode when routing to
fooListFinder, otherwise this route will catch the "garbage" URLs.
Best regards,
Thierry Boileau
Thanks, that worked for me. I did need the "?{fooQuery}" part, although I
forgot to add the Variable part and it still worked as I expected. What does
the new Variable do?
Stokes.
[...]
route =
component.getDefaultHost().attach("/foos/{fooid}?{fooQuery}", ,
<FooFinder>);
route.getTemplate().setMatchingMode(Template.MODE_EQUALS);
//In this case, the variable "fooQuery" is redefined : it's a
query variable, and it is not required (in order to allow such URIs :
/foos/123?).
Variable variable = new Variable(Variable.TYPE_URI_QUERY, "",
false, false);
route.getTemplate().getVariables().put("fooQuery", variable);