SlideShare una empresa de Scribd logo
1 de 78
Web Development
with GWT and Xtend
      Sven Efftinge, Oliver Zeigermann
http://todomvc.appspot.com
Motivation for GWT:
Modern Single Page Applications
Motivation for GWT:
Modern Single Page Applications
Single Page Application
Motivation for GWT:
Modern Single Page Applications
Single Page Application
• Works like a client/server application in the browser
Motivation for GWT:
Modern Single Page Applications
Single Page Application
• Works like a client/server application in the browser
Motivation for GWT:
Modern Single Page Applications
Single Page Application
• Works like a client/server application in the browser

Developing for the Browser is a tough task!
Motivation for GWT:
Modern Single Page Applications
Single Page Application
• Works like a client/server application in the browser

Developing for the Browser is a tough task!
• Browsers have different levels of maturity and compliance
  to standards
Motivation for GWT:
Modern Single Page Applications
Single Page Application
• Works like a client/server application in the browser

Developing for the Browser is a tough task!
• Browsers have different levels of maturity and compliance
  to standards
• Programming to the DOM can be tedious
Motivation for GWT:
Modern Single Page Applications
Single Page Application
• Works like a client/server application in the browser

Developing for the Browser is a tough task!
• Browsers have different levels of maturity and compliance
  to standards
• Programming to the DOM can be tedious
• JavaScript
Motivation for GWT:
Modern Single Page Applications
Single Page Application
• Works like a client/server application in the browser

Developing for the Browser is a tough task!
• Browsers have different levels of maturity and compliance
  to standards
• Programming to the DOM can be tedious
• JavaScript
Motivation for GWT:
Modern Single Page Applications
Single Page Application
• Works like a client/server application in the browser

Developing for the Browser is a tough task!
• Browsers have different levels of maturity and compliance
  to standards
• Programming to the DOM can be tedious
• JavaScript

Many projects also require a server side backend
Motivation for GWT:
Modern Single Page Applications
Single Page Application
• Works like a client/server application in the browser

Developing for the Browser is a tough task!
• Browsers have different levels of maturity and compliance
  to standards
• Programming to the DOM can be tedious
• JavaScript

Many projects also require a server side backend
•Common toolset, code, and language desirable for frontend
 and backend
GWT for the win!
GWT for the win!
Abstraction from differences between
GWT for the win!
Abstraction from differences between
GWT for the win!
Abstraction from differences between

• Client & Server
  o   Write everything in Java
  o   Shared code between Client and Server
GWT for the win!
Abstraction from differences between

• Client & Server
  o   Write everything in Java
  o   Shared code between Client and Server

• Different Browser implementations
  o   Special JavaScript per browser
  o   Common Widgets to unify differences
Client Server Communication
     Unification of client and server code
Call from client side: Loading Todos
  TodoServiceAsync service = GWT.create(TodoService.class);
service.load(name, new AsyncCallback<List<Todo>>() {
	
	   @Override
	   public void onSuccess(List<Todo> result) {
	   	   // store and display todos
	   }
	
	   @Override
	   public void onFailure(Throwable caught) {
	   	   GWT.log("Loading todos failed", caught);
	   }
});
Implementation on server side
public class TodoServiceImpl extends RemoteServiceServlet
    implements	TodoService {

	   @Override
	   public List<Todo> load(String name) {
	   	   return getMemcacheService().get(name);
	   }

	   @Override
	   public void save(String name, List<Todo> todos) {
	   	   getMemcacheService().put(name, todos);
	   }
}
User Interfaces with GWT
Widgets working on all browsers without
         touching the DOM
Building UIs Programmatically
Programmatically Composing Widgets:
Displaying a Todo
  FlowPanel view = new FlowPanel();
  view.setStyleName("view");
  ...
  Label label = new Label();
  view.add(label);
  Button button = new Button();
  button.setStyleName("destroy");
  view.add(button);
  button.addClickHandler(new ClickHandler() {
  	   @Override
  	   public void onClick(ClickEvent event) {
          // remove element from todo list	 	
  	   }
  });
Any idea how this will look like
when displayed?
Declarative UI Design
       using
UiBinder XML
  <g:HTMLPanel>
    <li ui:field="li">
	       <g:FlowPanel styleName="view">
	   	       <g:CheckBox ui:field="checkBox"
                styleName="toggle"/>
	   	       <g:Label ui:field="label"/>
	   	       <g:Button ui:field="removeButton"
                styleName='destroy'/>
	       </g:FlowPanel>
	   </li>
