Eclipse Wiki Weblog

All | General | Java | Eclipse | Groovy | Grails | GWT | Google | MathEclipse | Bliki
20061215 Friday December 15, 2006

How to integrate a GWT module in a new JAMWiki Special: page

Note: this document is work in progress and not complete at the moment

Contents
  1. An AJAX calculator example
  2. Creating a new Special:Calc page
  3. Integrating the GWT module
  4. Introductory articles

An AJAX calculator example

My example GWT module is the MathEclipse AJAX calculator called org.matheclipse.gwt.Calc which is separately developed in the GWT hosted mode and should now be included into a new JAMWiki Special:Calc page.

In the main GWT EntryPoint in the method org.matheclipse.gwt.client.Calc#onModuleLoad() we can distinguish between non-hosted mode and hosted mode with the GWT.isScript() method. In the onModuleLoad() method we also create the main calculator GUI panel and insert it into a prepared "slot1" in calc.jsp (see below).

 public void onModuleLoad() {
   CALC_SERVICE = (CalcServiceAsync) GWT.create(CalcService.class);
   ServiceDefTarget target = (ServiceDefTarget) CALC_SERVICE;
   if (GWT.isScript()) {
     String url = GWT.getModuleBaseURL();
     url += "calc"; 
     target.setServiceEntryPoint(url);
   } else {
     target.setServiceEntryPoint("/calc");
   }
 ...
   // Create a panel for the GUI and insert it into a prepared "slot1" in cals.jsp
   RootPanel slot1 = RootPanel.get("slot1");
   slot1.add(panel);
 ...

Creating a new Special:Calc page

 protected ModelAndView handleJAMWikiRequest(HttpServletRequest request, HttpServletResponse response, ModelAndView next, WikiPageInfo pageInfo) throws Exception {
   pageInfo.setPageTitle(new WikiMessage("calc.title"));
   pageInfo.setAction(WikiPageInfo.ACTION_CALC);
   pageInfo.setSpecial(true);
   return next;
 }
 calc.title=AJAX online calculator

 ...
 public static final int ACTION_CALC = 999;
 ...
 public boolean getActionCalc() {
     return (this.action == ACTION_CALC);
 }

<c:when test="${pageInfo.actionCalc}">
  <jsp:include page="calc.jsp" flush="true" />
</c:when>

Integrating the GWT module

Note:In the following I assume that your JAMWiki Application-URI is /wiki

In a separated GWT project I compiled all GWT files with the GWTCompiler from Java to JavaScript into the \www\org.matheclipse.gwt.Calc directory. These files must now been copied into a JAMWiki subdirectory.

For a better organization all compiled (static) GWT files in this example go into subdirectory:

 /wiki/static

and the main gwt.js is stored in

 /wiki/static/gwt.js

 /www/org.matheclipse.gwt.Calc 

directory into the directory

 /wiki/static/org.matheclipse.gwt.Calc

<meta name='gwt:module' content='/wiki/static/org.matheclipse.gwt.Calc=org.matheclipse.gwt.Calc'>

 <%@ page errorPage="/WEB-INF/jsp/error.jsp"
    contentType="text/html; charset=utf-8"
 %>
 <%@ include file="page-init.jsp" %>
 <-- <GWT CSS styles follow in this section -->
 <style type="text/css">
   ... 
 </style>
 <script language='javascript' src='/wiki/static/gwt.js'></script>
    <iframe id='__gwt_historyFrame' style='width:0;height:0;border:0'></iframe>
    <div id="loadingWait">Loading...</div>
       <table align="left" verticalalign="top">
	<tr><td id="slot1"></td></tr>
       </table>

 ...
 <servlet>
   <servlet-name>calculator</servlet-name>
     <servlet-class>org.matheclipse.gwt.server.CalcServiceImpl</servlet-class>
   <load-on-startup>1</load-on-startup>
 </servlet>
 ...
 <servlet-mapping>
   <servlet-name>calculator</servlet-name>
   <url-pattern>/static/org.matheclipse.gwt.Calc/calc</url-pattern>
 </servlet-mapping>

Introductory articles

Posted by axelclk ( Dec 15 2006, 11:01:57 PM CET ) Permalink Comments [0]

Calendar

Links

Search

del.icio.us Tag Cloud

RSS Feeds

Navigation

Referers