Common-Controls Guided Tour TreeControl

Similar documents
Common-Controls Guided Tour TreeListControl

Common-Controls Guided Tour ListControl

Common-Controls Guided Tour TabSetControl

Auftrag. Common-Controls Guided Tour FormTag s

Common-Controls Quickstart

directive attribute1= value1 attribute2= value2... attributen= valuen %>

JSF & Struts 1, 4, 7, 2, 5, 6, 3 2, 4, 3, 1, 6, 5, 7 1, 4, 2, 5, 6, 3, 7 1, 2, 4, 5, 6, 3, 7

Jakarta Struts. Pocket Reference. Chuck Cavaness and Brian Keeton. Beijing Boston Farnham Sebastopol Tokyo

Sun Sun Certified Web Component Developer for J2EE 5 Version 4.0

CSC309: Introduction to Web Programming. Lecture 11

Web Programming. Lecture 11. University of Toronto

Advanced Java Programming

Welcome To PhillyJUG. 6:30-7:00 pm - Network, eat, find a seat 7:00-7:15 pm - Brief announcements 7:15-8:30 pm - Tom Janofsky's presentation

Java Programming Language

Building Web Applications With The Struts Framework

1 CUSTOM TAG FUNDAMENTALS PREFACE... xiii. ACKNOWLEDGMENTS... xix. Using Custom Tags The JSP File 5. Defining Custom Tags The TLD 6

COURSE 9 DESIGN PATTERNS

Advanced Graphics Components Using JavaServer Faces Technology. Christophe Jolif Architect ILOG S.A.

JAVA. Duration: 2 Months

Oracle EXAM - 1Z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Buy Full Product

CS506 Web Design & Development Final Term Solved MCQs with Reference

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

SAS Web Infrastructure Kit 1.0. Overview

Module 3 Web Component

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

Courses For Event Java Advanced Summer Training 2018

PSD1B Advance Java Programming Unit : I-V. PSD1B- Advance Java Programming

Struts interview questions

[Course Overview] After completing this module you are ready to: Develop Desktop applications, Networking & Multi-threaded programs in java.

JavaServer Pages (JSP)

Oracle 1z Java Enterprise Edition 5 Web Component Developer Certified Professional Exam. Practice Test. Version:

IDIOM + BUSINESS RULES BEANS

Introduction to Java Server Pages. Enabling Technologies - Plug-ins Scripted Pages

/ / JAVA TRAINING

S imilar to JavaBeans, custom tags provide a way for

Servlet and JSP Review

A JavaBean is a class file that stores Java code for a JSP

Tapestry. Code less, deliver more. Rayland Jeans

An implementation of Tree Panel component in EXT JS 4.0

JavaServer Pages. What is JavaServer Pages?

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

The project is conducted individually The objective is to develop your dynamic, database supported, web site:

SNS COLLEGE OF ENGINEERING, Coimbatore

import com.ibm.portal.portlet.service.impersonation.impersonationservice;

The Struts MVC Design. Sample Content

sessionx Desarrollo de Aplicaciones en Red EL (2) EL (1) Implicit objects in EL Literals José Rafael Rojano Cáceres

Multiple Inheritance, Abstract Classes, Interfaces

web.xml Deployment Descriptor Elements

COURSE DETAILS: CORE AND ADVANCE JAVA Core Java

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Java Server Pages. JSP Part II

Selected Java Topics

Securent Entitlement Management Solution. v 3.1 GA. JACC Agent for WebSphere. September Part No. 31GA-JACCAGENTWEBSPHERE-1

Java EE 6: Develop Web Applications with JSF

1Z Java EE 6 Web Component Developer Certified Expert Exam Summary Syllabus Questions

SAS Web Infrastructure Kit 1.0. Developer s Guide

Session 8. JavaBeans. Reading & Reference. Reading. Reference. Session 8 Java Beans. 2/27/2013 Robert Kelly, Head First Chapter 3 (MVC)