</g:HTMLPanel>
UIBinder Code for dynamic stuff
    public class TaskComposite extends Composite {

	    // ...

	    @UiField
	    Label label;

	    // ...

	    @UiHandler("label")
	    public void editTask(DoubleClickEvent event) {
	    	   editMode();
	    }

	    // ...
}
The Tragedy of Building UIs
The Tragedy of Building UIs
 Declarative using XML
The Tragedy of Building UIs
 Declarative using XML
    structure of code reflects structure of UI (declarative)
The Tragedy of Building UIs
 Declarative using XML
    structure of code reflects structure of UI (declarative)
    XML
The Tragedy of Building UIs
 Declarative using XML
    structure of code reflects structure of UI (declarative)
    XML
    needs Java code for dynamic parts
The Tragedy of Building UIs
 Declarative using XML
    structure of code reflects structure of UI (declarative)
    XML
    needs Java code for dynamic parts
    code duplication (through binding)
The Tragedy of Building UIs
 Declarative using XML
    structure of code reflects structure of UI (declarative)
    XML
    needs Java code for dynamic parts
    code duplication (through binding)

 Imperative using Java
The Tragedy of Building UIs
 Declarative using XML
    structure of code reflects structure of UI (declarative)
    XML
    needs Java code for dynamic parts
    code duplication (through binding)

 Imperative using Java
    all in one place
The Tragedy of Building UIs
 Declarative using XML
    structure of code reflects structure of UI (declarative)
    XML
    needs Java code for dynamic parts
    code duplication (through binding)

 Imperative using Java
    all in one place
    hard to read (imperative)
Statically Typed like Java
Statically Typed like Java
        Compiles To Java
Statically Typed like Java
        Compiles To Java
      Much more concise
Statically Typed like Java
        Compiles To Java
      Much more concise
    Powerful possibilities
Clearing Completed Tasks

clearCompletedButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                List<Todo> result = new ArrayList<Todo>();
                for (Todo t : getTodos()) {
                    if (!t.isDone()) {
                        result.add(t);
                    }
                }
                setTodos(result);
            }
        });
Clearing Completed Tasks

clearCompletedButton.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                List<Todo> result = new ArrayList<Todo>();
                for (Todo t : getTodos()) {
                    if (!t.isDone()) {
                        result.add(t);
                    }
                }
                setTodos(result);
            }
        });
Clearing Completed Tasks


List<Todo> result = new ArrayList<Todo>();
for (Todo t : getTodos()) {
    if (!t.isDone()) {
        result.add(t);
    }
}
setTodos(result);
Clearing Completed Tasks


val List<Todo> result = new ArrayList<Todo>();
for (Todo t : getTodos()) {
    if (!t.isDone()) {
        result.add(t);
    }
}
setTodos(result);
Clearing Completed Tasks


val List<Todo> result = new ArrayList<Todo>();
for (Todo t : getTodos()) {
    if (!t.isDone()) {
        result.add(t);
    }
}
setTodos(result);
Clearing Completed Tasks


val List<Todo> result = new ArrayList<Todo>();
for (Todo t : getTodos()) {
    if (!t.isDone()) {
        result.add(t);
    }
}
setTodos(result);
Type Inference
Semicolons?
Property Access
Operator Overloading
Operator Overloading



                                           sty le!
                                        va
                                 e Ja
                         e rativ
             still imp
      that’s
But
Functional Xtend Style
Functional Xtend Style




todos = todos.filter[!done].toList
Functional Xtend Style



clearCompletedButton.addClickHandler [
    todos = todos.filter[!done].toList
]
clearCompletedButton.addClickHandler [
    todos = todos.filter[!done].toList
]


        clearCompletedButton.addClickHandler(new ClickHandler() {
                    @Override
                    public void onClick(ClickEvent event) {
                        List<Todo> result = new ArrayList<Todo>();
                        for (Todo t : getTodos()) {
                            if (!t.isDone()) {
                                result.add(t);
                            }
                        }
                        setTodos(result);
                    }
                });
Client Server Communication
                     Revisited
GWT-RPC in Java
1) Server-Side Service Implementation
  public class TodoServiceImpl extends RemoteServiceServlet implements TodoService {
    public List<Todo> load(final String name) {
      return (List<Todo>) getMemcacheService().get(name);
    }

      public void save(final List<Todo> todos, final String name) {
        getMemcacheService().put(name, todos);
      }
  }
