Apache OFBiz Cookbook Over 60 simple but incredibly effective recipes for taking control of OFBiz Ruth Hoffman BIRMINGHAM - MUMBAI Apache OFBiz Cookbook Copyright © 2010 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. First published: September 2010 Production Reference: 1020910 Published by Packt Publishing Ltd. 32 Lincoln Road Olton Birmingham, B27 6PA, UK. ISBN 978-1-847199-18-8 www.packtpub.com Cover Image by Harmeet Singh ([email protected]) Credits Author Editorial Team Leader Ruth Hoffman Mithun Sehgal Reviewers Project Team Leader Adrian Crum Ashwin Shetty Shi Jinghai Project Coordinator Acquisition Editor Joel Goveya Chaitanya Apte Proofreader Development Editor Jonathan Todd Rakesh Shejwal Graphics Technical Editor Geetanjali Sawant Vanjeet D'souza Production Coordinator Indexer Arvindkumar Gupta Hemangini Bari Cover Work Arvindkumar Gupta About the Author Ruth Hoffman is an OFBiz evangelist with over 25 years of information technology experience, including stints in software design and development, training, project management, product marketing, and software sales, She has dedicated the last few years of her eventful career to furthering the OFBiz vision. Whether it be writing about OFBiz, providing implementation and OFBiz consulting services, or just "kicking the OFBiz tires" for each new release, she enjoys working with and telling the world about all that this amazing ERP software suite has to offer. Ruth's current passion is her quest to provide high quality, cost effective OFBiz training and documentation. She has pursued this quest through multiple channels, including the OFBiz website. She invites everyone to stop by, take a gander, and give some feedback at http://www.myofbiz.com As a long-standing supporter of OFBiz, she has authored several other OFBiz titles, including OFBiz E-Commerce Out-Of-The-Box and The OFBiz Catalog Manager. For more information, please see: http://www.myofbiz.com. I would like to thank my partner, JC, for being so patient and understanding, my daughter for not getting too upset when I cancelled our planned Lilac Festival adventure, and my dog Sadie for sitting by me all those long hours when no one else would. Also, my sincerest thanks go to Adrian Crum and Shi Jinghai for their dedicated efforts in providing technical reviews of this book. Thanks for keeping me honest and setting me straight on a number of occasions. Your contributions are greatly appreciated! About the Reviewers Adrian Crum is an IT Manager/Computer programmer for a company that builds homes. Prior to that, he owned and operated a computer retail/service/consulting business. He was Technical Editor of Coast Compute Magazine, and a contributing writer for Programmer's Journal. Adrian has been involved with the Apache OFBiz project as a contributing programmer since 2004, and he is a member of the Project Management Committee. His extensive experience in many programming languages and cross-platform development has been a key part of his contributions to the Apache OFBiz project. Shi Jinghai graduated from Tsinghua University in 1991. In 2001, he took part in the China 2G Citizen Card Project and became an important system designer of the National Citizen Identity Information System of China. In 2004, he started his own company (Beijing Langhua Ltd.) focusing on IT services based on some excellent open source projects such as OFBiz, OpenCms, JBoss Portal, and Jasig CAS among others. Table of Contents Preface 1 Chapter 1: Getting Started 7 Introduction 7 Getting the project code 9 Getting code from the Subversion repository 12 Fixing IP port collision errors 14 The JAVA_HOME setting 17 "Class Not Found" errors 18 Installation verification 20 SSL verification 22 Running JUnit tests 25 Locating an OFBiz Component 26 Locating an OFBiz Application 28 Chapter 2: Java Development 31 Introduction 32 Java runtime CLASSPATH 32 Java compile time CLASSPATH 33 Naming conventions 34 Writing OFBiz Java Events 35 Writing OFBiz Java Services 39 Debugging using the logfile 42 Calling OFBiz Services from a Java program 43 Getting and validating request parameters (Events) 45 Getting and validating request parameters (Services) 47 Managing error messages 48 Using Java properties files 50 Sending e-mail from an OFBiz Event or Service 51 Handling XML files 53 Table of Contents Chapter 3: The User Interface 57 Introduction 57 Creating HTML web pages 58 Adding actions to Screen widgets 63 HTML markup in Screen widgets 65 CSS styling in Screen widgets 66 Platform-specific widgets 68 OFBiz Tree widgets 69 OFBiz Menu widgets 71 OFBiz Form widgets 72 Creating web pages using FreeMarker 74 Passing Screen widget parameters to FreeMarker 77 Calling Java methods from FreeMarker 78 Forcing FreeMarker to render HTML markup 79 Uploading files in FreeMarker forms 79 Chapter 4: OFBiz Services 83 Introduction 83 Managing existing OFBiz Services 85 Calling a Service from an HTML form 86 Calling asynchronous Services from HTML forms 89 Calling a Service many times from an HTML form 91 Creating a new Service definition file 92 Creating a new Service definition 93 Implementing Services 94 Defining Service attributes (INPUT/OUTPUT) 95 Service Event Condition Actions 96 Service groups 98 Handling Service errors 100 Writing Groovy Services 102 Mail Event Condition Actions 104 Entity Event Condition Actions 106 Chapter 5: The OFBiz Entity Engine 111 Introduction 111 Changing the default database 113 Connecting to a remote database 119 Connecting to multiple databases 120 Creating entity groups 121 Disabling automatic database checks 123 Mapping database data types 123 ii Table of Contents Creating a new entity model 126 Modifying an existing entity model 130 Building a view-entity 132 Chapter 6: OFBiz Security 137 Introduction 137 Securing communications ports 138 Disabling demonstration user accounts 141 Protecting OFBiz web pages 142 Creating user accounts 144 Protecting applications using security groups 147 Protecting views ("Tarpitting") 152 Retrieving forgotten passwords 154 Changing your password 156 Adding or changing SSL certificates 157 OFBiz single sign-on and the external login key 160 Chapter 7: WebTools 163 Introduction 163 Cache maintenance 164 Changing debug settings 167 Exporting database data to XML documents 170 Loading database(s) from XML documents 172 Managing internationalization labels 174 Using the SQL processor 176 Exploring the entity reference tool 177 Viewing OFBiz usage statistics 181 Uncovering artifact information 183 Working with temporal expressions 186 Chapter 8: Web Services 189 Introduction 189 Requesting web services using URL parameters 190 Requesting web services using an HttpClient 193 Creating HttpClients and passing XML documents 196 Creating XML-RPC web service clients 199 Becoming an XML-RPC web service provider 202 OFBiz SOAP messaging clients 204 Generating a WSDL document 212 Creating SOAP-compliant web services 215 iii
Description: