SlideShare a Scribd company logo
GWT with MVP: A Case Study David Chandler [email_address] http://blog.TurboManage.com
OR… How I learned to love ( C S S   && anonymous() { inner() {} classes() {} });
Who is this guy? Wrote first book on running a Web site (1995) Written Web apps in perl, ksh, C with lex/yacc, ColdFusion, JSF, GWT Most recently, Web architect with Intuit on Internet banking products Patent on non-recursive SQL trees Working in a startup last 6 mos
Anatomy of a GWT app What’s GWT+MVP? “ Good” practices & patterns gwt-presenter gwt-dispatch Caching, batching, queuing GWT Tools Resources
GWT+MVP Model View Presenter Way of organizing code analogous to MVC Services    Presenter    View View implements interface defined in presenter fires no events of its own Presenter listens for DOM events (ClickHandlers, etc.) listens on event bus calls services
GWT+MVP Where to put the model? Singleton accessible everywhere? (user info) Hide it behind services? Bits & pieces in each presenter? None at all?
Good practice #1 Define the Display interface Return interfaces, not Widgets Supports testing, decoupling from view Button getSaveButton(); HasClickHandlers  getSaveButton(); Caveat: sometimes you have to write your own
How to untangle How can presenters communicate with services and each other? Example: new friend added Does main presenter hold ref to all others? Use an  event bus Define your own application events extending GwtEvent Presenters add handlers to listen for events
Good practice #2 Let presenter handle all events (even DOM) Sometimes hard If put click handler in the view, then view would have to call service layer Instead, handle in presenter display.getSaveButton().addClickHandler…
How to handle Widget collections? Say, every row in a table has clickable widgets Ans #1: catch event in parent Widget only a) each table cell is a DIV. Handle event in containing Widget Note: parent must be a Widget to receive events (and all of its ancestors) b) along with this, expose handler reg mechanism through interface
How to handle Widget collections? What if every row has multiple TextBoxes? Ans #2: write Display interface with arrays interface Display { HasValue<String> getFirstName(int i); HasValue<String> getLastName(int i); int getNumRows(); void addRows(int n); }
Guice Google’s dependency injection framework Small, light, almost plain English ServerModule DispatchServletModule DispatchTestModule ROAUserServiceImpl Used by gwt-dispatch, useful for unit tests
Google GIN Dependency injection for GWT Quite useful for MVP implementations Provides access to EventBus, Dispatch, anything “global” your app may need Auto-creates Images and Constants Instead of GWT.create(RoaImages.class); Can use bind(RoaImages. class ).in(Singleton. class ); @Inject RoaImages images;
gwt-presenter Open source framework by David Peterson http://code.google.com/p/gwt-presenter/ Very clean MVP implementation Uses GIN to bind presenters as singletons “ Place” management Automatically syncs GWT History object when fire PlaceRequestEvent in code When browser URL changes, fires PRE
gwt-presenter Look at wiring (RoaModule, RoaGinjector, RoaMvp, AppPresenter) WidgetDisplay asWidget() WidgetPresenter onPlaceRequest() Don’t forget to call bind() in constructor! WidgetContainerPresenter, DeckPresenter Create new presenter & view
gwt-presenter gotchas Don’t forget to call bind() in constructor! Loads all presenters at startup …  and all views …  with many Widgets in the views Alternatives Temp solution: LazyPresenter replaces onBind() with onFirstRequest() Real solution: GWT.runAsync(), working on it…
Command pattern GWT-RPC basics: every service = 3 classes Service interface (LoginService) Async version (LoginServiceAsync) Server impl (LoginServiceImpl) @RemoteServiceRelativePath(&quot;gwtlogin&quot;) public   interface  LoginService  extends  RemoteService { public  LoginInfo login(String requestUri)  throws  UserNotRegisteredException; }
Command pattern Eclipse tooling auto-creates the asyncs What if you wanted to add a standard arg to every service call? Like a security token to prevent CSRF Would have to add to every interface, async, and impl UGH Or what if you wanted to cache data from service calls?
Command pattern Turn verbs (methods) into nouns (classes) loginService.login(p1,p2…,callback); dispatchService.execute(new LoginAction(), new AsyncCallback<LoginResult>() { handleSuccess(LoginResult result)… handleFailure(Throwable caught)… }
Command pattern Command pattern benefits Send security token in DispatchService and Actions don’t even have to know about it Actions and ActionHandlers can extend base classes Constructor params are saved with the cmd Caching! Batching! Queuing! Rollback!
gwt-dispatch Companion framework by David Peterson http://code.google.com/p/gwt-dispatch/ Base classes for Action, Result DisplayCallback automatically calls start/stop view on service call init/return HiveMind MVP tutorial highly recommended!
gwt-dispatch Wiring it up (GuiceConfig, ServerModule, DispatchServletModule) Create new Result, Action, ActionHandler Call it from presenter
Good practice #3 Stop thinking synchronously! Pass Callbacks everywhere a trip to the server may be needed ArrayList<User> service.getUsers() service.getUsers(new AsyncCallback() {…}); Extend AsyncCallback with your own Provide standard handleFailure(); Other standard handling on call or return
Tools In case I forgot… Web Developer Toolbar (Ctrl+Shift+E) Firebug (F12) YSlow Chrome Developer Tools! Speed Tracer (runs in Chrome)
Other GWT goodies DeferredCommand Often necessary for setFocus() Timer Good for animation http://code.google.com/p/gwt-fx/ Fade, blinds, etc.
Resources Book The CSS Anthology (Rachel Andrew, 3 rd  Ed.) Blogs HiveMind MVP tutorial http://blog.turbomanage.com  (lots of gwt-dispatch, gwt-presenter example code) Google I/O videos AppEngine + GWT Training Apr 12-13

More Related Content

What's hot (20)

PDF
Qt and QML performance tips & tricks for Qt 4.7
Pasi Kellokoski
 
PDF
Part 1: ng-grid and a Simple REST API
reneechemel
 
PDF
WebGL and three.js
Anton Narusberg
 
PDF
Best Practices in Qt Quick/QML - Part III
ICS
 
PPTX
GWTcon 2015 - Best development practices for GWT web applications
Arcbees
 
PPT
Gwt RPC
maheshm1206
 
PDF
Qt Internationalization
ICS
 
PDF
QThreads: Are You Using Them Wrong?
ICS
 
PDF
Best Practices in Qt Quick/QML - Part 3
ICS
 
PPTX
Qt for beginners part 5 ask the experts
ICS
 
PDF
Driving and virtualizing control systems: the Open Source approach used in Wh...
Igalia
 
PDF
Meet the Widgets: Another Way to Implement UI
ICS
 
PPT
Multiple Screens
graphitech
 
PPT
Starting with Reactjs
Thinh VoXuan
 
PDF
Introducing GWT Polymer (vaadin)
Manuel Carrasco Moñino
 
PDF
Qt multi threads
Ynon Perek
 
PDF
Angry Developer: Creating a Game in QML and JavaScript for MeeGo N9 @iRajLal
Raj Lal
 
PDF
Software Development Best Practices: Separating UI from Business Logic
ICS
 
PDF
QVariant, QObject — Qt's not just for GUI development
ICS
 
PDF
Introduction to ReactJS
Tu Hoang
 
Qt and QML performance tips & tricks for Qt 4.7
Pasi Kellokoski
 
Part 1: ng-grid and a Simple REST API
reneechemel
 
WebGL and three.js
Anton Narusberg
 
Best Practices in Qt Quick/QML - Part III
ICS
 
GWTcon 2015 - Best development practices for GWT web applications
Arcbees
 
Gwt RPC
maheshm1206
 
Qt Internationalization
ICS
 
QThreads: Are You Using Them Wrong?
ICS
 
Best Practices in Qt Quick/QML - Part 3
ICS
 
Qt for beginners part 5 ask the experts
ICS
 
Driving and virtualizing control systems: the Open Source approach used in Wh...
Igalia
 
Meet the Widgets: Another Way to Implement UI
ICS
 
Multiple Screens
graphitech
 
Starting with Reactjs
Thinh VoXuan
 
Introducing GWT Polymer (vaadin)
Manuel Carrasco Moñino
 
Qt multi threads
Ynon Perek
 
Angry Developer: Creating a Game in QML and JavaScript for MeeGo N9 @iRajLal
Raj Lal
 
Software Development Best Practices: Separating UI from Business Logic
ICS
 
QVariant, QObject — Qt's not just for GUI development
ICS
 
Introduction to ReactJS
Tu Hoang
 

Similar to GWT MVP Case Study (20)

ODP
RIA implementation patterns
Ürgo Ringo
 
PPTX
GWT = easy AJAX
Olivier Gérardin
 
PDF
Javaland 2014 / GWT architectures and lessons learned
pgt technology scouting GmbH
 
PPT
Google Dev Day2007
lucclaes
 
PPTX
YaJUG: What's new in GWT2
Olivier Gérardin
 
PPT
Google Web Toolkit Introduction - eXo Platform SEA
nerazz08
 
PPT
GWT
Lorraine JUG
 
PPT
Google Web Toolkits
Yiguang Hu
 
PPT
GWT is Smarter Than You
Robert Cooper
 
PPT
Google Web Toolkit
Christos Stathis
 
PPTX
Google web toolkit web conference presenation
Stephen Erdman
 
PPT
GWT Extreme!
cromwellian
 
PPT
GWT
yuvalb
 
PDF
Best Practices - By Lofi Dewanto
GWTcon
 
PPT
Google Web Toolkits
Yiguang Hu
 
PPTX
Ext GWT - Overview and Implementation Case Study
Avi Perez
 
PPTX
Gwt session
Mans Jug
 
PPTX
Gwt session
Ahmed Akl
 
PDF
GWT-Basics
tutorialsruby
 
PDF
GWT-Basics
tutorialsruby
 
RIA implementation patterns
Ürgo Ringo
 
GWT = easy AJAX
Olivier Gérardin
 
Javaland 2014 / GWT architectures and lessons learned
pgt technology scouting GmbH
 
Google Dev Day2007
lucclaes
 
YaJUG: What's new in GWT2
Olivier Gérardin
 
Google Web Toolkit Introduction - eXo Platform SEA
nerazz08
 
Google Web Toolkits
Yiguang Hu
 
GWT is Smarter Than You
Robert Cooper
 
Google Web Toolkit
Christos Stathis
 
Google web toolkit web conference presenation
Stephen Erdman
 
GWT Extreme!
cromwellian
 
GWT
yuvalb
 
Best Practices - By Lofi Dewanto
GWTcon
 
Google Web Toolkits
Yiguang Hu
 
Ext GWT - Overview and Implementation Case Study
Avi Perez
 
Gwt session
Mans Jug
 
Gwt session
Ahmed Akl
 
GWT-Basics
tutorialsruby
 
GWT-Basics
tutorialsruby
 
Ad

More from David Chandler (13)

PDF
StORM: a lightweight ORM for Android SQLite
David Chandler
 
PDF
Easy REST APIs with Jersey and RestyGWT
David Chandler
 
PDF
Cómo trabajan los Googlers
David Chandler
 
PDF
Life of an engineer
David Chandler
 
PDF
StORM preview
David Chandler
 
PDF
Google App Engine Update 2012
David Chandler
 
PDF
GWT Plus HTML 5
David Chandler
 
PDF
Scalable Apps with Google App Engine
David Chandler
 
PDF
What's New in GWT 2.2
David Chandler
 
PDF
Develop and Deploy Scalable Apps with Google App Engine
David Chandler
 
PDF
Secrets of the GWT
David Chandler
 
PPT
The 90-Day Startup with Google AppEngine for Java
David Chandler
 
PDF
Securing JSF Applications Against the OWASP Top Ten
David Chandler
 
StORM: a lightweight ORM for Android SQLite
David Chandler
 
Easy REST APIs with Jersey and RestyGWT
David Chandler
 
Cómo trabajan los Googlers
David Chandler
 
Life of an engineer
David Chandler
 
StORM preview
David Chandler
 
Google App Engine Update 2012
David Chandler
 
GWT Plus HTML 5
David Chandler
 
Scalable Apps with Google App Engine
David Chandler
 
What's New in GWT 2.2
David Chandler
 
Develop and Deploy Scalable Apps with Google App Engine
David Chandler
 
Secrets of the GWT
David Chandler
 
The 90-Day Startup with Google AppEngine for Java
David Chandler
 
Securing JSF Applications Against the OWASP Top Ten
David Chandler
 
Ad

Recently uploaded (20)

PDF
introduction to computer hardware and sofeware
chauhanshraddha2007
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
PPTX
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
PPTX
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PPTX
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
PDF
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PDF
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PPTX
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 
introduction to computer hardware and sofeware
chauhanshraddha2007
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
TrustArc Webinar - Navigating Data Privacy in LATAM: Laws, Trends, and Compli...
TrustArc
 
Farrell_Programming Logic and Design slides_10e_ch02_PowerPoint.pptx
bashnahara11
 
Agentic AI in Healthcare Driving the Next Wave of Digital Transformation
danielle hunter
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
The Future of Mobile Is Context-Aware—Are You Ready?
iProgrammer Solutions Private Limited
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
The Future of Artificial Intelligence (AI)
Mukul
 
AVL ( audio, visuals or led ), technology.
Rajeshwri Panchal
 
NewMind AI Weekly Chronicles – July’25, Week III
NewMind AI
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Peak of Data & AI Encore - Real-Time Insights & Scalable Editing with ArcGIS
Safe Software
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
How ETL Control Logic Keeps Your Pipelines Safe and Reliable.pdf
Stryv Solutions Pvt. Ltd.
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
AI Code Generation Risks (Ramkumar Dilli, CIO, Myridius)
Priyanka Aash
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
Generative AI vs Predictive AI-The Ultimate Comparison Guide
Lily Clark
 

GWT MVP Case Study

  • 1. GWT with MVP: A Case Study David Chandler [email_address] http://blog.TurboManage.com
  • 2. OR… How I learned to love ( C S S && anonymous() { inner() {} classes() {} });
  • 3. Who is this guy? Wrote first book on running a Web site (1995) Written Web apps in perl, ksh, C with lex/yacc, ColdFusion, JSF, GWT Most recently, Web architect with Intuit on Internet banking products Patent on non-recursive SQL trees Working in a startup last 6 mos
  • 4. Anatomy of a GWT app What’s GWT+MVP? “ Good” practices & patterns gwt-presenter gwt-dispatch Caching, batching, queuing GWT Tools Resources
  • 5. GWT+MVP Model View Presenter Way of organizing code analogous to MVC Services  Presenter  View View implements interface defined in presenter fires no events of its own Presenter listens for DOM events (ClickHandlers, etc.) listens on event bus calls services
  • 6. GWT+MVP Where to put the model? Singleton accessible everywhere? (user info) Hide it behind services? Bits & pieces in each presenter? None at all?
  • 7. Good practice #1 Define the Display interface Return interfaces, not Widgets Supports testing, decoupling from view Button getSaveButton(); HasClickHandlers getSaveButton(); Caveat: sometimes you have to write your own
  • 8. How to untangle How can presenters communicate with services and each other? Example: new friend added Does main presenter hold ref to all others? Use an event bus Define your own application events extending GwtEvent Presenters add handlers to listen for events
  • 9. Good practice #2 Let presenter handle all events (even DOM) Sometimes hard If put click handler in the view, then view would have to call service layer Instead, handle in presenter display.getSaveButton().addClickHandler…
  • 10. How to handle Widget collections? Say, every row in a table has clickable widgets Ans #1: catch event in parent Widget only a) each table cell is a DIV. Handle event in containing Widget Note: parent must be a Widget to receive events (and all of its ancestors) b) along with this, expose handler reg mechanism through interface
  • 11. How to handle Widget collections? What if every row has multiple TextBoxes? Ans #2: write Display interface with arrays interface Display { HasValue<String> getFirstName(int i); HasValue<String> getLastName(int i); int getNumRows(); void addRows(int n); }
  • 12. Guice Google’s dependency injection framework Small, light, almost plain English ServerModule DispatchServletModule DispatchTestModule ROAUserServiceImpl Used by gwt-dispatch, useful for unit tests
  • 13. Google GIN Dependency injection for GWT Quite useful for MVP implementations Provides access to EventBus, Dispatch, anything “global” your app may need Auto-creates Images and Constants Instead of GWT.create(RoaImages.class); Can use bind(RoaImages. class ).in(Singleton. class ); @Inject RoaImages images;
  • 14. gwt-presenter Open source framework by David Peterson http://code.google.com/p/gwt-presenter/ Very clean MVP implementation Uses GIN to bind presenters as singletons “ Place” management Automatically syncs GWT History object when fire PlaceRequestEvent in code When browser URL changes, fires PRE
  • 15. gwt-presenter Look at wiring (RoaModule, RoaGinjector, RoaMvp, AppPresenter) WidgetDisplay asWidget() WidgetPresenter onPlaceRequest() Don’t forget to call bind() in constructor! WidgetContainerPresenter, DeckPresenter Create new presenter & view
  • 16. gwt-presenter gotchas Don’t forget to call bind() in constructor! Loads all presenters at startup … and all views … with many Widgets in the views Alternatives Temp solution: LazyPresenter replaces onBind() with onFirstRequest() Real solution: GWT.runAsync(), working on it…
  • 17. Command pattern GWT-RPC basics: every service = 3 classes Service interface (LoginService) Async version (LoginServiceAsync) Server impl (LoginServiceImpl) @RemoteServiceRelativePath(&quot;gwtlogin&quot;) public interface LoginService extends RemoteService { public LoginInfo login(String requestUri) throws UserNotRegisteredException; }
  • 18. Command pattern Eclipse tooling auto-creates the asyncs What if you wanted to add a standard arg to every service call? Like a security token to prevent CSRF Would have to add to every interface, async, and impl UGH Or what if you wanted to cache data from service calls?
  • 19. Command pattern Turn verbs (methods) into nouns (classes) loginService.login(p1,p2…,callback); dispatchService.execute(new LoginAction(), new AsyncCallback<LoginResult>() { handleSuccess(LoginResult result)… handleFailure(Throwable caught)… }
  • 20. Command pattern Command pattern benefits Send security token in DispatchService and Actions don’t even have to know about it Actions and ActionHandlers can extend base classes Constructor params are saved with the cmd Caching! Batching! Queuing! Rollback!
  • 21. gwt-dispatch Companion framework by David Peterson http://code.google.com/p/gwt-dispatch/ Base classes for Action, Result DisplayCallback automatically calls start/stop view on service call init/return HiveMind MVP tutorial highly recommended!
  • 22. gwt-dispatch Wiring it up (GuiceConfig, ServerModule, DispatchServletModule) Create new Result, Action, ActionHandler Call it from presenter
  • 23. Good practice #3 Stop thinking synchronously! Pass Callbacks everywhere a trip to the server may be needed ArrayList<User> service.getUsers() service.getUsers(new AsyncCallback() {…}); Extend AsyncCallback with your own Provide standard handleFailure(); Other standard handling on call or return
  • 24. Tools In case I forgot… Web Developer Toolbar (Ctrl+Shift+E) Firebug (F12) YSlow Chrome Developer Tools! Speed Tracer (runs in Chrome)
  • 25. Other GWT goodies DeferredCommand Often necessary for setFocus() Timer Good for animation http://code.google.com/p/gwt-fx/ Fade, blinds, etc.
  • 26. Resources Book The CSS Anthology (Rachel Andrew, 3 rd Ed.) Blogs HiveMind MVP tutorial http://blog.turbomanage.com (lots of gwt-dispatch, gwt-presenter example code) Google I/O videos AppEngine + GWT Training Apr 12-13

Editor's Notes

  • #6: Show interface AddPrayerPresenter
  • #8: AddPrayerPresenter HasSelectedValue
  • #9: Show how ManagePrayersPresenter init just listens for events EMPHASIZE ASYNCHRONOUS Show typing strategy for GwtEvent (copy handler, then Event)
  • #11: #1 See ItemsTable.refresh (maybe show setid in Firefox), onClick #2 show ItemsTable.onClick fires ItemSelectedEvent ItemsTable.addSelectionHandler
  • #13: ServerModule DispatchServletModule DispatchTestModule ROAUserServiceImpl Speaking of unit tests, show BaseTest
  • #14: Show RoaModule Show ManagePrayersPresenter
  • #16: ROAModule ROAGinjector ROAMvp AppPresenter DailyROAPresenter
  • #18: Backup why GWT-RPC Lets you send POJOs, handler serialization / deserialization Show RoaMvp also
  • #21: Demo cache hits Daily ROA, Home, Daily ROA Look at AddPrayerPresenter, search for refreshPrayerLists
  • #22: Show AddPrayerPresenter:155
  • #23: Guice
  • #26: As seen in MessageView