GWT-RPC in Java
1) Server-Side Service Implementation
  public class TodoServiceImpl extends RemoteServiceServlet implements TodoService {
    public List<Todo> load(final String name) {
      return (List<Todo>) getMemcacheService().get(name);
    }

      public void save(final List<Todo> todos, final String name) {
        getMemcacheService().put(name, todos);
      }
  }


2) Server-Side Service Interface
  @RemoteServiceRelativePath("todoService")
  public interface TodoService extends RemoteService {
    public List<Todo> load(final String name);

      public void save(final List<Todo> todos, final String name);
  }
GWT-RPC in Java
1) Server-Side Service Implementation
  public class TodoServiceImpl extends RemoteServiceServlet implements TodoService {
    public List<Todo> load(final String name) {
      return (List<Todo>) getMemcacheService().get(name);
    }

      public void save(final List<Todo> todos, final String name) {
        getMemcacheService().put(name, todos);
      }
  }


2) Server-Side Service Interface
  @RemoteServiceRelativePath("todoService")
  public interface TodoService extends RemoteService {
    public List<Todo> load(final String name);

      public void save(final List<Todo> todos, final String name);
  }


3) Client-Side Async-Interface
  public interface TodoServiceAsync {
    public void load(final String name, final AsyncCallback<List<Todo>> result);

      public void save(final List<Todo> todos, final String name,
                       final AsyncCallback<Void> result);
  }
GWT-RPC in Xtend
1) Server-Side Service Implementation

   @GwtService
   class TodoServiceImpl {
   	
   	 override List<Todo> load(String name) {
   	 	 return memcacheService.get(name) as List<Todo>
   	 }

   	   override void save(List<Todo> todos, String name) {
   	   	 memcacheService.put(name, todos)
   	   }
   }
GWT-RPC in Xtend
1) Server-Side Service Implementation

   @GwtService
   class TodoServiceImpl {
   	
   	 override List<Todo> load(String name) {
   	 	 return memcacheService.get(name) as List<Todo>
   	 }

   	   override void save(List<Todo> todos, String name) {
   	   	 memcacheService.put(name, todos)
   	   }
   }



       @GwtService is a so called “Active Annotation”.
           It adds the needed boilerplate during compilation.
Building UIs Programmatically
                       with Xtend
Imperative UIs in Java

FlowPanel view = new FlowPanel();
view.setStyleName("view");
...
Label label = new Label();
label.setText(todo.getText());
view.add(label);
Button button = new Button();
button.setStyleName("destroy");
view.add(button);
button.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
       deleteTodo(todo);	
    }
});
Declarative UIs in Xtend

flowPanel [
    styleName = 'view'
    ...
    label [
        text = todo.text
    ]
    button [
        styleName = 'destroy'
        onClick [
             deleteTodo(todo)
        ]
    ]
]
Declarative UIs in Xtend

flowPanel [
    styleName = 'view'
    ...
    label [
        text = todo.text
    ]
    button [
        styleName = 'destroy'
        onClick [
             deleteTodo(todo)
        ]
    ]
]                   That’s a so   called Builder API
Declarative UI Design
       using
The XML

	   <section id="todoapp">
	   	   <header id="header">
	   	   	   <h1>todos</h1>
	   	   	   <g:TextBox ui:field="todoText"/>
	   	   </header>

	   	   <section ui:field="mainSection">
	   	   	   <input ui:field="toggleAll" type="checkbox"></input>
	   	   	   <label for="toggle-all">Mark all as complete</label>
	   	   	   <ul id="todo-list">
	   	   	       <g:FlowPanel ui:field="todoPanel"></g:FlowPanel>
	   	   	   </ul>
	   	   </section>

	   	   <footer ui:field="todoStatsContainer">
	   	   	   <span id="todo-count">
	   	   	   	   <strong class="number" ui:field="remainingTodosCount"></strong>
	   	   	   	   <span class="word" ui:field="remainingTodosLabel"></span>
	   	   	   	   left.
	   	   	   </span>
	   	   	   <g:Button ui:field="clearCompleted">
	   	   	   	   Clear completed (<span class="number-done" ui:field="clearTodosCount"></span>)
	   	   	   </g:Button>
	   	   </footer>
	   </section>
public class ToDoView extends Composite {
  interface ToDoViewUiBinder extends UiBinder<Widget,ToDoView> {
  }

    private static ToDoViewUiBinder uiBinder =
                                GWT.create(ToDoViewUiBinder.class);
    @UiField
    protected SpanElement clearTodosCount;

    @UiField
    protected SpanElement remainingTodosLabel;

    @UiField
    protected FlowPanel todoPanel;
                                                        Here’s the boilerplate!
    @UiField
    protected InputElement toggleAll;

    @UiField
    protected Element remainingTodosCount;

    @UiField
    protected Button clearCompleted;

    @UiField
    protected TextBox todoText;

    @UiField
    protected Element mainSection;

    @UiField
    protected Element todoStatsContainer;

    // ... actual implementation
}
Active Annotations Once More


@WithUiBinding
class ToDoView extends Composite {
  // ... actual implementation
}
Active Annotations Once More


@WithUiBinding
class ToDoView extends Composite {
  // ... actual implementation
}



       @WithUiBinding looks up the XML and
           adds the boilerplate for you.
Wrap-up
Wrap-up



          GWT is cool!
Wrap-up



          GWT is cool!
    Even more so with Xtend :-)
Questions?
Questions?

Más contenido relacionado

La actualidad más candente

VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
Taha Shakeel
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 
Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife Spring
Mario Fusco
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
elliando dias
 

La actualidad más candente (20)

VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
 
4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
 
Q
QQ
Q
 
Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察Jggug 2010 330 Grails 1.3 観察
Jggug 2010 330 Grails 1.3 観察
 
Testing Backbone applications with Jasmine
Testing Backbone applications with JasmineTesting Backbone applications with Jasmine
Testing Backbone applications with Jasmine
 
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
Rxjs marble-testing
Rxjs marble-testingRxjs marble-testing
Rxjs marble-testing
 
Talk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe ConversetTalk KVO with rac by Philippe Converset
Talk KVO with rac by Philippe Converset
 
Javascript
JavascriptJavascript
Javascript
 
Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife Spring
 
Clojure - A new Lisp
Clojure - A new LispClojure - A new Lisp
Clojure - A new Lisp
 
Nativescript angular
Nativescript angularNativescript angular
Nativescript angular
 
Selenium cheat sheet
Selenium cheat sheetSelenium cheat sheet
Selenium cheat sheet
 
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and JasmineRails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
Rails-like JavaScript Using CoffeeScript, Backbone.js and Jasmine
 
DRYing to Monad in Java8
DRYing to Monad in Java8DRYing to Monad in Java8
DRYing to Monad in Java8
 
Anonymous functions in JavaScript
Anonymous functions in JavaScriptAnonymous functions in JavaScript
Anonymous functions in JavaScript
 
Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...Reactive Programming for a demanding world: building event-driven and respons...
Reactive Programming for a demanding world: building event-driven and respons...
 
Ad java prac sol set
Ad java prac sol setAd java prac sol set
Ad java prac sol set
 

Destacado

Challenges In Dsl Design
Challenges In Dsl DesignChallenges In Dsl Design
Challenges In Dsl Design
Sven Efftinge
 
Dependency Injection for Eclipse developers
Dependency Injection for Eclipse developersDependency Injection for Eclipse developers
Dependency Injection for Eclipse developers
Sven Efftinge
 

Destacado (8)

Eclipse Banking Day
Eclipse Banking DayEclipse Banking Day
Eclipse Banking Day
 
Xtend - A Language Made for Java Developers
Xtend - A Language Made for Java DevelopersXtend - A Language Made for Java Developers
Xtend - A Language Made for Java Developers
 
Challenges In Dsl Design
Challenges In Dsl DesignChallenges In Dsl Design
Challenges In Dsl Design
 
Eclipse Xtend
Eclipse XtendEclipse Xtend
Eclipse Xtend
 
Introduction to Xbase
Introduction to XbaseIntroduction to Xbase
Introduction to Xbase
 
Getting rid of backtracking
Getting rid of backtrackingGetting rid of backtracking
Getting rid of backtracking
 
Dependency Injection for Eclipse developers
Dependency Injection for Eclipse developersDependency Injection for Eclipse developers
Dependency Injection for Eclipse developers
 
Language Engineering With Xtext
Language Engineering With XtextLanguage Engineering With Xtext
Language Engineering With Xtext
 

Similar a Gwt and Xtend

Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache FlinkMaximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Flink Forward
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
Jussi Pohjolainen
 

Similar a Gwt and Xtend (20)