Migrating from IBM VisualAge to Borland 6 JBuilder

Advanced Action Classes

Extending the JavaScript Development Toolkit

Unit 5 JSP (Java Server Pages)

Laurent Guérin / V / 2009 June. ( for Telosys and + )

SECTION I: ALL ABOUT STRUTS2 FRAMEWORK 1. FUNDAMENTALS OF STRUTS AND STRUTS2...

An abstract tree stores data that is hierarchically ordered. Operations that may be performed on an abstract tree include:

JAVA MOCK TEST JAVA MOCK TEST II

What is it? CMSC 433 Programming Language Technologies and Paradigms Spring Approach 1. Disadvantage of Approach 1

CA IdentityMinder. Glossary

文字エンコーディングフィルタ 1. 更新履歴 2003/07/07 新規作成(第 0.1 版) 版 数 第 0.1 版 ページ番号 1

Java for Programmers Course (equivalent to SL 275) 36 Contact Hours

MyEclipse EJB Development Quickstart

SAP NetWeaver Scheduler for Java

JSP. Common patterns

Oracle Universal Content Management. Content Portlet Suite Developer Guide 10g Release 3 ( )

SAS Web Infrastructure Kit 1.0. Overview, Second Edition

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

CS61B Lecture #12. Today: Various odds and ends in support of abstraction.

5.1 Registration and Configuration

Java RMI. Algorithmen und Programmierung V Netzprogrammierung. Volker Roth. Wintersemester 2009/2010. Institut für Informatik Freie Universität Berlin

Frequently Asked Questions

Java Server Page (JSP)

2.6 Error, exception and event handling

JAVA - FILE CLASS. The File object represents the actual file/directory on the disk. Below given is the list of constructors to create a File object

Java TM. JavaServer Faces. Jaroslav Porubän 2008

Accessing EJB in Web applications

Developing Java EE Management Applications for Oracle WebLogic Server c (12.1.3)

Introduction to Programming Using Java (98-388)

Page 1

CSE 431S Type Checking. Washington University Spring 2013

AN ISO 9001:2008 CERTIFIED COMPANY ADVANCED. Java TRAINING.

COMP9321 Web Application Engineering

WebVisit User course

Actual4Test. Actual4test - actual test exam dumps-pass for IT exams

COMP9321 Web Application Engineering

BEAWebLogic. Server. Monitoring and Managing with the J2EE Management APIs

Basic Principles of JSPs

COMP 401 Spring 2013 Midterm 2

Vendor: SUN. Exam Code: Exam Name: Sun Certified Web Component Developer for J2EE 5. Version: Demo

Java EE Patterns. Student Guide - Volume 1. SL-500 Rev C.0.1. D61856GC10 Edition 1.0 D62465

Combining Doclets with JDBC and JSP Technologies to Deliver the Next-Generation Documentation System for the Java Platform

