0

I'm a beginner in GWT. Currently I'm trying to create an Web application in Spring to consume data from REST and displays those details in GWT. So, I used Spring RestTemplate for client(to make a request and unmarshalling to java Object) and left the Dependency Injection to Spring(annotation). I have developed these entire thing in Eclipse IDE which has GWT-2.4 plugin.

I have tried to start this Web Application in below Cases and facing the specified issues.

Case #1: When i'm trying to start the application as Google Web Application (Right Click -> Run as -> Google Web Application), The dependency injection is not happening, It throws NullPointerException on an Property reference. I guess when i'm starting as Google App it doesn't makes my Context Loaded and thus Bean-DI is not happening.

Case #2: While trying to Run on Tomcat Server, all my Bean Creation and Dependency Injection are happening, but it doesn't make an EntryPoint for GWT. I have not defined any Controller explicitly, because i'm in the thought of GWT will take care of it(as like running in Google Web App Server).

NOTE: The Application is working perfectly when i'm running the GWT modules seperately(not consumes the data from WebService) and even Spring RestTemplate Module working as good enough in consume RestService and displays the values in System.Out.println().

The core issue is in making an Interaction between GWT and Spring DI.

Project.gwt.xml:

<inherits name='com.google.gwt.user.User'/>
<inherits name='com.google.gwt.user.theme.clean.Clean'/>

<entry-point class='com.abc.XXXX.gwt.ui.client.XXXX'/>

  <source path='client'/>
  <source path='shared'/>
  <source path='service'/>

ApplicationContext.xml:

<context:component-scan base-package="com.serco.XXXX" />

<context:property-placeholder location="classpath:ClientConfig.properties" />

<bean id="clientSkillService" class="com.abc.XXXX.gwt.ui.service.clientService.impl.ClientSkillService"
    p:hostName="${rest.hostName}"
    p:portNumber="${rest.port}"
    p:userName="${rest.userName}"
    p:password="${rest.password}">
</bean>

<bean id="restTemplate" class="org.springframework.web.client.RestTemplate">
    <property name="messageConverters">
        <list>
            <bean class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter">
                <constructor-arg>
                    <bean class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
                        <property name="classesToBeBound">
                            <list>
                                <value>com.abc.XXXX.gwt.ui.shared.SkillDetailList</value>
                                <value>com.abc.XXXX.gwt.ui.shared.SkillDetail</value>
                            </list>
                        </property>
                    </bean>
                </constructor-arg>
            </bean>
        </list>
    </property>
</bean>

Web.xml:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
    classpath:ApplicationContext.xml
    </param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Kindly provide your suggestion, how to make it work.

Thanks in Advance.

Updated: HTML File

 <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>XYZ UI DASHBOARD</title>
    <script type="text/javascript" language="javascript" src="RTSocketDataMonitor/RTSocketDataMonitor.nocache.js"></script>
  </head>
  <body>
    <h1 align="center">XYZ UI DASHBOARD</h1>
    <div align="center" id="grid_tbl"></div>
</body>

Entry Point Class: XXXX.java

public class XXXX implements EntryPoint {
    /*entry point method*/
    public void onModuleLoad() {
        //Creation of DialogBoxes and Panel here
        DialogBox dialogBox;
        //Creation of Composite Derived Class which has DataGrid, DataList, Columnprovider properties to render Details in Table format
        SkillDetailPaginationHandler<SkillDetail> skd = 
        new SkillDetailPaginationHandler<SkillDetail>();
        //added VertiCal Panel in Dialogue Boxes and set it in RootPanel
        RootPanel.get("grid_tbl").add(dialogBox);
    }
}

GWT Compiled WAR Contents:

  ->Root
      -->XXXX(Folder in the Project Name)
        -->gwt(Folder)
        -->XXXX.nocache.js
        -->host.html
      -->WEB-INF (Folder)
        --> deploy
        --> lib 
        --> web.xml
omega
  • 592
  • 2
  • 5
  • 21

1 Answers1

0

You need to separate both the modules in separate project.

You need to compile the GWT module first and then put its generated files in the main Web project and then from the controller of the web application call the .html file of the GWT project. I hope you understood this and it helps you.

Japan Trivedi
  • 4,445
  • 2
  • 23
  • 44
  • Thanks for your reply. Can you please elaborate, where we need to place the GWT Compiled Project (i'm assuming it is the WAR content) in "Main Web Project"?. Appreciate if you have given some examples. – omega Oct 19 '12 at 12:16
  • Right now I am not having its example. You can create a new folder under the WEB-INF directory or parallel to it. You need to just use the path where you have the main html file or GWT and call it from your controller. – Japan Trivedi Oct 19 '12 at 12:38
  • I have compiled the GWT module and placed adjacent to WEB-INF folder. When I start up the tomcat server, It renders the HTML file(static content), but not as a GWT application. (Actually i have DataGrid which will dispatch to this HTML in `OnModuleLoad()` method) Am i missing anything here?. (Updated HTML file in this post) – omega Oct 22 '12 at 09:00
  • What is the content of the GWT compiled folder? The JS and other contents are in the same folder? – Japan Trivedi Oct 22 '12 at 09:34
  • Please find the content details in the POST. – omega Oct 22 '12 at 11:03
  • Everything looks fine. Please check the path specified in the html is correct or not. Otherwise this should work properly. – Japan Trivedi Oct 22 '12 at 12:04
  • Ok, let me check it. This is for my understanding, How does the `onModuleLoad()` method in `EntryPoint` Class will be invoked during tomcat startup?, Does it is based upon the `XXXX.noCache.js` or anyother thing?... – omega Oct 22 '12 at 13:54
  • Yup!... Its working now i can able to see the hardcoded data. But when i try to get the Details(data) from RestTemplate, It throws Exception during GWT Compile time. **[ERROR] : public class org.springframework.web.client.RestTemplate** Does it ask it to inherit in gwt.xml? – omega Oct 22 '12 at 14:25
  • I'm not sure about using rest template in GWT. You need to figure it out somehow. – Japan Trivedi Oct 23 '12 at 02:16
  • @omega If you want GWT to use RestTemplate, you need to include the sources (so a jar containing the actual .java source files, not the normal dependency containing compiled class files). GWT needs the raw source files for the javascript compilation. I see a few problems with this, most notably that you'll probably need atleast GWT 2.8 (for java 8 support), and I'm not source there is a sources jar available for RestTemplate. In all honesty, trying to use Spring code on the client side might be possible with some technical effort but I wouldn't recommend it. – FrederikVH Jun 21 '18 at 12:48