ZK MVVM, Spring & JPA On Two PaaS Clouds
Upcoming SlideShare
Loading in...5
×
 

ZK MVVM, Spring & JPA On Two PaaS Clouds

on

  • 9,188 views

 

Statistics

Views

Total Views
9,188
Views on SlideShare
9,174
Embed Views
14

Actions

Likes
1
Downloads
117
Comments
2

3 Embeds 14

http://a0.twimg.com 8
http://paper.li 3
https://si0.twimg.com 3

Accessibility

Categories

Upload Details

Uploaded via as OpenOffice

Usage Rights

CC Attribution License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • The source code discussed in this slide is now the subject of an article 'Implementing event-driven GUI patterns using the ZK Java AJAX framework'

    http://www.ibm.com/developerworks/websphere/zones/portal/proddoc/zkjavaajax/
    Are you sure you want to
    Your message goes here
    Processing…
  • For more on ZK MVVM see the old deck which pre-dates the official ZK6 'ZK Bind' support at http://tinyurl.com/bw8wnge
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

ZK MVVM, Spring & JPA On Two PaaS Clouds ZK MVVM, Spring & JPA On Two PaaS Clouds Presentation Transcript

  • ZK, Spring & JPA On Two PaaS Clouds(Java MVVM Adventures Featuring Heroku & Openshift) Simon Massey
  • OverviewWhat is PaaS "Cloud" and why we should care?Background to the ZkToDo2 sample appOutline of the MVVM PatternWalk through of MVVM sample page (new ZK6 features!)Quick pass of the Spring & JPA internalsThe key ingredient: maven build profilesLive push of source to two clouds! (Fingers crossed!)
  • Clouds (In One Slide)Clouds come "as a service" (aaS) Software aaS Infrastructure aaS Platform aaSSaaS is your data on the cloud with leased software (they do everything)IaaS is leased managed hardware (they can do the network)PaaS is leased application/database capacity (they keep it running whilst you write the app)
  • The PaaS PropositionServer virtualization is very mainstream. High density host servers reduce overheadsFailover, off-site backup, standby servers, spare parts, upgrades, network is divided by number of virtual serversRent a "virtual private server" (VPS) and you have to set it up and care for it yourself (logs filling up your disks?)How do you source 0.2 system adminstrators for your app? And if they change jobs?Outsource this to a PaaS provider!
  • The PaaS Proposition (2)A big provider with a big server farm has automated deployment "elastic platform"Need more power? "Click here Sir to approve the monthy credit card payments..."Choice is a double edged sword; standardization is the key to maintaining a large estate of applicationsBig cloud farms run thousands of servers and are evolving best practice at a high rateRunning your own servers is very last century; you can offload that work to the experts
  • Is Your PaaS RIA Friendly?Not all PaaS clouds are AJAX friendly. Some assume that you are hosting a blog (i.e. stateless full page reload app)Not all PaaS clouds provide a relational database. ZK apps tend to be data orientated desktop-like apps which need an RDBMSJ2EE is "complex" but PHP and Ruby are "simple"(??). Java sat outside the party whilst Ruby On Rails danced up a storm… but now the big Rails clouds are doing Java and are making it look very easy!
  • InterludeCode https://github.com/simbo1905/ZkToDo2Where is it running?Redhat Openshift zktd2-zkdemo.rhcloud.comHeruko glowing-light-1070.herokuapp.com(note: apps may suspend when idle so may take a long time to start on first hit)What IDE, DB, etc?
  • The Code In ContextThe "ZK ToDo 2" sample app has the same screen implimented three times; using MVP, MVC and ZK6 MVVM (aka MVB) patternsThree ZK articles document the different patterns in the code MVP (2007), MVC (2009), MVVM (2011). MVVM article is out of date as sample code now does ZK6 "ZK Bind" MVVMSample code has moved to the zktodo2 repo on GitHub with an Apache2 licenseThe code now deploys to Heroku or Openshift PaaS clouds!
  • About The CodeThe "ZkToDo2" sample app (aka zktd2) is a simple database CRUD app written with ZK, Spring and JPACode uses a relational DB and has configurations for HSQL, MySQL and PostreSQL databasesSpring instantiates the objects and wires them together when the ZUL page "asks for" a spring bean due to XML databindingsLeverages SpringMVC scopes and ZKSpring for elegant care free coding
  • The MVVM Screen....
  • … is all databindings! Your ClickMe! 1 Java 2ZK Web ZKDesktop Bind 4 3Saved! this.msg="Saved!"
  • Model-View-ViewModel View == Web Desktop Binder <<reflection>> Legend ViewModel compiles to command DomainModel load
  • The ViewModel Class[show code] org.zkforge.zktodo2.ZkToDoViewModelHolds the List<Reminder> the user is working withHolds the selectedItem Reminder the user is currently editingUses the ReminderService which updates the databaseHas the add(), save(), delete() methodsCan be shared by different viewsThe view is active; "@bind" has AJAX updates write to the selectedItem Reminder
  • Data BindingsPage load calls getReminders on toDoViewModel and renders each date in a list:<window apply="org.zkoss.bind.BindComposer" viewModel="@id(vm) @init(toDoViewModel2)"><listbox model="@load(vm.reminders)" selectedItem="@bind(vm.selectedReminder)"><template name="model" var="reminder"><listitem> <listcell label="@load(reminder.date)"/></listitem></template</listbox></window>
  • Data Bindings 2When the user selects a different reminder in the list let the user edit it in the edit panel:Date:<datebox value="@bind(vm.selectedReminder.date)" />The vm.selectedReminder is refered to in multiple places. It is written to by the onSelect Event of the Listbox:<listbox model="@load(vm.reminders)" selectedItem="@bind(vm.selectedReminder)">ZKBind keeps track what it changes and reloads UI with changed state
  • Command BindingsNew in ZK6!<button label="Save" onClick="@command(save)"/>There is zero code to read/write data between screen and the JPA entites: binder is updating them over AJAXsave() only calls save(selectedReminder) or delete(selectedReminder)The binder is a generic UI ControllerZK Bind updates UI + Model + EntitiesYou just write very testable Java!
  • Less Boiler Plate CodeJava methods which change state have hints as to what to reload into the screen:@Command@NotifyChange({"reminders","selectedReminder"})public void delete() { .... }Annotations on the Reminder entity setters and on the ViewModel CRUD methodsDesktop "zul" is bound onto the ViewModelCould make "admin screen" & "read-only screen" for the same ViewModel (else "touch screen" & "mouse screen")
  • Spring Bean XML Definitions...ViewModel bean has "desktop" scope <bean id="toDoViewModel2" class="org.zkforge.zktodo2.ZkToDoViewModel" p:reminderService-ref="reminderService" scope="desktop" />So only one bean per web desktop (you may have many desktops per http session)... has singleton reminder service: <bean id="reminderService" class="org.zkforge.zktodo2.ReminderService"p:basicDao-ref="basicDao" />… has singleton basicDao: <bean id="basicDao" class="org.zkforge.zktodo2.BasicDao"/ >
  • … Stable Since 2007Same BasicDao for other patterns demo screensThese days you dont need the Spring XML. Spring has alternative way to specificy how to wire up the beans (with Java annotations)CDI would not be hard at all (see zkcdi library)Back-end code is "orthodox" allowing us to focus on the code and whats new; ZK Patterns… and deploying onto different Clouds!
  • ZK Cloud "Bake Off"Two leading cloud providers chosen scientifically and at random (google+beer)Each backed by a major software company (Salesforce vs Redhat)Are they opensource like ZK, do they run it well, and are they easy to use...?
  • What Do You Get? Feature Heroku Openshift Deploy from Yes. Git + Maven Yes. Git + Maven source?[1] Database? PostgreSQL MySQL Container? Jetty7.4 JBossAS7.0 (embedded) (standalone) Proprietary No problems for No problems for Gotchas?[2] the sample app the sample app[1] With Git you commit locally and "push" all the commits to one or more repos. One remote repo is the cloud; it compiles+deploys[2] ”Can I move my production app at any time to my own servers?”
  • The Maven Build ProfilesDevelop and debug on the jetty-maven-plugin ”mvn jetty:run” then deploy to JBoss, Weblogic, Websphere or Tomcat when it is ready to user testWhen in JUnit or debugging (jetty:run) Spring is configured to setup the resources (datasource, jms)To run in JBossAS7 Spring is configured to pull in the platform resources (jndi-datasource, jndi-jms)Maven build profiles swap the Spring configuration based on a "-P" parameter using webapp "overlays"Write once deploy to any cloud: mvn -P "openshift" package mvn -P "cloudX" package
  • Live Deploy DemoThis could be wishful thinking...![p.s. All went well, we committed a change to the screen locally and with a single command deployed to each of the two cloud services]
  • … And The Winner Is ...?Both clouds are lightening fast for ZK AJAX!Both have fully opensourced stacks!Both are oh-so-easy-to-use
  • ReferencesThe code https://github.com/simbo1905/ZkToDo2ZK6 MVVM introduction Hello ZK MVVMMVC article Desktop MVC Patterns ZK, Spring & JPAOriginal MVP article SmallTalks 2008 Best MVC PatternsBook on how to build a layered domain model with Spring POJOs In ActionMartin Fowler GUI Patterns pages UI ArchitecturesJosh Smiths inspirational Microsoft .Net MVVM Article