Hi,
On 19/06/10 15:34, Thierry Boileau wrote:
> Hello Kevin,
>
> at this time, the application is instantiated and attached, when handling the
> first request. The main reason is that the context path of the app is not
> known by advance.
> You can still get this value as follow:
> ServletContext context = (ServletContext) getContext().getAttributes()
> .get("org.restlet.ext.servlet.ServletContext");
> System.out.println(context.getContextPath());
In addition, if you're not sure whether you're going to be in a servlet
environment, you could do something along these lines in your root
application, with the main router:
Router router = new Router(getContext()) {
@Override
public void handle(Request request, Response response) {
String rootUrl =
getContext().getParameters().get(BASE_URL_CTX_PARAM);
if (rootUrl == null) {
rootUrl = request.getRootRef().toString() + "/";
getContext().getParameters().set(BASE_URL_CTX_PARAM,
rootUrl);
// set up the menus
}
super.handle(request, response);
}
};
This way, setting up the menu is done when the first request comes in,
before it's processed by the router. (This probably needs some
synchronization on the parameters too.)
Best wishes,
Bruno.
------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2624269