/* Copyright 2012 Robert C. Ilardi

Transcription:

Common-Controls Guided Tour TreeControl Version 1.0.3 - Last changed: 01. August 2004

Herausgeber: SCC Informationssysteme GmbH 64367 Mühltal Tel: +49 (0) 6151 / 13 6 31 0 Internet www.scc-gmbh.com Product Site: www.common-controls.com Copyright 2000-2003 SCC Informationssysteme GmbH. All rights reserved. Published 2003 No part of this publication may be stored in a retrieval system, transmitted, or reproduced in any way without the prior agreement and written permission of SCC Informationssysteme GmbH. Java, JavaServer Pages are registered trademarks of Sun Microsystems Windows is a registered trademark of Microsoft Corporation. Netscape is a registered trademark of Netscape Communications Corp. All other product names, marks, logos, and symbols may be trademarks or registered trademarks of their respective owners. GuidedTour TreeControl ii

Table of contents 1 Guided Tour TreeControl...1 1.1 Object...1 1.2 Registration of the Painterfactory...2 1.3 Derivation of the Action class for the Struts adapter...2 1.4 Instancing of the TreeControl...3 1.5 Provision of the display data...4 1.6 Configuration of the TreeControls within the JSP-Page...9 1.7 Tour End...10 1.8 Exkurs: Implementation of a Callback method...11 1.9 Exkurs: Use of an ImageMap...12 1.10 Alternative Layouts...13 2 Glossary...14 GuidedTour TreeControl iii

1 Guided Tour TreeControl 1.1 Object This exercise demonstrates the use of the TreeControl. This control element generates a tree whose nodes can be exploded and closed. For this, the programmer merely provides the display data (of the data model) by the implementation of a simple interface. TreeControl offers the following features: The lines at the uppermost level can be displayed or hidden. Different images can be stored in an ImageMap for the nodes and the leaves. The assignment of the images to the relevant tree nodes takes place with the help of regular expressions. The control element independently administers all the necessary status data across several Server Roundtrips. This includes, for example, the exploded or closed status of a tree node. Check boxes can be displayed or hidden before the tree entries. When selecting a node at a lower level, all the higher-level nodes are selected automatically. Figure 1: Example TreeControl Only the following steps are required for using the TreeControl: 1. Selection of the design for the user interface. 2. Creation of an action class. 3. Instancing of a TreeControl. 4. Provision of display data. 5. Configuration of the tree within the JSP-Page. Guided Tour TreeControl 1

1.2 Registration of the Painterfactory The registration of the Painterfactory takes place first. It defines which design the user interface will get. This can be done across the application in the init()-method of the Frontcontroler-Servlet. 1 Here, we select the standard design that the DefaultPainter offers us. 2 import javax.servlet.servletexception ; import org.apache.struts.action.actionservlet; import com.cc.framework.ui.painter.painterfactory; import com.cc.framework.ui.painter.def.defpainterfactory; import com.cc.framework.ui.painter.html.htmlpainterfactory; public class MyFrontController extends ActionServlet { public void init() throws ServletException { super.init(); // Register all Painter Factories with the preferred GUI-Design // In this case we use the Default-Design. PainterFactory.registerApplicationPainter ( getservletcontext (), DefPainterFactory.instance()); PainterFactory.registerApplicationPainter ( getservletcontext (), HtmlPainterFactory.instance()); 1.3 Derivation of the Action class for the Struts adapter In our tree, we want to display product groups and products. Therefore, the action class which takes care of the loading and filling of the TreeControl must have the nomenclature "ProductTreeBrowseAction". The action class is then derived from the class FWAction, which encapsulates the Struts-action class and extends with functionalities of the presentation framework. Instead of the execute()-method, the doexecute()-method is called. On calling, it gets the ActionContext, through which the access to additional objects such as the Request- Session- and Response-object is capsulated. import java.io.ioexception; import javax.servlet.servletexception; import com.cc.framework.adapter.struts.fwaction; import com.cc.framework.adapter.struts.actioncontext; public class ProductTreeBrowseAction extends FWAction { * @see com.cc.framework.adapter.struts.fwaction#doexecute(actioncontext) public void doexecute(actioncontext ctx) throws IOException, ServletException { // In the next chapter, we will instantiate // our TreeControls with the DisplayData 1 If it has to be possible for the individual user to choose between different interface designs, then additional PainterFactorys are registered in the user session. This is done mostly in the LoginAction with PainterFactory.registerSessionPainter() in the session Scope. 2 Additional designs (PainterFactories) are included in the kit of the Professional Edition, or you can develop them yourself. Guided Tour TreeControl 2

1.4 Instancing of the TreeControl Now, the TreeControl is instanced within our action and filled with the display data. The data model is assigned to the control element through the setdatamodel()-method. The method takes, as the argument, an object of type TreeGroupDataModel. What this involves is an interface which provides access to the display data of the tree. It is the job of the application developer to provide a corresponding implementation. import java.io.ioexception; import javax.servlet.servletexception; import com.cc.framework.adapter.struts.actioncontext; import com.cc.framework.adapter.struts.fwaction; import com.cc.framework.ui.control.treecontrol; public class ProductTreeBrowseAction extends FWAction { * @see com.cc.framework.adapter.struts.fwaction#doexecute(actioncontext) public void doexecute(actioncontext ctx) throws IOException, ServletException { try { // first we get the Data for our Tree ProductGroupDsp data = DBProduct.fetch(); // secondly create the TreeControl and populate it // with the Data to display TreeControl products = new TreeControl(); products.setdatamodel(data); // third put the TreeControl into the Session-Object. // Our Control is a statefull Object. ctx.session().setattribute("products", products); catch (Throwable t) { ctx.addglobalerror("error: ", t); // Display the Page with the Tree ctx.forwardtoinput(); Guided Tour TreeControl 3

1.5 Provision of the display data The tree consists of group and leaf nodes. Group nodes can, in turn have additional nodes (composite pattern). Accordingly, for both the node types, the interfaces TreeGroupDataModel and TreeNodeDataModel are available (TreeGroupDataModel extendstreenodedatamodel). With their help, the tree structure can be easily generated. In doing so, the root node is generated first and under it, additional groups or leaves are suspended. The root node is passed onto the TreeControl as a data model. // Root ProductGroupDsp root = new ProductGroupDsp("0", "Products", "Root"); ProductGroupDsp group = null; ProductGroupDsp subgroup = null; // First Group under the Root-Element group = new ProductGroupDsp("1201", "Workstations & Monitors"); subgroup = new ProductGroupDsp("2102", "Workstations"); subgroup.addchild( new ProductDsp("3005", "XWR4000", "product description")); subgroup.addchild( new ProductDsp("3005", "XWR4010", "product description")); group.addchild(subgroup); subgroup = new ProductGroupDsp("2103", "Monitors"); subgroup.addchild( new ProductDsp("3101", "ITV 2800") ); subgroup.addchild( new ProductDsp("3102", "ITV 2820i") ); subgroup.addchild( new ProductDsp("3103", "ITV 3220") ); group.addchild(subgroup); root.addchild(group); // Secound Group under the Root-Element group = new ProductGroupDsp("1204", "Printing & Multifunction"); root.addchild(group); Guided Tour TreeControl 4

The class ProductGroupDsp public class ProductGroupDsp extends ProductBaseDsp implements TreeGroupDataModel { * ParentNode private TreeGroupDataModel parent = null; * ChildNodes private Vector children = new Vector(); // ------------------------------------------------ // Methods // ------------------------------------------------ * Constructor * @param key Unique Key for the Group * @param name Name of the Group * @param unknownchildren true if the Childs should be loaded later * false if the Childnodes exists public ProductGroupDsp(String key, String name) { super(); this.key = key; this.name = name; this.type = "prodgroup"; * Constructor * @param key Unique Key for the Group * @param name Name of the Group * @param description description for the Group * @param unknownchildren true if the Childs should be loaded later * false if the Childnodes exists public ProductGroupDsp(String key, String name, String description) { super(); this.key = key; this.name = name; this.description = description; this.type = "prodgroup"; * @see TreeGroupDataModel#getChild(int) public TreeNodeDataModel getchild(int index) { return (TreeNodeDataModel) children.elementat(index); Guided Tour TreeControl 5

* @see TreeGroupDataModel#addChild(TreeNodeDataModel) public void addchild(treenodedatamodel child) { children.add(child); child.setparent(this); * Returns the Number of ChildNodes * -1 = The Number of ChildNodes is unknown. * When the Node opens an onexpandex Event is generated * and the Childs can be loaded at runtime * 0 = This Node has no ChildNodes * >0 = This Node has ChildNodes * * @see TreeGroupDataModel#size() public int size() { return children.size(); * @see TreeNodeDataModel#getParent() public TreeGroupDataModel getparent() { return parent; * @see TreeNodeDataModel#setParent(TreeGroupDataModel) public void setparent(treegroupdatamodel parent) { this.parent = parent; * @see TreeNodeDataModel#getParentKey() public String getparentkey() { return parent.getuniquekey(); * @see TreeNodeDataModel#getUniqueKey() public String getuniquekey() { return this.key; Guided Tour TreeControl 6

The class ProductDsp public class ProductDsp extends ProductBaseDsp implements TreeNodeDataModel { * ParentNode private TreeGroupDataModel parent = null; * Constructor * @param key Unique Productkey * @param name Productname public ProductDsp(String key, String name) { super(); this.key = key; this.name = name; this.type = "product"; * Constructor * @param key Unique Productkey * @param name Productname * @param description Product description public ProductDsp(String key, String name, String description) { super(); this.key = key; this.name = name; this.description = description; this.type = "product"; public void setparent(treegroupdatamodel parent) { this.parent = parent; public TreeGroupDataModel getparent() { return parent; public String getparentkey() { return parent.getuniquekey(); public String getuniquekey() { return this.key; Guided Tour TreeControl 7

The class ProductBaseDsp public class ProductBaseDsp { * ProductKey protected String key = ""; * Name of the Product protected String name = ""; * Description for the Product protected String description = ""; * Type for the Node protected String type = ""; * Constructor public ProductBaseDsp() { super(); public String getname() { return name; public String getdescription() { return description; public String gettype() { return type; Guided Tour TreeControl 8

1.6 Configuration of the TreeControls within the JSP-Page In order to use the TreeControl on a JSP page, the corresponding tag library must be declared at the start of the page. Then, the Common-Controls can be used with the prefix <ctrl:tagname/>. [In addition, the tag libraries must be included in the Deployment descriptor, the WEB-INF/web.xml file] <%@ taglib uri="/web-inf/tlds/cc-controls.tld" prefix="ctrl" %> <ctrl:tree id="prodtree1" name="products" action="sample201/productbrowse" root="true" linesatroot="true" labelproperty="name" imageproperty="type" expandmode="multiple" groupselect="true" checkboxes="false"/> All the necessary steps for using the TreeControl are thus complete. The opening and closing behavior does not have to be self-implemented. It is administered by the control element itself. This also applies to the selection states of checkboxes, which can be activated with the attribute checkboxes="true". The programmer can thus concentrate on the technical sequences and on providing the display data. Professional Edition: With the attribute runat="client", the tree is generated in a JavaScript version and and can thus be exploded and closed without Server Roundtrips. However, this increase in the user comfort does not need any changes in the application program. Guided Tour TreeControl 9

1.7 Tour End The TreeControl can be easily and quickly integrated. Its standard behavior can also be overwritten if required. Thus, it is also possible to generate special Tree- objects, which already encapsulate the access to certain technical data and can be repeatedly used within an application project. Thanks to the configuration options in the JSP-Page, the behavior of the TreeControl can be changed quickly. Alternative designs can be easily integrated by customizing the existing Painter. Parallel support to different designs is also possible. Features of the TreeControl: Implements automatic exploding and closing of nodes. Administers the state of optional checkboxes. Different configuration options (display/hiding of the root node, opening and closing behavior is modiable, connecting lines can be suppressed at the highest level). Data below a group node can also be loaded only when the group is opened. The tree does not have to be fully known right from the beginning. This is e.g. very helpful in conjunction with databases. When a node with an unknown number of children is first exploded, an onexpandex event is sent to the application. Design of the TreeControl can be defined in the JSP or also on the server side! Maps the action that is to be carried out on the tree to CallBack methods in the action class (Examples: oncheck, onexpand, oncollapse, onexpandex). Images can be assigned in front of the nodes/leaves through regular expressions. Authorization check at node level. Nodes can thus be automatically hidden from unauthorized users. (see Security Documentation). Layout through Painterfactory can be customized to own StyleGuide (Corporate Identity). Optimized HTML-Code. Same Look and Feel in Microsoft InternetExplorer > 5.x and Netscape Navigator > 7.x Guided Tour TreeControl 10

1.8 Exkurs: Implementation of a Callback method The TreeControl automatically generates an ondrilldown-event on clicking on a label, to which the programmer can react within the action class. To react to this event in our example, we include a corresponding Callback method in the ProductTreeBrowseAction. Since we do not wish to implement the business logic here, we forward the event to another action - ProductDisplayAction. import java.io.ioexception; import javax.servlet.servletexception; import com.cc.framework.adapter.struts.actioncontext; import com.cc.framework.adapter.struts.fwaction; import com.cc.framework.ui.control.controlactioncontext; import com.cc.framework.ui.control.treecontrol; import com.cc.sampleapp.common.forwards; public class ProductTreeBrowseAction extends FWAction { * @see com.cc.framework.adapter.struts.fwaction#doexecute(actioncontext) public void doexecute(actioncontext ctx) throws IOException, ServletException { try { ProductGroupDsp data = DBProduct.fetch(); TreeControl products = new TreeControl(); products.setdatamodel(data); ctx.session().setattribute("products", products); catch (Throwable t) { ctx.addglobalerror("error: ", t); // Display the Page with the Tree ctx.forwardtoinput(); // ------------------------------------------------ // Tree-Control Event Handler // ------------------------------------------------ * This Method is called when the TreeLabel is clicked * In our Example we switch to the DetailView, which shows * more Information about the node. * @param ctx ControlActionContext * @param key UniqueKey, as created in the Datamodel public void products_ondrilldown(controlactioncontext ctx, String key) { ctx.forwardbyname(forwards.drilldown, key); The name of the CallBack is composed of the Property name of the TreeControl - the name of the Bean - and the event that has occurred. Since the TreeControl was saved in the Session under the name "products", the name of the CallBack method is products_ondrilldown. Guided Tour TreeControl 11

1.9 Exkurs: Use of an ImageMap The TreeControl uses predefined images for depicting exploded and closed nodes; these images can be easily replaced if required. A separate image can be assigned to every entry within the tree. One option for this is the use of an ImagMap. The ImageMap is declared outside the tree in the JSP-Page and assigned to the TreeControl with the attribute imagemap. <%@ taglib uri="/web-inf/tlds/cc-controls.tld" prefix="ctrl" %> <%@ taglib uri="/web-inf/tlds/cc-utility.tld" prefix="util" %> <util:imagemap name="imap_products"> <util:imagemapping rule="prodgroup.open" src="images/imgboxopen.gif" width="16" height="16"/> <util:imagemapping rule="prodgroup.closed" src="images/imgboxclosed.gif" width="16" height="16"/> <util:imagemapping rule="product" src=" images/imgitem.gif" width="16" height="16"/> </util:imagemap> <ctrl:tree id="prodtree1" name="products" action="sample201/productbrowse" root="true" linesatroot="true" labelproperty="name" imageproperty="type" imagemap="imap_products" expandmode="multiple" groupselect="true" checkboxes="true"/> Working: When depicting the tree, the data model returns one expression each via the method gettype(), which is compared with the ImageMap. In case of a tally with a rule, the corresponding image is drawn. For closed and exploded nodes, these expressions are automatically extended with the suffix ".open" or ".closed", so that it is possible to use different images for different states. The rules are specified with regular expressions. The method that returns the expression for the image to be drawn is determined using the attribute imageproperty. In our example, that type-property is used, which always returns "prodgroup" for groups and "product" for individual leaves. Guided Tour TreeControl 12

1.10 Alternative Layouts Other layouts can be generated by means of the implementation and registration of own Painterfactory, as the following example shows. Guided Tour TreeControl 13

2 Glossary C CC Common-Controls Glossary 14