GWT app new branch
This commit is contained in:
parent
4d800396b8
commit
5d2d79308e
|
@ -0,0 +1,116 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<!-- POM file generated with GWT webAppCreator -->
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>google_web_toolkit</artifactId>
|
||||
<packaging>war</packaging>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<name>com.baeldung.Google_web_toolkit</name>
|
||||
|
||||
<properties>
|
||||
|
||||
<!-- Setting maven.compiler.source to something different to 1.8
|
||||
needs that you configure the sourceLevel in gwt-maven-plugin since
|
||||
GWT compiler 2.8 requires 1.8 (see gwt-maven-plugin block below) -->
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
|
||||
<!-- Don't let your Mac use a crazy non-standard encoding -->
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- ensure all GWT deps use the same version (unless overridden) -->
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt</artifactId>
|
||||
<version>2.8.2</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-servlet</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-user</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.gwt</groupId>
|
||||
<artifactId>gwt-dev</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<!-- Output classes directly into the webapp, so that IDEs and "mvn process-classes" update them in DevMode -->
|
||||
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
|
||||
|
||||
<plugins>
|
||||
|
||||
<!-- GWT Maven Plugin-->
|
||||
<plugin>
|
||||
<groupId>net.ltgt.gwt.maven</groupId>
|
||||
<artifactId>gwt-maven-plugin</artifactId>
|
||||
<version>1.0-rc-8</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
<goal>test</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<moduleName>com.baeldung.Google_web_toolkit</moduleName>
|
||||
<moduleShortName>Google_web_toolkit</moduleShortName>
|
||||
<failOnError>true</failOnError>
|
||||
<!-- GWT compiler 2.8 requires 1.8, hence define sourceLevel here if you use
|
||||
a different source language for java compilation -->
|
||||
<sourceLevel>1.8</sourceLevel>
|
||||
<!-- Compiler configuration -->
|
||||
<compilerArgs>
|
||||
<!-- Ask GWT to create the Story of Your Compile (SOYC) (gwt:compile) -->
|
||||
<arg>-compileReport</arg>
|
||||
<arg>-XcompilerMetrics</arg>
|
||||
</compilerArgs>
|
||||
<!-- DevMode configuration -->
|
||||
<warDir>${project.build.directory}/${project.build.finalName}</warDir>
|
||||
<classpathScope>compile+runtime</classpathScope>
|
||||
<!-- URL(s) that should be opened by DevMode (gwt:devmode). -->
|
||||
<startupUrls>
|
||||
<startupUrl>Google_web_toolkit.html</startupUrl>
|
||||
</startupUrls>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<!-- Skip normal test execution, we use gwt:test instead -->
|
||||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.17</version>
|
||||
<configuration>
|
||||
<skip>true</skip>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,31 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
When updating your version of GWT, you should also update this DTD reference,
|
||||
so that your app can take advantage of the latest GWT module capabilities.
|
||||
-->
|
||||
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.8.2//EN"
|
||||
"http://gwtproject.org/doctype/2.8.2/gwt-module.dtd">
|
||||
<module rename-to='google_web_toolkit'>
|
||||
<!-- Inherit the core Web Toolkit stuff. -->
|
||||
<inherits name='com.google.gwt.user.User'/>
|
||||
|
||||
<!-- Inherit the default GWT style sheet. You can change -->
|
||||
<!-- the theme of your GWT application by uncommenting -->
|
||||
<!-- any one of the following lines. -->
|
||||
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
|
||||
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
|
||||
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
|
||||
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
|
||||
|
||||
<!-- Other module inherits -->
|
||||
|
||||
<!-- Specify the app entry point class. -->
|
||||
<entry-point class='com.baeldung.client.Google_web_toolkit'/>
|
||||
|
||||
<!-- Specify the paths for translatable code -->
|
||||
<source path='client'/>
|
||||
<source path='shared'/>
|
||||
|
||||
<!-- allow Super Dev Mode -->
|
||||
<add-linker name="xsiframe"/>
|
||||
</module>
|
|
@ -0,0 +1,108 @@
|
|||
package com.baeldung.client;
|
||||
|
||||
import com.baeldung.shared.MessageService;
|
||||
import com.baeldung.shared.MessageServiceAsync;
|
||||
import com.google.gwt.core.client.EntryPoint;
|
||||
import com.google.gwt.core.client.GWT;
|
||||
import com.google.gwt.event.dom.client.ClickEvent;
|
||||
import com.google.gwt.event.dom.client.ClickHandler;
|
||||
import com.google.gwt.event.dom.client.KeyCodes;
|
||||
import com.google.gwt.event.dom.client.KeyUpEvent;
|
||||
import com.google.gwt.event.dom.client.KeyUpHandler;
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
import com.google.gwt.user.client.ui.Button;
|
||||
import com.google.gwt.user.client.ui.DialogBox;
|
||||
import com.google.gwt.user.client.ui.HTML;
|
||||
import com.google.gwt.user.client.ui.Label;
|
||||
import com.google.gwt.user.client.ui.RootPanel;
|
||||
import com.google.gwt.user.client.ui.TextBox;
|
||||
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||
|
||||
/**
|
||||
* Entry point classes define <code>onModuleLoad()</code>.
|
||||
*/
|
||||
public class Google_web_toolkit implements EntryPoint {
|
||||
private final MessageServiceAsync messageServiceAsync = GWT.create(MessageService.class);
|
||||
|
||||
public void onModuleLoad() {
|
||||
Button sendButton = new Button("Submit");
|
||||
TextBox nameField = new TextBox();
|
||||
nameField.setText("Hi there");
|
||||
|
||||
Label warningLabel = new Label();
|
||||
|
||||
sendButton.addStyleName("sendButton");
|
||||
|
||||
RootPanel.get("nameFieldContainer").add(nameField);
|
||||
RootPanel.get("sendButtonContainer").add(sendButton);
|
||||
RootPanel.get("errorLabelContainer").add(warningLabel);
|
||||
|
||||
Button closeButton = new Button("Thanks");
|
||||
closeButton.getElement().setId("closeButton");
|
||||
|
||||
Label textToServerLabel = new Label();
|
||||
HTML serverResponseLabel = new HTML();
|
||||
VerticalPanel vPanel = new VerticalPanel();
|
||||
vPanel.addStyleName("vPanel");
|
||||
vPanel.add(new HTML("Sending message to the server:"));
|
||||
vPanel.add(textToServerLabel);
|
||||
vPanel.add(new HTML("<br><b>Server replies:</b>"));
|
||||
vPanel.add(serverResponseLabel);
|
||||
vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
|
||||
vPanel.add(closeButton);
|
||||
vPanel.setVisible(false);
|
||||
RootPanel.get("serverResponseContainer").add(vPanel);
|
||||
|
||||
closeButton.addClickHandler(event -> {
|
||||
sendButton.setEnabled(true);
|
||||
sendButton.setFocus(true);
|
||||
vPanel.setVisible(false);
|
||||
});
|
||||
|
||||
class MyHandler implements ClickHandler, KeyUpHandler {
|
||||
|
||||
public void onClick(ClickEvent event) {
|
||||
sendMessageToServer();
|
||||
}
|
||||
|
||||
public void onKeyUp(KeyUpEvent event) {
|
||||
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
|
||||
sendMessageToServer();
|
||||
}
|
||||
}
|
||||
|
||||
private void sendMessageToServer() {
|
||||
|
||||
warningLabel.setText("");
|
||||
String textToServer = nameField.getText();
|
||||
if (textToServer == null || textToServer.isEmpty()) {
|
||||
warningLabel.setText("Please enter the message");
|
||||
return;
|
||||
}
|
||||
|
||||
sendButton.setEnabled(false);
|
||||
textToServerLabel.setText(textToServer);
|
||||
serverResponseLabel.setText("");
|
||||
messageServiceAsync.sendMessage(textToServer, new AsyncCallback<String>() {
|
||||
public void onFailure(Throwable caught) {
|
||||
serverResponseLabel.addStyleName("serverResponseLabelError");
|
||||
serverResponseLabel.setHTML("server error occurred");
|
||||
closeButton.setFocus(true);
|
||||
}
|
||||
|
||||
public void onSuccess(String result) {
|
||||
serverResponseLabel.removeStyleName("serverResponseLabelError");
|
||||
serverResponseLabel.setHTML(result);
|
||||
closeButton.setFocus(true);
|
||||
vPanel.setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Add a handler to send the name to the server
|
||||
MyHandler handler = new MyHandler();
|
||||
sendButton.addClickHandler(handler);
|
||||
nameField.addKeyUpHandler(handler);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package com.baeldung.server;
|
||||
|
||||
import com.baeldung.shared.MessageService;
|
||||
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* The server-side implementation of the RPC service.
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class MessageServiceImpl extends RemoteServiceServlet implements MessageService {
|
||||
|
||||
public String sendMessage(String message) throws IllegalArgumentException {
|
||||
if (message == null) {
|
||||
throw new IllegalArgumentException("message is null");
|
||||
}
|
||||
|
||||
return "Hello, " + message + "!<br><br> Time received: " + LocalDateTime.now();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.baeldung.shared;
|
||||
|
||||
import com.google.gwt.user.client.rpc.RemoteService;
|
||||
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
|
||||
|
||||
/**
|
||||
* The client-side stub for the RPC service.
|
||||
*/
|
||||
@RemoteServiceRelativePath("greet")
|
||||
public interface MessageService extends RemoteService {
|
||||
String sendMessage(String message) throws IllegalArgumentException;
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package com.baeldung.shared;
|
||||
|
||||
import com.google.gwt.user.client.rpc.AsyncCallback;
|
||||
|
||||
/**
|
||||
* The async counterpart of <code>MessageService</code>.
|
||||
*/
|
||||
public interface MessageServiceAsync {
|
||||
void sendMessage(String input, AsyncCallback<String> callback) throws IllegalArgumentException;
|
||||
}
|
|
@ -0,0 +1,31 @@
|
|||
/** Add css rules here for your application. */
|
||||
h1 {
|
||||
font-size: 2em;
|
||||
font-weight: bold;
|
||||
color: #777777;
|
||||
margin: 40px 0px 70px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.sendButton {
|
||||
display: block;
|
||||
font-size: 16pt;
|
||||
}
|
||||
|
||||
/** Most GWT widgets already have a style name defined */
|
||||
.gwt-DialogBox {
|
||||
width: 400px;
|
||||
}
|
||||
|
||||
.vPanel {
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
.serverResponseLabelError {
|
||||
color: red;
|
||||
}
|
||||
|
||||
/** Set ids using widget.getElement().setId("idOfElement") */
|
||||
#closeButton {
|
||||
margin: 15px 6px 6px;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
<!doctype html>
|
||||
<!-- The DOCTYPE declaration above will set the -->
|
||||
<!-- browser's rendering engine into -->
|
||||
<!-- "Standards Mode". Replacing this declaration -->
|
||||
<!-- with a "Quirks Mode" doctype is not supported. -->
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||
|
||||
<link type="text/css" rel="stylesheet" href="Google_web_toolkit.css">
|
||||
|
||||
<title>Sample GWT Application</title>
|
||||
|
||||
<script type="text/javascript" language="javascript" src="google_web_toolkit/google_web_toolkit.nocache.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Sample GWT Application</h1>
|
||||
<table align="center">
|
||||
<tr>
|
||||
<td colspan="2" style="font-weight:bold;">Please enter your message:</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td id="nameFieldContainer"></td>
|
||||
<td id="sendButtonContainer"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" style="color:red;" id="errorLabelContainer"></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td colspan="2" style="color:red;" id="serverResponseContainer"></td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,24 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
|
||||
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
|
||||
version="2.5"
|
||||
xmlns="http://java.sun.com/xml/ns/javaee">
|
||||
|
||||
<!-- Servlets -->
|
||||
<servlet>
|
||||
<servlet-name>greetServlet</servlet-name>
|
||||
<servlet-class>com.baeldung.server.MessageServiceImpl</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>greetServlet</servlet-name>
|
||||
<url-pattern>/google_web_toolkit/greet</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<!-- Default page to serve -->
|
||||
<welcome-file-list>
|
||||
<welcome-file>Google_web_toolkit.html</welcome-file>
|
||||
</welcome-file-list>
|
||||
|
||||
</web-app>
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Loading…
Reference in New Issue