RIA Mit ZK Boost Your Productivity
Total Page:16
File Type:pdf, Size:1020Kb
RIA mit ZK Boost your productivity Daniel Seiler, AIA 2008, Mainz Agenda Introduction ZK basics ZK component library We build an application ZK advanced concepts Custom component example Integration example, Gmaps Summary Goals of this session Infect you with the ZK virus You are able to explain the position of ZK in the current RIA Landscape You know the main features, concepts and principles of ZK Daniel Seiler, Processwide AG 3 The problem to solve To build rich, interactive, fast and scalable, distributed business applications ... ... we need a framework and technology that ... ... maximizes our productivity by abstracting and hiding much of the complexity ... provides a rich set of prebuilt components and features ... is easy to extend Daniel Seiler, Processwide AG 4 The big picture Local offline Trad. Distributed Rich (Asynchronous update, sorting, drag & drop, ...) Trad. Web- tools applications applications I nternet (Communication with Webserver) (Standalone, not ('Fat client', corba, RMI, (Page reloading, distributed, ...) local installation, ...) Application (User interactions, data storage, ...) simple controls) Office tools Eclipse RCP Runs in an external Runs directly in a runtime environment browser (No plugin, (plugin or standalone) Ajax) Applets (Java) Javascript Framework Flex (flash) library Laszlo (flash) Curl Captain Casa jQuery Echo2 (Swing, JSF) Prototype GWT Script.aculo.us ICE Faces DWR ZK Daniel Seiler, Processwide AG 5 The right tool for your job R ichness + Rich UI Local offline - Local, no central access tools - Application distribution (e.g. Java Webstart etc...) , User ex + Rich UI Trad. distributed + Proven development model, tool support per applications (Fat) - Application distribution (e.g. Java Webstart etc...) - Complex to build distributed applications ience + Rich UI RIA + Easy application distribution External RTE - Needs installation of RTE - Communication with server not fully out of the box + Quite rich UI RIA y + Distributed by nature ilit Ajax - Slower user experience due to slow Javascript - Needs lot of resources on the server + Everywhere available through standard browser availab Trad. web- l - Poor UI apps - Complex technology stack (HTML, CSS, Javascript, ...) Globa Daniel Seiler, Processwide AG 6 Why Ajax? Basic idea: breaking up the concept of the webpage to allow dynamic updates of certain areas within one page to increase the overall user experience Typical technology stack: XHTML and CSS, Document Object Model, XML and XSLT The XMLHttpRequest object for asynchronous communication JavaScript to bring these technologies together Disadvantages: Traditional webconcepts like back button and bookmarks need to be rethought Indexing through search engines is not guaranteed Depends on Javascript switched on in the browser Complex technology stack Javascript is quite slow. There is hope: (http://www.google.com/chrome) Daniel Seiler, Processwide AG 7 Ajax tools Snippet jQuery, prototype, script.aculo.us, DWR Widget Yahoo UI Library, jbossrichfaces former Ajax4JSF, Dojo Toolkit Framework Backbase, ZK, Echo2, GWT, ICE Faces Daniel Seiler, Processwide AG 8 What is ZK? Web: http://www.zkoss.org Developed by: Potix Corporation 11F-2, No.87, Zhengzhou Road Taipei, 103 Taiwan, Republic of China +886-2-2552-1002 According to wikipedia: http://en.wikipedia.org/wiki/ZK_Framework ZK is an open-source Ajax Web application framework, written in Java, that enables creation of rich graphical user interfaces for Web applications with no JavaScript and little programming knowledge. ZK takes the so called server-centric approach that the content synchronization of components and the event pipelining between clients and servers are automatically done by the engine and Ajax plumbing codes are completely transparent to web application developers. Daniel Seiler, Processwide AG 9 Selling points Open Source: ZK is the leading open source Ajax + Mobile framework. ZK developer community is extremely active with 20+ translations, 100+ articles/blogs, and 100,000+ lines of codes, 700,000+ downloads, from 190+ countries. Rich User Experience: 170+ off-the-shelf state-of-art XUL/HTML-complaint Ajax components. Numerous third party widgets: JFreeChart, JasperReports, Google Maps, FCKeditor, Timeline, Timeplot, ExtJS, Dojo and so on Server push support: Comet and Client polling Standards-based: ZK is a standard-compliant solution. Extensibility and Customizability: ZK is fully customizable and extensible with modular and plug-and-play architecture. Mobile Access: ZK extends the reach of enterprise Internet applications to 1+ billion mobile devices at minimal cost. ZK supports Java Mobile, Android, and various mobile browsers. Security: ZK is designed from the ground up to be secure. Sun is using it for their virtual platform management suite: http://www.openxvm.org/xvmsui.html Daniel Seiler, Processwide AG 10 ZK Products Framework ZK Framework ZK Mobile Application component ZK Spreadsheet Development ZK Studio Enterprise Integration ZK JSP, JSF, Portlet, RSS ZK Forge Integrating third party widgets, such as ZK Gmaps, ZK FCKeditor, ZK Timeline, ZK Ext JS, ZK Dojo and so on Daniel Seiler, Processwide AG 11 ZK's Ajax solution Many Documents One ZUL <window title="Context Menu and Right HTML Click" border="normal" width="360px"> <label value="Move Mouse Over Me!" Simplify tooltip="edit"/> CSS </window> ZK Ajax Framework Javascript IE6 Firefox Opera … Firefox IE7 One Browser Many Browsers Daniel Seiler, Processwide AG 12 Generating an HTML page Browser Server 1. Browser sends an URL 4. ZK events (optional) ex: onCreate() Event DOM ZK Queue Layout 5. ZK Engine 2.Query & events Load page (opt.) Javascript action Internet Application Code 3. Create *.zul components 8. Return (opt.) ZK Client 6. Access persistent layer Engine or other utilities 9. Response 7. Manipulate a HTML page EJB, JDO, components ZK MQ, Mail… components (optional) Daniel Seiler, Processwide AG 13 ZK doing Ajax Daniel Seiler, Processwide AG 14 ZK – Overall picture ZK JSP ZK JSF ZK Portlet ZK RSS ZK Server Push Mobile ZUL/XHTML XML ZK MAX Component SetSec 508 Output ZK Core zscript EL Bean Common Groovy Ruby MV EL OGNL . Shell . EL Daniel Seiler, Processwide AG 15 ZK Components See: http://www.zkoss.org/zkdemo/userguide/ XUL (Mozilla) compliant 170+ off-the-shelf components ▹ grid, tabbox, listbox, combobox, chart, splitter, slider, groupbox… ▹ Context Menu ▹ Drag and Drop ▹ Live data (listbox and grid) ▹ Auto-completion (combobox) ▹ Customizable sorting (listbox and grid) Daniel Seiler, Processwide AG 16 ZUL, EL and zscript <window id="myWindow" title="fileupload demo" border="normal"> <button label="Upload for ${myWindow.title}"> <attribute name="onClick"> { Object media = Fileupload.get(); if (media instanceof org.zkoss.image.Image) { Image image = new Image(); image.setContent(media); image.setParent(pics); } else if (media != null) Messagebox.show("Not an image:" + media, "Error", Messagebox.OK, Messagebox.ERROR); } </attribute> </button> <zscript>myWindow.appendChild(new Button("New Button"));</zscript> <vbox id="pics" /> </window> Lets try it out on the ZK components Demo page ... Daniel Seiler, Processwide AG 17 Our first application 1) User enters his personal data 2) Data gets sent to the server and stored in a DB 3) Table gets updated with the new user Daniel Seiler, Processwide AG 18 Architecture Daniel Seiler, Processwide AG 19 simple.zul <?page id="simplePage" title="Simple ZK Application"?> <zk> <window id="simpleWindow" use="com.processwide.demo.zk.window.SimpleWindow" title="Simple ZK Demo" border="normal" width="800px" height="500px"> <caption label="${simpleWindow.myCaption}" /> Declaration of <grid> external Java class <rows> as view handler <row>Firstname*:<textbox id="firstname" width="300px" /></row> ... Expression language, </rows> default: common-el </grid> ... <button label="Save" onClick="simpleWindow.addPerson()" /> <grid id="personsGrid"> Scripting code, ... default: BeanShell </grid> Placeholder for dynamically </window> updated result table Danie</zkl >Seiler, Processwide AG 20 SimpleWindow.java 1/2 public class SimpleWindow extends Window { private Grid personsGrid; public void onCreate() { createPersonsGrid(); } public String getMyCaption() { return "(C) 2008 by Processwide AG"; } private void createPersonsGrid() { personsGrid = (Grid)Path.getComponent("/simpleWindow/personsGrid"); // add all the persons List<Person> persons = PersonDAO.getInstance().getAllPersons(); for (Iterator<Person> it = persons.iterator(); it.hasNext();) { Person person = it.next(); addPersonRecord(person); } } ... Daniel Seiler, Processwide AG 21 SimpleWindow.java 2/2 ... public void addPerson() { // extracting the person data Textbox firstName = (Textbox) Path.getComponent("/simpleWindow/firstname"); ... Person personBean = new Person(); personBean.setFirstname(firstName.getValue()); ... PersonDAO.getInstance().addPerson(personBean); addPersonRecord(personBean); } public void addPersonRecord(Person person) { Row row = new Row(); Rows rows = personsGrid.getRows(); rows.appendChild(row); row.appendChild(new Label(person.getFirstname())); ... } Daniel Seiler, Processwide AG 22 Add a delete button public void addPersonRecord(final Person person) { final Row row = new Row(); final Rows rows = personsGrid.getRows(); rows.appendChild(row); // create the delete button Button deleteBtn = new Button("delete"); deleteBtn.addEventListener("onClick", new EventListener() { public void onEvent(final Event arg0) throws Exception { //