Net conf BG xamarin lecture
Net conf BG xamarin lectureNet conf BG xamarin lecture
Net conf BG xamarin lecture
 
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo A GWT Application with MVP Pattern Deploying to CloudFoundry using  Spring Roo
A GWT Application with MVP Pattern Deploying to CloudFoundry using Spring Roo
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
Qt Workshop
Qt WorkshopQt Workshop
Qt Workshop
 
To-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step GuideTo-Do App With Flutter: Step By Step Guide
To-Do App With Flutter: Step By Step Guide
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
2008 - TechDays PT: WCF, JSON and AJAX for performance and manageability
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
GWT MVP Case Study
GWT MVP Case StudyGWT MVP Case Study
GWT MVP Case Study
 
Google Web Toolkits
Google Web ToolkitsGoogle Web Toolkits
Google Web Toolkits
 
"Migrate large gwt applications - Lessons Learned" By Harald Pehl
"Migrate large gwt applications - Lessons Learned" By Harald Pehl"Migrate large gwt applications - Lessons Learned" By Harald Pehl
"Migrate large gwt applications - Lessons Learned" By Harald Pehl
 
Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache FlinkMaximilian Michels – Google Cloud Dataflow on Top of Apache Flink
Maximilian Michels – Google Cloud Dataflow on Top of Apache Flink
 
Flink Batch Processing and Iterations
Flink Batch Processing and IterationsFlink Batch Processing and Iterations
Flink Batch Processing and Iterations
 
Design patterns for fun and profit
Design patterns for fun and profitDesign patterns for fun and profit
Design patterns for fun and profit
 
Quick Intro to Android Development
Quick Intro to Android DevelopmentQuick Intro to Android Development
Quick Intro to Android Development
 
Software Language Design & Engineering
Software Language Design & EngineeringSoftware Language Design & Engineering
Software Language Design & Engineering
 
mobl
moblmobl
mobl
 
compose_speaker_session.pdf
compose_speaker_session.pdfcompose_speaker_session.pdf
compose_speaker_session.pdf
 
Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)Introduction To Google Android (Ft Rohan Bomle)
Introduction To Google Android (Ft Rohan Bomle)
 

Más de Sven Efftinge

Xtext at MDD Day 2010
Xtext at MDD Day 2010Xtext at MDD Day 2010
Xtext at MDD Day 2010
Sven Efftinge
 
Xtext @ Profict Summer Camp
Xtext @ Profict Summer CampXtext @ Profict Summer Camp
Xtext @ Profict Summer Camp
Sven Efftinge
 
Vermisste Sprachfeatures in Java (german)
Vermisste Sprachfeatures in Java (german)Vermisste Sprachfeatures in Java (german)
Vermisste Sprachfeatures in Java (german)
Sven Efftinge
 

Más de Sven Efftinge (17)

Parsing Expression With Xtext
Parsing Expression With XtextParsing Expression With Xtext
Parsing Expression With Xtext
 
Future of Xtext
Future of XtextFuture of Xtext
Future of Xtext
 
Functional programming with Xtend
Functional programming with XtendFunctional programming with Xtend
Functional programming with Xtend
 
Domain Specific Languages (EclipseCon 2012)
Domain Specific Languages (EclipseCon 2012)Domain Specific Languages (EclipseCon 2012)
Domain Specific Languages (EclipseCon 2012)
 
Xtend @ EclipseCon 2012
Xtend @ EclipseCon 2012Xtend @ EclipseCon 2012
Xtend @ EclipseCon 2012
 
This Is Not Your Father's Java
This Is Not Your Father's JavaThis Is Not Your Father's Java
This Is Not Your Father's Java
 
Getting the most out of Java [Nordic Coding-2010]
Getting the most out of Java [Nordic Coding-2010]Getting the most out of Java [Nordic Coding-2010]
Getting the most out of Java [Nordic Coding-2010]
 
Xtext at MDD Day 2010
Xtext at MDD Day 2010Xtext at MDD Day 2010
Xtext at MDD Day 2010
 
Xtext Webinar
Xtext WebinarXtext Webinar
Xtext Webinar
 
Code Generation in Agile Projects
Code Generation in Agile ProjectsCode Generation in Agile Projects
Code Generation in Agile Projects
 
Xtext Eclipse Con
Xtext Eclipse ConXtext Eclipse Con
Xtext Eclipse Con
 
Generic Editor
Generic EditorGeneric Editor
Generic Editor
 
Bessere Softwareentwicklung (Itemis Wintercon)
Bessere Softwareentwicklung (Itemis Wintercon)Bessere Softwareentwicklung (Itemis Wintercon)
Bessere Softwareentwicklung (Itemis Wintercon)
 
