How to insert static HTML content

19 views
Skip to first unread message

compuroad

unread,
Nov 2, 2009, 10:17:18 PM11/2/09
to Google Web Toolkit
I would like to know if there is a built in way in GWT to read and
inject HTML content. At least 50% of the site I am planning has static
HTML content that would not benefit from GWT one page model. I am
thinking in building a application that reads the static content using
java.io.File and injects into GWT using the HTML widget.

I would like to know if there are any alternatives.

Thanks,

Wilson

rjcarr

unread,
Nov 3, 2009, 2:53:31 AM11/3/09
to Google Web Toolkit
I would suggest writing your page in the traditional way and then only
filling in GWT for the sections you need. You typically do with
placeholders as divs and tds. For example:

<body>
Here is some HTML ...
<div id="gwt"></div>
Here is more HTML ...
</body>

...

EntryPoint {
RootPanel.get("gwt").add(new Label("Here is GWT HTML ..."));
...

compuroad

unread,
Nov 3, 2009, 11:42:09 PM11/3/09
to Google Web Toolkit
Thanks for the sugestion. But what do I do with "navigation". GWT is a
"one page" show. When the user needs to create an account on the site
I need to clear the "Home" content and replace with a GWT generated
"Create Account" page/content. But since my home is static HTML, how
am I going to do it?

Robert J. Carr

unread,
Nov 4, 2009, 12:35:25 AM11/4/09
to google-we...@googlegroups.com
Well, what you say here:

"GWT is a "one page" show"

Is absolutely true. Given that, you'll have to come up with the
solution that suits you best. Some options are:

1) Don't use GWT for the login and have it redirect you to your GWT
page when you've authenticated.
2) Integrate your login into GWT and have it replace the login with
content when you've authenticated.
3) Create 2 GWT apps, one for login and one for content.

There are probably other options I'm missing ...

gwtfanb0y

unread,
Nov 4, 2009, 5:04:01 AM11/4/09
to Google Web Toolkit
I would recommend to integrate the login into the GWT page. This works
very great
for me (collected good experience with it) and is easy to implement.
So everything
looks smooth.

Ian Bambury

unread,
Nov 4, 2009, 7:09:27 AM11/4/09
to google-we...@googlegroups.com
What I do is create a complete html file for each page. This allows my site to get spidered, allows updates without recompiles, easier to write than Java strings, etc. In the GWT app, I just use requestbuilder to get the page directly, strip out the content, and put it in an HTMLPanel (so I can get at the elements by id)

There's no need for any server-side code to get and return the html.

Yozons Support on Gmail

unread,
Nov 4, 2009, 12:39:56 PM11/4/09
to google-we...@googlegroups.com
On Wed, Nov 4, 2009 at 2:04 AM, gwtfanb0y <siegfri...@googlemail.com> wrote:

I would recommend to integrate the login into the GWT page. This works
very great
for me (collected good experience with it) and is easy to implement.
So everything looks smooth.


Siegfried, what is the mechanism to start with a login page view, then switch to the application view once authenticated, but still using the same base HTML page?

How do you swap out the login page layout and put in the new one?  And presumably if your RPC shows they are no longer logged in, it can then revert back and display the login page view again.

Is there a way to create these as separate modules (new to all of this) and then have them swap in/out?  And it seems like there would be more issues for memory leaks and such doing this as you'd certainly need to be sure to clear out all objects in the other views as they change.

I know it's possible as I've seen in in gmail, switching from inbox to contacts, etc., but not clear how to make it work.  Any code examples we can study?

gwtfanb0y

unread,
Nov 5, 2009, 3:30:56 AM11/5/09
to Google Web Toolkit
In the following code snippet i am using GIN and GUICE with the MVP
Pattern. In my module, i am loading
the class 'AppPresenter':

*** MainApp.java ***
public void onModuleLoad() {
AppPresenter appPresenter = injector.getAppPresenter();
appPresenter.go(RootPanel.get());
injector.getPlaceManager().fireCurrentPlace();
}


Now follow to the method "go", you can see that the "container" is
currently null. The method "checkIsUserInSession()"
decides what to show. I am using Spring Security in the backend to
check user permissions and return a UserModel
with a simple boolean inside it (for this example i have modified it
to make it simple). The methods "showMain()" and
"showLogin()" are adding only components to the container. That's it.

*** AppPresenter.java ***
import com.google.gwt.user.client.ui.HasWidgets;

public class AppPresenter {
private HasWidgets container;

}

public void go(final HasWidgets container) {
this.container = container;
checkIsUserInSession();
}


@SuppressWarnings({"NonBooleanMethodNameMayNotStartWithQuestion"})
private void checkIsUserInSession() {
UserServiceAsync rpcService = GWT.create(UserService.class);
rpcService.getCurrentUser(new FailureCheckingAsyncCallback<UserModel>
() {
@Override
protected void doOnSuccess(UserModel result) {

//noinspection unchecked
if (result.isLoggedIn==true)
showMain();
} else {
showLogin();
}
}
}
);
}


@SuppressWarnings({"MethodOnlyUsedFromInnerClass"})
private void showMain() {
container.clear();
container.add(portalMainWidget.getDisplay().asWidget());
}


private void showLogin() {
container.clear();
container.add(loginComponent.getDisplay().asWidget());
}


Have a lot of fun!



On 4 Nov., 18:39, Yozons Support on Gmail <yoz...@gmail.com> wrote:

Yozons Support on Gmail

unread,
Nov 5, 2009, 8:00:58 PM11/5/09
to google-we...@googlegroups.com
Thanks.


On Thu, Nov 5, 2009 at 12:30 AM, gwtfanb0y <siegfri...@googlemail.com> wrote:

@SuppressWarnings({"MethodOnlyUsedFromInnerClass"})
private void showMain() {
 container.clear();
 container.add(portalMainWidget.getDisplay().asWidget());
}


private void showLogin() {
 container.clear();
 container.add(loginComponent.getDisplay().asWidget());
}


What type are the loginComponent and portalMainWidget?

David

Yozons Support on Gmail

unread,
Nov 6, 2009, 1:58:14 PM11/6/09
to siegfri...@googlemail.com, google-we...@googlegroups.com
Decided to send this directly to your email in case you missed it in the google groups.  I think your framework makes sense to me, except I'm not sure what super type (implemenst/extends) the components that you swap in and out are.  They seem to have a getDisplay() method that itself has an asWidget() method, so not sure what I'd do with my current separate pages.

Of course, my current login page and my current main app page are all objects that implement EntryPoint.  So I see I'll have a much smaller EntryPoint class in the new model, and its job will be to swap in the other two (and possible a few others as we grow, like a distinct logoff view, reset passwords, etc.) based on whether its logged in or not.  But when I move most of the code in my existing classes that implement EntryPoint, presumably they should subclass/implement something in common so that the new EntryPoint class can do the swaps (and use getDisplay().asWidget()...).

Thanks for any insights...

gwtfanb0y

unread,
Nov 9, 2009, 5:46:06 AM11/9/09
to Google Web Toolkit
They extend 'com.google.gwt.user.client.ui.Composite'.

"getDisplay().asWidget())" is a method (in use with the MVP) which
returns only the Widget:

@Override
public Widget asWidget() {
return this;
}

I do not separate my views into different EntryPoints, just use them
inside one EntryPoint
and switch them on/off with my AppPresenter.class .


On 6 Nov., 02:00, Yozons Support on Gmail <yoz...@gmail.com> wrote:
> Thanks.
>

Yozons Support on Gmail

unread,
Nov 9, 2009, 8:06:49 PM11/9/09
to google-we...@googlegroups.com
On Mon, Nov 9, 2009 at 2:46 AM, gwtfanb0y <siegfri...@googlemail.com> wrote:

They extend 'com.google.gwt.user.client.ui.Composite'.

"getDisplay().asWidget())" is a method (in use with the MVP) which
returns only the Widget:

 @Override
 public Widget asWidget() {
     return this;
 }


Thanks for the answer.  I don't know what getDisplay() does or where it's defined, but I figured I didn't really need it.  I think I am now doing more or less the same as you, but my "page view objects" just return their topmost panel which is set into the app presenter's RootPanel, which in my case also does the EntryPoint.  It seems to work great.

I suppose there's no time benefit to downloading of the application page views (I think there's some code splitting that may help in the now or in the future with 2.0), but it does snap nicely between views.

Thanks again...

gwtfanb0y

unread,
Nov 10, 2009, 5:14:07 AM11/10/09
to Google Web Toolkit
You are right, "getDisplay" is only an Interface and was not useful
for this example.
So you have moved from many to only one EntryPoint?

With code splitting in GWT 2.0 i think it is possible to show the user
a "loading in progress"-view,
like the same when your browser opens a big flash page.


On 10 Nov., 02:06, Yozons Support on Gmail <yoz...@gmail.com> wrote:

Yozons Support on Gmail

unread,
Nov 10, 2009, 8:52:23 PM11/10/09
to google-we...@googlegroups.com
Yes, I only have one EntryPoint now and it does look nicer and is snappier.   I'll worry about code splitting later, I suppose.  Right now, it's fine that everything is downloaded together.  Hopefully it won't be too big a deal to partition it once that feature is available.
Reply all
Reply to author
Forward
0 new messages