Opening a new window in Echo3

In this example of Echo3 (server-side application) we will create a new Window. To create this example we have created two class files WindowServlet.java and WindowApp.java.

Opening a new window in Echo3

Opening a new window in Echo3

     

In this example of Echo3 (server-side application) we will create a new Window. To create this example we have created two class files WindowServlet.java and WindowApp.java. WindowApp.java is responsible for creating the application user interface through which the user will interact. WindowApp class extends the abstract class ApplicationInstance 

The init() method is used to initialize the state of the user interface for a user. It must return an Echo Window object representing the state of the initial window of an application. Here we have created a new Window by constructing the object of WindowPane. Further we have created the class WindowServlet which extends the WebContainerServlet for handling HTTP request to the servlet. WindowServlet will call the WindowApp class. Here is the full source code of WindowServlet and WindowApp as follows:

 

 

 

WindowServlet.java

package window;

import nextapp.echo.app.ApplicationInstance;
import nextapp.echo.webcontainer.WebContainerServlet;

public class WindowServlet extends WebContainerServlet {

  public ApplicationInstance newApplicationInstance() {
  return new WindowApp();
  }
}

WindowApp.java

package window;

import nextapp.echo.app.ApplicationInstance;
import nextapp.echo.app.ContentPane;
import nextapp.echo.app.Label;
import nextapp.echo.app.Window;
import nextapp.echo.app.*;


import nextapp.echo.app.event.ActionListener;
import nextapp.echo.app.event.ActionEvent;

public class WindowApp extends ApplicationInstance {

 private WindowPane windowPane;

  public Window init() {
  Window window = new Window();
  window.setTitle("Window1");
  ContentPane contentPane = new ContentPane();
  Label label=new Label("Window Example");
  windowPane = new WindowPane();
  windowPane.setTitle("Window");
  windowPane.add(new Label("New Window"));
  contentPane.add(windowPane);
  window.setContent(contentPane);
  return window;
  }  

Do the servlet entry and servlet mapping into the deployment descriptor file web.xml

<!DOCTYPE web-app 
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

<display-name>Interactive Test Application</display-name>
<description>
   An interactive application to test features of the Echo Platform.
</description>

<servlet>
<servlet-name>WindowServlet</servlet-name>
<servlet-class>window.WindowServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WindowServlet</servlet-name>
<url-pattern>/winapp</url-pattern>
</servlet-mapping>

</web-app>

Output :

Type the following URL into the address bar http://localhost:8080/echo3/winapp 

Download Source Project