here's one approach to running GWT apps from within Web2py (approach 
adapted from basic pyjs' approach).

in your controller e.g., user.py
def gwtapp():
    return dict()

in applications/app/static directory place war directory (rename war to 
enable use of multiple GWT apps) e.g., app1

in applications/app/views directory create user/gwtapp.html
in this file place the main HTML file from your GWT app.
You can edit this file to your hearts contents but the essential change is:
<script type="text/javascript" language="javascript" src="{{=URL(r=request,
c='static',f='app1/gwtapp_name/gwtapp_name.nocache.js')}}"></script>

Place any functions you want your GWT client app to call in the controller 
user.py.

That's all the web2py requirements.

In your GWT Java file, to perform JSON calls you'll need to call a function 
in a Web2py controller function...

A hack is required to construct such URLs.

To create an URL for the function get_user_profile() call the following 
function and append "get_user_profile"

private static String GET_SERVER_URL() {
String url = GWT.getHostPageBaseURL();
if (!GWT.isScript()) {
url = url.replace(":8888", ":8000");
url += "init/user/";
 }
return url;
}

private static final String JSON_URL = GET_SERVER_URL();

This will return the correct content whether you run Web2py or dev_appserver
.py (both of which run GWT JavaScript) or run the Development Mode of GWT 
which runs Java byte code (ie !isScript()). For the latter, you'll need to 
launch your Web2py server app on default 127.0.0.1:8000 and the GWT 
Development Mode app on default 127.0.0.1:8888.

Setting up a call to the server might look like this:
 RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, 
URL.encode(JSON_URL 
+ "get_user_profile"));

I've left out Java import statement but IDEs will typically shout and 
insert them for you.





On Friday, 8 June 2012 15:39:46 UTC+1, Carl wrote:
>
> Here's my crack at the question:
>
> how can I have an HTML file in web2py/applications/init rather than in 
> Web2py's "special" static directory?
>
> Here's why I'm asking this question. if anyone thinks I should be asking 
> a different question, constructive questions welcomed.
> I'm using GWT which has GWT.getModuleBaseURL() to return the path to its 
> "root" directory. I need this path to create an URL to call my Web2py 
> Server function (in web2py/applications/init/controllers/default).
>
> If I place my GWT static files in web2py/applications/init/static then GWT
> .getModuleBaseURL() returns domain.com/init/static. I want it to return 
> domain.com instead.
>
>
>
>

Reply via email to