Domain-Specific Languages in der Praxis
Domain-Specific Languages in der PraxisDomain-Specific Languages in der Praxis
Domain-Specific Languages in der Praxis
 
Xtext @ Profict Summer Camp
Xtext @ Profict Summer CampXtext @ Profict Summer Camp
Xtext @ Profict Summer Camp
 
Vermisste Sprachfeatures in Java (german)
Vermisste Sprachfeatures in Java (german)Vermisste Sprachfeatures in Java (german)
Vermisste Sprachfeatures in Java (german)
 
Scala
ScalaScala
Scala
 

Último

Último (20)

Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
A Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source MilvusA Beginners Guide to Building a RAG App Using Open Source Milvus
A Beginners Guide to Building a RAG App Using Open Source Milvus
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 

Gwt and Xtend

  • 1. Web Development with GWT and Xtend Sven Efftinge, Oliver Zeigermann
  • 3. Motivation for GWT: Modern Single Page Applications
  • 4. Motivation for GWT: Modern Single Page Applications Single Page Application
  • 5. Motivation for GWT: Modern Single Page Applications Single Page Application • Works like a client/server application in the browser
  • 6. Motivation for GWT: Modern Single Page Applications Single Page Application • Works like a client/server application in the browser
  • 7. Motivation for GWT: Modern Single Page Applications Single Page Application • Works like a client/server application in the browser Developing for the Browser is a tough task!
  • 8. Motivation for GWT: Modern Single Page Applications Single Page Application • Works like a client/server application in the browser Developing for the Browser is a tough task! • Browsers have different levels of maturity and compliance to standards
  • 9. Motivation for GWT: Modern Single Page Applications Single Page Application • Works like a client/server application in the browser Developing for the Browser is a tough task! • Browsers have different levels of maturity and compliance to standards • Programming to the DOM can be tedious
  • 10. Motivation for GWT: Modern Single Page Applications Single Page Application • Works like a client/server application in the browser Developing for the Browser is a tough task! • Browsers have different levels of maturity and compliance to standards • Programming to the DOM can be tedious • JavaScript
  • 11. Motivation for GWT: Modern Single Page Applications Single Page Application • Works like a client/server application in the browser Developing for the Browser is a tough task! • Browsers have different levels of maturity and compliance to standards • Programming to the DOM can be tedious • JavaScript
  • 12. Motivation for GWT: Modern Single Page Applications Single Page Application • Works like a client/server application in the browser Developing for the Browser is a tough task! • Browsers have different levels of maturity and compliance to standards • Programming to the DOM can be tedious • JavaScript Many projects also require a server side backend
  • 13. Motivation for GWT: Modern Single Page Applications Single Page Application • Works like a client/server application in the browser Developing for the Browser is a tough task! • Browsers have different levels of maturity and compliance to standards • Programming to the DOM can be tedious • JavaScript Many projects also require a server side backend •Common toolset, code, and language desirable for frontend and backend
  • 14. GWT for the win!
  • 15. GWT for the win! Abstraction from differences between
  • 16. GWT for the win! Abstraction from differences between
  • 17. GWT for the win! Abstraction from differences between • Client & Server o Write everything in Java o Shared code between Client and Server
  • 18. GWT for the win! Abstraction from differences between • Client & Server o Write everything in Java o Shared code between Client and Server • Different Browser implementations o Special JavaScript per browser o Common Widgets to unify differences
  • 19. Client Server Communication Unification of client and server code
  • 20. Call from client side: Loading Todos TodoServiceAsync service = GWT.create(TodoService.class); service.load(name, new AsyncCallback<List<Todo>>() { @Override public void onSuccess(List<Todo> result) { // store and display todos } @Override public void onFailure(Throwable caught) { GWT.log("Loading todos failed", caught); } });
  • 21. Implementation on server side public class TodoServiceImpl extends RemoteServiceServlet implements TodoService { @Override public List<Todo> load(String name) { return getMemcacheService().get(name); } @Override public void save(String name, List<Todo> todos) { getMemcacheService().put(name, todos); } }
  • 22. User Interfaces with GWT Widgets working on all browsers without touching the DOM
  • 24. Programmatically Composing Widgets: Displaying a Todo FlowPanel view = new FlowPanel(); view.setStyleName("view"); ... Label label = new Label(); view.add(label); Button button = new Button(); button.setStyleName("destroy"); view.add(button); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { // remove element from todo list } });
  • 25. Any idea how this will look like when displayed?
  • 27. UiBinder XML <g:HTMLPanel> <li ui:field="li"> <g:FlowPanel styleName="view"> <g:CheckBox ui:field="checkBox" styleName="toggle"/> <g:Label ui:field="label"/> <g:Button ui:field="removeButton" styleName='destroy'/> </g:FlowPanel> </li> </g:HTMLPanel>
  • 28. UIBinder Code for dynamic stuff public class TaskComposite extends Composite { // ... @UiField Label label; // ... @UiHandler("label") public void editTask(DoubleClickEvent event) { editMode(); } // ... }
  • 29. The Tragedy of Building UIs
  • 30. The Tragedy of Building UIs Declarative using XML
  • 31. The Tragedy of Building UIs Declarative using XML structure of code reflects structure of UI (declarative)
  • 32. The Tragedy of Building UIs Declarative using XML structure of code reflects structure of UI (declarative) XML
  • 33. The Tragedy of Building UIs Declarative using XML structure of code reflects structure of UI (declarative) XML needs Java code for dynamic parts
  • 34. The Tragedy of Building UIs Declarative using XML structure of code reflects structure of UI (declarative) XML needs Java code for dynamic parts code duplication (through binding)
  • 35. The Tragedy of Building UIs Declarative using XML structure of code reflects structure of UI (declarative) XML needs Java code for dynamic parts code duplication (through binding) Imperative using Java
  • 36. The Tragedy of Building UIs Declarative using XML structure of code reflects structure of UI (declarative) XML needs Java code for dynamic parts code duplication (through binding) Imperative using Java all in one place
  • 37. The Tragedy of Building UIs Declarative using XML structure of code reflects structure of UI (declarative) XML needs Java code for dynamic parts code duplication (through binding) Imperative using Java all in one place hard to read (imperative)
  • 38.
  • 40. Statically Typed like Java Compiles To Java
  • 41. Statically Typed like Java Compiles To Java Much more concise
  • 42. Statically Typed like Java Compiles To Java Much more concise Powerful possibilities
  • 43.
  • 44. Clearing Completed Tasks clearCompletedButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { List<Todo> result = new ArrayList<Todo>(); for (Todo t : getTodos()) { if (!t.isDone()) { result.add(t); } } setTodos(result); } });
  • 45. Clearing Completed Tasks clearCompletedButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { List<Todo> result = new ArrayList<Todo>(); for (Todo t : getTodos()) { if (!t.isDone()) { result.add(t); } } setTodos(result); } });
  • 46. Clearing Completed Tasks List<Todo> result = new ArrayList<Todo>(); for (Todo t : getTodos()) { if (!t.isDone()) { result.add(t); } } setTodos(result);
  • 47. Clearing Completed Tasks val List<Todo> result = new ArrayList<Todo>(); for (Todo t : getTodos()) { if (!t.isDone()) { result.add(t); } } setTodos(result);
  • 48. Clearing Completed Tasks val List<Todo> result = new ArrayList<Todo>(); for (Todo t : getTodos()) { if (!t.isDone()) { result.add(t); } } setTodos(result);
  • 49. Clearing Completed Tasks val List<Todo> result = new ArrayList<Todo>(); for (Todo t : getTodos()) { if (!t.isDone()) { result.add(t); } } setTodos(result);
  • 54. Operator Overloading sty le! va e Ja e rativ still imp that’s But
  • 56. Functional Xtend Style todos = todos.filter[!done].toList
  • 57. Functional Xtend Style clearCompletedButton.addClickHandler [ todos = todos.filter[!done].toList ]
  • 58. clearCompletedButton.addClickHandler [ todos = todos.filter[!done].toList ] clearCompletedButton.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { List<Todo> result = new ArrayList<Todo>(); for (Todo t : getTodos()) { if (!t.isDone()) { result.add(t); } } setTodos(result); } });
  • 60. GWT-RPC in Java 1) Server-Side Service Implementation public class TodoServiceImpl extends RemoteServiceServlet implements TodoService { public List<Todo> load(final String name) { return (List<Todo>) getMemcacheService().get(name); } public void save(final List<Todo> todos, final String name) { getMemcacheService().put(name, todos); } }
  • 61. GWT-RPC in Java 1) Server-Side Service Implementation public class TodoServiceImpl extends RemoteServiceServlet implements TodoService { public List<Todo> load(final String name) { return (List<Todo>) getMemcacheService().get(name); } public void save(final List<Todo> todos, final String name) { getMemcacheService().put(name, todos); } } 2) Server-Side Service Interface @RemoteServiceRelativePath("todoService") public interface TodoService extends RemoteService { public List<Todo> load(final String name); public void save(final List<Todo> todos, final String name); }
  • 62. GWT-RPC in Java 1) Server-Side Service Implementation public class TodoServiceImpl extends RemoteServiceServlet implements TodoService { public List<Todo> load(final String name) { return (List<Todo>) getMemcacheService().get(name); } public void save(final List<Todo> todos, final String name) { getMemcacheService().put(name, todos); } } 2) Server-Side Service Interface @RemoteServiceRelativePath("todoService") public interface TodoService extends RemoteService { public List<Todo> load(final String name); public void save(final List<Todo> todos, final String name); } 3) Client-Side Async-Interface public interface TodoServiceAsync { public void load(final String name, final AsyncCallback<List<Todo>> result); public void save(final List<Todo> todos, final String name, final AsyncCallback<Void> result); }
  • 63. GWT-RPC in Xtend 1) Server-Side Service Implementation @GwtService class TodoServiceImpl { override List<Todo> load(String name) { return memcacheService.get(name) as List<Todo> } override void save(List<Todo> todos, String name) { memcacheService.put(name, todos) } }
  • 64. GWT-RPC in Xtend 1) Server-Side Service Implementation @GwtService class TodoServiceImpl { override List<Todo> load(String name) { return memcacheService.get(name) as List<Todo> } override void save(List<Todo> todos, String name) { memcacheService.put(name, todos) } } @GwtService is a so called “Active Annotation”. It adds the needed boilerplate during compilation.
  • 66. Imperative UIs in Java FlowPanel view = new FlowPanel(); view.setStyleName("view"); ... Label label = new Label(); label.setText(todo.getText()); view.add(label); Button button = new Button(); button.setStyleName("destroy"); view.add(button); button.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { deleteTodo(todo); } });
  • 67. Declarative UIs in Xtend flowPanel [ styleName = 'view' ... label [ text = todo.text ] button [ styleName = 'destroy' onClick [ deleteTodo(todo) ] ] ]
  • 68. Declarative UIs in Xtend flowPanel [ styleName = 'view' ... label [ text = todo.text ] button [ styleName = 'destroy' onClick [ deleteTodo(todo) ] ] ] That’s a so called Builder API
  • 70. The XML <section id="todoapp"> <header id="header"> <h1>todos</h1> <g:TextBox ui:field="todoText"/> </header> <section ui:field="mainSection"> <input ui:field="toggleAll" type="checkbox"></input> <label for="toggle-all">Mark all as complete</label> <ul id="todo-list"> <g:FlowPanel ui:field="todoPanel"></g:FlowPanel> </ul> </section> <footer ui:field="todoStatsContainer"> <span id="todo-count"> <strong class="number" ui:field="remainingTodosCount"></strong> <span class="word" ui:field="remainingTodosLabel"></span> left. </span> <g:Button ui:field="clearCompleted"> Clear completed (<span class="number-done" ui:field="clearTodosCount"></span>) </g:Button> </footer> </section>
  • 71. public class ToDoView extends Composite { interface ToDoViewUiBinder extends UiBinder<Widget,ToDoView> { } private static ToDoViewUiBinder uiBinder = GWT.create(ToDoViewUiBinder.class); @UiField protected SpanElement clearTodosCount; @UiField protected SpanElement remainingTodosLabel; @UiField protected FlowPanel todoPanel; Here’s the boilerplate! @UiField protected InputElement toggleAll; @UiField protected Element remainingTodosCount; @UiField protected Button clearCompleted; @UiField protected TextBox todoText; @UiField protected Element mainSection; @UiField protected Element todoStatsContainer; // ... actual implementation }
  • 72. Active Annotations Once More @WithUiBinding class ToDoView extends Composite { // ... actual implementation }
  • 73. Active Annotations Once More @WithUiBinding class ToDoView extends Composite { // ... actual implementation } @WithUiBinding looks up the XML and adds the boilerplate for you.
  • 75. Wrap-up GWT is cool!
  • 76. Wrap-up GWT is cool! Even more so with Xtend :-)

Notas del editor

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n
  60. \n
  61. \n
  62. \n
  63. \n
  64. \n
  65. \n
  66. \n
  67. \n
  68. \n
  69. \n
  70. \n
  71. \n
  72. \n