You are on page 1of 93

JRapid Corp. | www.jrapid.com | info@jrapid.

com

JRapid User Manual


Version 1.0Beta Revision October 2010
1. Introduction .............................................................................................................................................. 6 1.1 About this guide.................................................................................................................................. 6 Chapters summary ................................................................................................................................ 6 1.2 Overview ............................................................................................................................................. 8 Productivity ........................................................................................................................................... 9 Quality................................................................................................................................................... 9 Domain-driven design........................................................................................................................... 9 Complex applications............................................................................................................................ 9 Desktop-like interfaces ......................................................................................................................... 9 Minimum learning curve.....................................................................................................................10 Software as a Service (SaaS) applications...........................................................................................10 1.3 JRapid applications............................................................................................................................10 AJAX / Web..........................................................................................................................................10 Multitenancy.......................................................................................................................................10 Open....................................................................................................................................................11 Multi Database....................................................................................................................................11 Self Documented.................................................................................................................................11 SOA / RESTful API ................................................................................................................................11 2. Concepts..................................................................................................................................................12 2.1 Entities and Properties......................................................................................................................12 2.2 Development cycle............................................................................................................................14 2.3 User interface....................................................................................................................................14 2.3.1 Forms .........................................................................................................................................14 2.3.2 Listings........................................................................................................................................15 2.3.3 Panels .........................................................................................................................................16 2.4 Data types, enumerations and widgets ............................................................................................16 1

JRapid Corp. | www.jrapid.com | info@jrapid.com

3. JRapid web-based Designer ....................................................................................................................18 3.1 Components......................................................................................................................................18 3.1.1 Toolbar .......................................................................................................................................19 3.1.2 Perspectives: Main and Files......................................................................................................20 3.2 Generation Modes: Dirty Mode vs. Real Mode ................................................................................20 3.3 The Project Stats ...............................................................................................................................21 3.4 Validation: Syntax and semantic.......................................................................................................22 3.4.1 Syntax validation........................................................................................................................22 3.4.2 Semantic validation....................................................................................................................22 3.4.3 Keyboard Shortcuts....................................................................................................................22 3.5 Perspectives and Views.....................................................................................................................23 3.5.1 Main perspective .......................................................................................................................23 3.5.2 Files view....................................................................................................................................26 4. Basic Tutorial...........................................................................................................................................27 4.1 Creating an entity..............................................................................................................................27 4.2 Generated files..................................................................................................................................29 4.3 Entering data.....................................................................................................................................29 4.3.1 Inserting the first company........................................................................................................30 4.3.2 Inserting more companies .........................................................................................................30 4.4 Adding some useful features ............................................................................................................31 4.4.1 Data types, widgets, and basic type validation..........................................................................31 4.4.2 Validation rules ..........................................................................................................................32 4.4.3 Default values ............................................................................................................................33 4.4.4 Autosuggest ...............................................................................................................................34 4.5 Previewing the application ...............................................................................................................35 4.6 Looking ahead: connecting entities ..................................................................................................35 4.6.1 More information ......................................................................................................................35 4.6.2 Scalability ...................................................................................................................................36 5. JRapid Elements ......................................................................................................................................37

JRapid Corp. | www.jrapid.com | info@jrapid.com

5.1 Listing ................................................................................................................................................37 5.2 Condition / Restriction......................................................................................................................38 5.3 Filter ..................................................................................................................................................39 5.4 Subset................................................................................................................................................40 5.5 Action ................................................................................................................................................41 5.6 Defaultset..........................................................................................................................................42 5.7 Transient Entities: Implementing more than CRUD use cases .........................................................42 5.7.1 Use case process ........................................................................................................................43 5.7.2 Implementation .........................................................................................................................44 5.8 Embedded Listing..............................................................................................................................44 5.9 Report ............................................................................................................................................... 45 6. Intermediate Tutorial..............................................................................................................................46 6.1 Collections.........................................................................................................................................48 6.1.1 Collection properties..................................................................................................................48 6.1.2 Embedded collections................................................................................................................52 6.2 Adding filters to listings ....................................................................................................................53 6.2.1 Property filter.............................................................................................................................53 6.2.2 Other filters................................................................................................................................54 6.3 Implementing a Prizes use case (NOT FOR SHARED SERVERS)......................................................55 6.3.1 Adding elements ........................................................................................................................55 6.3.2 Implementing Java Service.........................................................................................................58 6.3.3 Running the use case .................................................................................................................59 6.4 Looking ahead: more server side programming ...............................................................................61 6.4.1 Server side validation.................................................................................................................61 6.4.2 Access level ................................................................................................................................61 6.4.3 Custom pages.............................................................................................................................61 6.4.4 Front end calculations................................................................................................................61 7. JRapid Architecture .................................................................................................................................62 7.1 Generated architecture.....................................................................................................................62

JRapid Corp. | www.jrapid.com | info@jrapid.com

7.1.1 Presentation tier: HTML + JavaScript.........................................................................................62 7.1.2 Logic tier.....................................................................................................................................63 7.1.3 Data tier .....................................................................................................................................67 7.1.4 Modifiable and read-only files ...................................................................................................68 7.1.5 Extending presentation layer.....................................................................................................68 7.1.6 Extending Java classes................................................................................................................69 7.2. Languages.........................................................................................................................................69 7.2.1 F-Path: Forms X-Path .................................................................................................................69 7.2.2 Expression Language (EL)...........................................................................................................69 7.2.3 HQL.............................................................................................................................................70 7.3 JRapid runtime library.......................................................................................................................70 7.3.1 Controller: Request processing cycle.........................................................................................70 7.3.2 RESTful web services API ...........................................................................................................71 7.3.3 Entities .......................................................................................................................................72 7.3.4 Exceptions ..................................................................................................................................72 7.3.5 Data Access Objects (DAO) ........................................................................................................73 7.3.6 Session .......................................................................................................................................74 7.3.7 Stereotypes ................................................................................................................................74 7.4. More about third party frameworks................................................................................................75 7.4.1 Hibernate ...................................................................................................................................75 7.4.2 jQuery.........................................................................................................................................75 7.4.3 Castor XML .................................................................................................................................75 7.4.4 Log4J...........................................................................................................................................76 7.4.5 Apache XMLRpc .........................................................................................................................76 8. Advanced Tutorial ...................................................................................................................................77 8.1 Writing advanced expressions ..........................................................................................................77 8.1.1 Default using EL and built-in function........................................................................................77 8.1.2 CalculatedValue .........................................................................................................................78 8.1.3. DynamicValue ...........................................................................................................................78

JRapid Corp. | www.jrapid.com | info@jrapid.com

8.2 Writing application logic ...................................................................................................................78 8.2.1 ServiceException ........................................................................................................................78 8.2.2 ConfirmationException ..............................................................................................................79 9. Add-Ons...................................................................................................................................................81 9.1 Views.................................................................................................................................................81 9.1.1 The underlying concept .............................................................................................................82 9.1.2 Using views ................................................................................................................................83 9.2 Widgets .............................................................................................................................................83 9.2.1 The underlying concept .............................................................................................................84 9.2.2 Using widgets .............................................................................................................................84 9.3 Templates..........................................................................................................................................85 9.3.1 The underlying concept .............................................................................................................85 9.3.2 Using templates .........................................................................................................................85 9.3.3 Developing templates ................................................................................................................86 9.4 Transformers.....................................................................................................................................86 9.4.1 Using Transformers....................................................................................................................87 9.4.2 Developing Transformers...........................................................................................................87 10. Reports..................................................................................................................................................88 10.1 About Jasper Reports......................................................................................................................88 10.2 Integration modes...........................................................................................................................88 10.2.1 Application ...............................................................................................................................88 10.2.2 Repository ................................................................................................................................91 10.3 Parameterized reports ....................................................................................................................93

JRapid Corp. | www.jrapid.com | info@jrapid.com

1. Introduction
The construction of AJAX web applications usually takes along unnecessary repetition of code. This happens even more frequently when the applications are based on large data models and most of the functionality is performing CRUDs. When modeling the data, some frequently repeated patterns (n-n relations, calculated fields, relations between fields) have to be coded again and again. This takes to greater developing times, greater costs, and undesired bugs. Code generation is the answer to this issue. Another fact is that every day, skills required to design, develop and maintain these applications are higher, and the variety of languages and frameworks so huge that the task turns into something unreachable. New frameworks and tools often ask the developer to spend hours setting up such a complex development environment just to see the first screen working. Easy-to-use web based development tools resolve this problem. There is also a big final barrier for developers when the deployment stage comes: the complexity of preparing server environments, the time spent publishing each version and the availability of the resulting application for final users are a considerable headache too. JRapid addresses all these currently unresolved issues in web applications: building high quality, maintainable, fault tolerant and scalable software while minimizing developing and deploying time, through an easy-to-use web base IDE.

1.1 About this guide


This reference guide is intended for Programmers Business Analysts Project leaders

And everyone who wishes to build enterprise level web applications easily, fast, but with no need of a programming background.

Chapters summary
The book is organized to help the reader learn gradually the necessary concepts and be able to jump to the platform. It is based on three main tutorials; before each one of them, the necessary background is provided to make the experience easier and totally natural.

JRapid Corp. | www.jrapid.com | info@jrapid.com

Chapter 1 introduces the platform, explaining the motivation, advantages of use and main characteristics of the resulting applications. Chapter 2 explains the basic concepts the user must understand before creating applications with JRapid. These concepts are easy and strongly related with well known ideas from Domain-drive design, Object Oriented Programming and relational databases. Chapter 3 introduces JRapid web-based Designer. The reader will understand the few steps needed to get applications running, along with the underneath code generation, compilation and publishing processes. It also describes the different toolbars, views and panels available. Chapter 4 takes the reader -from this moment on, the user- to the platform, experiencing a full development cycle for the first JRapid application, proving how easy is to design, implement and publish the creations. Chapter 5 goes a bit deeper on JRapid concepts, explaining functional patterns. These patterns are highlevel behaviors that exist in almost every application, and that were almost never seriously considered before JRapid appeared. Chapter 6 takes the user one step forward, introducing the use of functional patterns. Firstly, it drives the user to the problem and it finally suggests the mentioned patterns as a solution, also including JRapid code for implementing it. Chapter 7 describes JRapid architecture, which consists of generated file structure, Java packages, thirdparty libraries and mainly, JRapid runtime library. It finally explains the way generated application server processes requests from the interface. Understanding what happens under the hood is necessary to take full advantage of JRapid benefits. Chapter 8 advanced tutorial puts the reader in front of real world and in consequence, real applications- requirements. It teaches how to simply implement use cases, integrate reports, and many other common tasks that frequently appear when working in enterprise-level applications. Chapter 9 is about JRapid Community Chapter 10 introduces Jasper Reports integration with JRapid applications.

JRapid Corp. | www.jrapid.com | info@jrapid.com

1.2 Overview
The platform is composed of a powerful code generator JRapid CodeGen- , a web based IDE, and an innovative 'cluster of clusters' cloud hosting. JRapid CodeGen is a tool that generates Java web applications ready to be used, starting from a system model. Its core takes a definition of the desired application (as a diagram similar to an ERD), and generates all the necessary files (HTML, Java Classes, XML, SQL) to get the application running. The resulting piece of software can then be extended to add complex business logic. It can also be regenerated after customization, as it takes advantage of the inheritance OOP principle to keep generated and custom code perfectly separated.

JRapid is targeted towards AJAX web developers both advanced or newbies- aiming to build fault tolerant and scalable applications. Customers may vary among freelancers, ISVs, corporations and software factories. And for all of them JRapid has a unique value proposition. Even as revolutionary as its technology is JRapids way of use: it's consumed as a service, entering in www.jrapid.com or on behalf of many of the favorites IDE in the market -e.g. Eclipse-. One of the most important features is that JRapid is just a tool that helps developers to get their own Java web applications in a better way, and it doesnt force anybody to learn a new language nor creates dependence. Source files are yours and are easily legible and understandable. JRapid success relies on some key features of its code generator that make it unique:

JRapid Corp. | www.jrapid.com | info@jrapid.com

Productivity
JRapid CodeGen improves productivity. Applications with hundreds of tables and complex data models can be developed in a few hours with a robust architecture. In a few seconds, new fully functional screens can be added to existing applications, driving to efficient iterative development methods.

Quality
JRapid CodeGen results in quality. The applications are obtained from a generated code that has been thoroughly tested in existing applications. Resulting application consists in two big levels of code. Generated code is error-proof and its quality is guaranteed by JRapid.

Domain-driven design
Domain-driven design provides a natural way of defining systems, focusing on the domain and domain logic, instead of focusing on the specific technology. JRapid provides off-the-shelf technology, and the developer concentrates on the model that represents the complex domain.

Complex applications
JRapid allows the generation of applications with complex business logic, which means much more than simple CRUDs. Its powerful Java architecture with BPM support guarantees base technology for the development of enterprise level systems.

Desktop-like interfaces
JRapid creates AJAX/RIA applications with desktop-like interfaces. Users forget that they are working online, thanks to the revolutionary look & feel that it provides.

JRapid Corp. | www.jrapid.com | info@jrapid.com

Minimum learning curve


JRapid, through JRapid IDE, makes the task of building an application something easy for everyone. There is no need of specialization on several technologies e.g. knowing HTML, JavaScript, Java, Hibernate and SQL- to obtain complex applications. In addition to this, the learning curve is very low, and all the training is self-provided, through a wide library of documentation, tutorials and videos.

Software as a Service (SaaS) applications


Applications generated with JRapid can be commercialized under SaaS, thanks to their multitenancy support. This means that the applications can be offered with this paradigm, resulting in greater possibilities of scaling businesses, lowering the barriers of entry, and access to the market.

1.3 JRapid applications


These are some of the characteristics and benefits of JRapid applications:

AJAX / Web
The applications are AJAX web based, meaning that they don't need to be installed, are multiplatform, and can be accessed remotely. This results in benefits to the developers and the applications users.

Multitenancy
Multitenancy is an architectural principle where a single instance of software running on a server allows different clients to access their data separately. As a consequence the developer can scale while minimizing the need for resources.

10

JRapid Corp. | www.jrapid.com | info@jrapid.com

Open
The Java source code of applications is completely legible and available to the programmer. Additionally, its architecture is based on open source frameworks allowing the programmer to have at his disposal every line of code that makes up his application and giving the possibility of modifying them as needed.

Multi Database
JRapid modularity allows its applications to use any database, including open source databases (MySQL, PostgreSQL) and proprietary databases (Oracle, SQL Server, DB2, Informix, Sybase, etc).

Self Documented
JRapid is not limited to code generation; it also generates all of the system's documentation: user manuals, UML diagrams, data specifications, etc.

SOA / RESTful API


JRapid apps are strongly oriented to services architectures. They can be easily integrated through the complete RESTful API which enables third party systems to connect to the system.

11

JRapid Corp. | www.jrapid.com | info@jrapid.com

2. Concepts
In order to start using JRapid, it is necessary to understand the key concepts upon which its functioning relies: entity and property. Afterwards, these concepts are taken to the platform and the system is implemented through the development cycle, obtaining as a result a system made of multiple layers: the first visible layer is the user interface.

projects: these are the web apps the user creates. modules: modules are a single part of a project. Each module is compiled separately. entities: entities belong to a module and they represent the objects in the model. properties: properties describe the data and behavior of the entities.

2.1 Entities and Properties


An entity represents an object. In general, it could be said that entities are the nouns found in the definition of a system: products, employees, subjects, sales. According to the author or the context where it mentioned, an entity may be referred as (or treated as an analogy of) a table, a class, a form, or a file. Each entity is made up of properties. For example, the Employee entity may have firstName, lastName and birthDate as properties. Depending on the author or context, a property may be also called field, column, or attribute. 1

Note that the same convention of Java Classes and properties is used. Entities begin with capital letter; properties begin with lower case, and then camel case.

12

JRapid Corp. | www.jrapid.com | info@jrapid.com

There are different software modeling languages that work with the concepts of entity and property (or analogies). Among them are ERD and UML Class Diagrams. JRapid incorporates some of the characteristics of these modeling languages and adds some new ones needed to define behaviors, entity relations, validations and permissions, among others. Additionally, JRapid defines special transient entities that are not persistent. This concept may be used to model the verbs that define an application (i.e. creating transient entities to model SendMail, ApproveBudget or PaySalaries). There is a direct analogy between transient entities and UML use cases, EJB Session Beans, etc. The next picture shows an example of JRapid entity diagram where each box is an entity and inside the box their properties are listed.

13

JRapid Corp. | www.jrapid.com | info@jrapid.com

2.2 Development cycle


JRapid covers the whole development cycle, which includes the design stage, the implementation itself, and finally the deployment. Everything is done very simply and in a transparent way.

For the design stage, the user has visual tools such as the interactive entity diagram- for doing the system definition. Self documented windows pop up and guide the user through the creation of the different components of the application. The implementation and deployment phase, which in common apps can take days, is started by clicking the desired generation mode, in the generation menu. The implementation stage is done partially or totally by JRapid CodeGen. Deployments are also transparent. After generation Java classes are compiled, and a few seconds later, the application is automatically deployed to the development server.

2.3 User interface


The obtained application has a user interface that consists in Forms, Lists and Panels. Entities are located in the system through the lists, and then can be edited using the entitys form. Both are initially placed in windows, but can also integrated into panels. By using the window layout, applications allow the user to work in multiple tasks at the same time, just as desktop applications do.

2.3.1 Forms
An entity form includes all the visible properties defined for an entity, so it allows the user to load completely a new instance of the entity to the system, and so to edit an existing one. The properties appear in the order that they were defined, and can be organized in tabs, columns and rows. This organization becomes necessary when an entity starts having too many properties to be displayed in a single screen.

14

JRapid Corp. | www.jrapid.com | info@jrapid.com

Each property is presented according to the available widgets for its type. For example, a date property will be shown as an input box which will display a calendar when clicked or focused. Alternately, it can be shown as a set of three select boxes for day, month and year.

2.3.2 Listings
An entity listing is a screen where the instances for an entity are shown, so the user can select a specific one and take some action: edit it, delete it, use it for something, etc. For example, user selects some companies from the list and clicks in assign to salesman, which will open a user defined form where these companies already loaded. Listings use filters to adjust the results shown, helping the user to find specific stored entities. Developers can also define different layouts and views for lists. These views are the way the results are displayed: table-like, basic-HTML, big rows including pictures, matrix disposition including pictures, etc.

15

JRapid Corp. | www.jrapid.com | info@jrapid.com

2.3.3 Panels
Panels work as an integration tool for lists and forms. They provide some organization to the generated application, and convert it from a big set of windowed lists and forms to an understandable application with modules oriented by its functional meaning. For example, the developer can create a contact manager panel that gathers client, contact and appointment lists and forms.

2.4 Data types, enumerations and widgets


Each programming language defines its built-in data types. JRapid definition language is as a high-level one, and functional aspects are specially considered for its type specification. A built-in type defines 3 main characteristics:

The database type where it will be stored: bit, integer, timestamp, etc. The widget to be shown: textbox, textarea, datepicker, timepicker, etc. The front-end default validation: valid integer, valid email, valid date, etc.

Some of the most important types are: double, float, integer, long, boolean, string, text, longtext, richtext, enum, date, time, datetime, timerange, timequantity, file, password, image, email, phone, url, id.

16

JRapid Corp. | www.jrapid.com | info@jrapid.com

For example, instead of having just Strings, as Java has, there are four possibilities: string, text, longtext and richtext. The difference between them can be related to the database type that they finally rely on string uses varchar and text a CLOB or TEXT-, and so in the default widget that is shown to the user string shows an HTML input box, text an HTML textarea, and richtext a WYSIWYG editorSome built-in types use the same database type but they show completely different widgets (e.g. email, phone and password). A complete table of default database types and widgets for each JRapid built-in type is available in JRapid documentation. JRapid also includes the enumeration concept. Enumerations come in handy when some properties may adopt one or more values out of a fixed set (e.g. male / female, single / married / divorced). These are treated just as a specific type called enum; the compiler asks the developer to define the set of possible values.

17

JRapid Corp. | www.jrapid.com | info@jrapid.com

3. JRapid web-based Designer


JRapid web-based Designer (formerly JR IDE) is the most complete tool to build JRapid applications. One of its distinguishing features is that it is web based, allowing programmers to access JRapid remotely from any computer with just an internet connection. Developers can model their applications using wizards through a visual method or either programming native JRapid XML (JML) language; it allows the programmer to easily modify the generated files, manage the private cloud, deploy projects, and more. Once the developer has properly authenticated in JRapid platform and selected the project, the designer appears.

3.1 Components
The web-based designer was developed to handle the creation and development of projects. When a project is created the user can access the IDE to edit that particular project. The IDE screen has the following components: Toolbar Perspectives o Views/Panes

Edit Windows

18

JRapid Corp. | www.jrapid.com | info@jrapid.com

Each perspective is useful for some specific purpose, like generating code, or modifying the generated files. Perspectives are made of different views. Many of the views inside a perspective can be resized to suit the user's preferences by dragging its borders to the desired position, and can also be maximized double clicking its top border (then they can be restored to its original size by another double click).

3.1.1 Toolbar
JRapid toolbar links to the main tasks for each stage of JRapid development process:

Create o o o o o Create entity Create other project elements: Panel, Enumset, Report Database Reverse Engineering Import from Excel Import from CSV

Generate o o o Generate UI (User Interface) Generate All Layers Generate Docs

Manage o o o Preview application Clean Project Refresh Context

Deploy o o o Download sources Download WAR file Publish

Community o o Enter Community Site Import View / Widget / Transformer / Template

19

JRapid Corp. | www.jrapid.com | info@jrapid.com

3.1.2 Perspectives: Main and Files


Main perspective provides an environment to work in the application design. All the available views are: Project Information o o Project Modules Database Connection

Entities Tree Preview Pane Designer Pane Entity Diagram XML Source Editor Project Monitor Generation Console

Files perspective acts as a visual interface of the current file structure of the application, showing both generated and user files. All the available views are: Files tree File editor

3.2 Generation Modes: Dirty Mode vs. Real Mode


JRapid CodeGen analyzes the XML model file and creates the files that make up the application. This process can be divided in two: creating presentation layer of the application (HTML, CSS, etc) and creating the service layer (Java classes, database tables). When the user modifies the model of the application, he can choose to either generate just the presentation layer (UI or user interface- generation) or to generate everything (full generation). If the user chooses to generate only the presentation layer then he should be aware that any changes made to the data model will not be available unless the rest of the layers are generated (i.e. if a user creates a new entity with a front end generation, then he can see the created form for that entity but he can't use it to insert data in the application). If the user has chosen to only generate the presentation layer the IDE will display a message at the toolbar indicating that he is working in dirty mode, which means that the underlying layers have not been generated yet and thus the changes made may not be fully available.

20

JRapid Corp. | www.jrapid.com | info@jrapid.com

3.3 The Project Stats


Once logged in to the project, the preview panel shows some general stats about the project:

These concepts are important for keeping track of the projects size: Current/Historical Entities: All new entities that have been once created and perhaps deletedcount for the historical entities quota. Active entities that can be accessed through the Entities Tree or Entities Diagram- count as current entities. Developers: Current assigned number of developers 21

JRapid Corp. | www.jrapid.com | info@jrapid.com

Recent activity: Some stats about the recent project activity

3.4 Validation: Syntax and semantic


JRapid provides two level of validation: Syntax and semantic validation.

3.4.1 Syntax validation


Syntax (DTD) validation checks for syntax (structural) errors against JRapid DTD, and will let the user know that there was an error and mark the line where the error occurred. It is applied every time the source XML is saved. If there are errors, a confirmation popup will appear, letting the user ignore the errors and so saving changes:

However, if the user wants to generate with syntax errors, the application will not let him continue until these errors are solved. The following message appears if the user wants to run a generation:

3.4.2 Semantic validation


The semantic validation checks for JRapid programming rules: errors such as duplicate names, inexistent referred entities, errors in the relationships between the attributes of an element, etc. These errors can be ignored, but the user should know that this means a risk of getting an unstable application.

3.4.3 Keyboard Shortcuts


Files can be accessed at any time by opening the open resource window. Ctrl-Shift-R: will open the open resource window (similar to Eclipse IDE)

22

JRapid Corp. | www.jrapid.com | info@jrapid.com

When the developer works with the code, there are some shortcuts available Ctrl-space: (from editors) autocomplete suggestion Ctrl-S: (from editors) save changes

3.5 Perspectives and Views


3.5.1 Main perspective
The main view contains everything needed for the fast development of JRapid applications, and it is the default view that greets the user after a login. This view was designed for both newbies and power users; it has panels for visual development and so for advanced XML editing. Project Information: Shows the available modules and the database connections for the project. When a module is selected the rest of the perspective refreshes with the information for the module and the activation of the toolbar actions apply to this module.

Entity tree: Entities for the current module. Expanding an entity on the tree shows a list of all of its sub-elements distinguished by different icons: A click on an entity has two consequences: it refreshes the preview pane with the information for this entity, and it positions the XML source editor in the selected entity. A click on one of its sub-elements opens up a window to edit that sub-element visually.

23

JRapid Corp. | www.jrapid.com | info@jrapid.com

XML Source Editor: This panel shows the xml code of the module. This editor offers some features for easier development such as: syntax highlighting, word suggestion (activated as you type or manually with a keyboard shortcut), syntax validation and semantic validation.

Preview pane: The preview pane shows the different HTML files generated for the selected entity. These can be navigated clicking on the links at the top of the panel. The preview pane works together with the designer pane to allow the modification of the CSS style of each view. When viewing an HTML file, clicking on its different elements loads the CSS style information for that element on the designer panel. Using the designer pane the style of each element can be customized.

Entity diagram: The entity diagram offers a view of the entities and other elements of the module. The boxes in the diagram can be moved around

24

JRapid Corp. | www.jrapid.com | info@jrapid.com

Elements can be added and edited through this diagram (as with the entity tree). Entities may be created by clicking on the "New Entity" link at the top right corner. Other elements like Enumset, Panel and Report can be created from that toolbar too. When adding sub-elements, the add button inside each box can be used. A context menu will be displayed:

In the entity diagram, clicking on an existing element also opens up the property editor for editing through its Edit Window. Project Monitor : Summarizes all the logging information in a visual way, grouping by the log type:

25

JRapid Corp. | www.jrapid.com | info@jrapid.com

o o o o

Compile errors Runtime Info logs Runtime Debug logs Javascript Errors

Generation Console Displays information on generation of code. While code is generated, all the actions taken by the generator are logged to the console, and all error will show up here so that the user can debug.

3.5.2 Files view


One of the reasons that differentiate JRapid from other tools is that after generating the code for the application, it lets the user see it and modify it. The code view allows the user to modify all the files generated by the JRapid code generator, including the java entities and the html files. This view is reserved for power users that want to customize their application to great extents. Files tree: List of files generated by JRapid that are accessible to the user for modification. Clicking on a file opens it up in the editor. File editor: Online editor for modification of file contents.

26

JRapid Corp. | www.jrapid.com | info@jrapid.com

4. Basic Tutorial
Throughout this tutorial, you will learn how to create a basic company CRUD application with JRapid.

4.1 Creating an entity


Clicking on New Entity link in the button bar will open the entity editor. The entity must be named Company. This can be used for the name and label fields. Then, on the properties section of the New Entity Dialog the following properties must be entered. Company - name (display: primary) - address (type: text, display:secondary) - city - totalEmployees (type: integer) - clientSince (type: date) - industry (type: enum) As no type is specified, name property will default to string.

The IDE should show the updated views, as it follows:

27

JRapid Corp. | www.jrapid.com | info@jrapid.com

Entity Diagram and Class tree: they show Company entity, including all properties. Each property shows its JRapid type. We will click on industry property in the entity diagram- to define the enum values.

When we click in OK the form preview shows the list of industries with the recently created values.

28

JRapid Corp. | www.jrapid.com | info@jrapid.com

4.2 Generated files


As there was no all-layer generation run, the only generated files are the UI (User Interface) ones. In order to create Java classes and server side code, you should execute a complete generation. Enter Generate menu and click on Generate All Layers. Java files will be generated, compiled and deployed to the development cloud. Finally, the application context is refreshed so as to load new compiled classes. In order to check the generated files, look at the preview pane header.

You may click on each link to preview the HTML files, and select an option to check out the sources in the Files Perspective.

4.3 Entering data


Now it is time to enter data to the application. Until this point, only the screens, and no back-end code, was generated. The application is ready and working and the user can start entering data. Companies to be inserted: (Mars, 6885 Elm Street, Mc Lean, Virginia, 64400, 01/10/2008, Food Market)

29

JRapid Corp. | www.jrapid.com | info@jrapid.com

(Chrysler, 1000 Chrysler Drive, Auburn Hills MI, 60000, 01/03/2008, Car Manufacturers) (Cargill, , 152,600, 01/01/2008, Food)

4.3.1 Inserting the first company

The generated form preview panel can be used for entering data. To enter each company, the fields must be filled in and then Ok button must be pressed. Another way of accessing this form is pressing Add button in the list.

4.3.2 Inserting more companies


From the list preview panel, click on Add to open the Company form and enter

Now the list shows:

30

JRapid Corp. | www.jrapid.com | info@jrapid.com

Click on the column header to order the list alphabetically. Click again to do a descendent ordering.

4.4 Adding some useful features


As you can see, the generated form contains some built-in features according to the entity definition we made before.

4.4.1 Data types, widgets, and basic type validation


For example, it offers a datepicker widget for date input:

However, default widgets can be overridden. JRapids Date type offers an alternative widget called selectdate. Open Edit Property window to change it.

31

JRapid Corp. | www.jrapid.com | info@jrapid.com

As totalEmployees was entered as an integer, JRapid provides a basic client side type validation that will prevent the user to enter non-integer values.

4.4.2 Validation rules


The system should not allow entering a company without specifying its name, but should not cause any trouble if the loaded company doesnt have the number of employees. Simple validation rules exist for this task, and then should be used. To set a property as required, open Edit Property window and check Required

32

JRapid Corp. | www.jrapid.com | info@jrapid.com

There are simple client-side validations that can be done without posting information to the server. These validations are expressed in FPath language, as all the information available is already at the clients browser. So we will add a validation for totalEmployees property, asking that this should be zero or positive. This value should be entered in Client Conditionals tab, Check if field.

Note that we created an OR validation (FPATH language), so we admit the null value. Otherwise, the form would appear in red when opened and that does not look nice (You may try it by yourself leaving only the positive condition) As a result, when opening the form and trying to save with no name, or entering a negative value, we get a client-side validation error.

4.4.3 Default values


We could think that almost every time the form is used for inserting a new Company, the clientSince property will be filled with todays date. So, clientSince property should be defaulted to todays date. To set a property as required, open Edit Property window, go to Value tab, and set default to now. The EL used for the default value entered includes a system variable or reserved word- named now. This variable is an alias of the current date and time, and applies for date and datetime properties. There are more system variables, like userId, that contains the users id, if it is logged.

33

JRapid Corp. | www.jrapid.com | info@jrapid.com

After submitting the form, we need to regenerate all layers. The reason is that default values come from server side (They are expressed as ELs). We could open the web service that feeds this form to check that the changes applied to the server side.

4.4.4 Autosuggest
Finally, we will tune up the city field of our Company form, by setting the autosuggest feature. Autosuggest is triggered when filling the field, and provides a list of similar values already entered in the database, helping the end user to enter values just as other users entered before.

34

JRapid Corp. | www.jrapid.com | info@jrapid.com

Again, as this change requires new server-side code, we need a generation of all layers.

4.5 Previewing the application


While in real mode, the application can be previewed accessing: http://yourserver.jrapid.com/yourapp This URL can be accessed from any place connected to internet. The only restriction is the authentication that it requires, which will be the current username and password.

4.6 Looking ahead: connecting entities


At this point, the user has successfully programmed the first JRapid application. It is moment of analyzing results, identifying advantages and disadvantages. The tutorial suggests a very simple application, which carries too many limitations if used in a real-world enterprise-level application.

4.6.1 More information


There is a field called number of employees, but that information could be improved letting the user entering the information of those employees. It would be interesting too, to have this information properly related.

35

JRapid Corp. | www.jrapid.com | info@jrapid.com

4.6.2 Scalability
With the current definition, the data is a little difficult to find. Considering the case of having 10.000 companies instead of 3, the only way of finding a company would be to order the list and start navigating the pages. In case of having a name filter, this task would be much simpler.

36

JRapid Corp. | www.jrapid.com | info@jrapid.com

5. JRapid Elements
Although Entity, Property and Panel are the main building blocks, there are other elements that help the developer in the road to building a successful JRapid Application: Listing, Subset, Filter, Action, Defaultset, Transient Entities, Embedded Listing, Report

5.1 Listing
Listings are the way of showing the existing instances of an entity in the database. They provide access to the whole dataset also allowing filtering, ordering and action execution on each instance. Each entity has an auto-generated listing, but its possible to create additional listings indicating what elements to display and how to display them. Each entity may have more than one listing.

37

JRapid Corp. | www.jrapid.com | info@jrapid.com

Depending on the user that accesses the system, the information listed by the system should vary. The developer may need to define different group of properties to be shown (projection) as columns, depending, for instance, on the users role. For example, a user from sales department wants to see the client account status in the search results, but perhaps a marketing user prefers to have the address and phone at first-sight. This can be achieved creating custom listings for each user role. Listings selection rules can be predefined (using Subsets) and specified at runtime (using Filters). Both Filters and Subsets rely on conditions to define the way they select the information. JRapids IDE Edit Listing window includes: Name: name of the listing. Subset: subset used. View: type of view (table, thumbnails, icons). Display properties: overrides default displayable properties (must be included in subsets definition). Display filters: overrides default displayable filters.

5.2 Condition / Restriction


JRapid includes Conditions and Restrictions, which limit the domain of values returned by a query to the system (selection). Both concepts are an abstraction of SQL/HQL where clause. They will be used when defining filters and subsets, as explained in the following sections. A Condition is just be a set of pair of property-name/value, like (firstName,John) which means firstname=John, and also can include a modification flag (defined by JRapid DAO interface), like Greater-or-Equal, Less-than, etc. (startDate,2008-12-01,GE). A restriction is used when the complexity is even higher, accepting HQL code.

38

JRapid Corp. | www.jrapid.com | info@jrapid.com

Conditions and Restrictions can be combined, creating new Conditions. Combination is achieved with logic operators (AND, OR).

SQL WHERE firstName = John WHERE startDate >= 2008-12-01 WHERE city = San Francisco OR city = Los Angeles WHERE EXISTS (SELECT * FROM Employee WHERE Employee.company = id)

Condition / Restriction Condition(firstName,John) Condition(startDate,2008-12-01,DAO.GE) Or (Condition(city,San Franscisco) , Condition(city,Los Angeles) ) Restriction(EXISTS FROM Employee WHERE Employee.company.id = me.id)

5.3 Filter
Filters let end users specify restrictions to listings (selection). They provide all the necessary programming structure (UI elements, server side code and web services). Filters work as the most important tool when searching for data. They can be combined to create specific queries and access in a few seconds to the desired information. Simplest filters are defined specifying the property which they restrict. More advanced filters can be obtained combining conditions and restrictions. JRapids IDE Edit Filter window includes: Name: filters name Mode: (auto or basic/advanced/mixed) o o o o Auto: a property-filter is set, requiring property name and flag used Basic: generates conditions Advanced: generates restrictions Mixed: generates both conditions and restrictions

39

JRapid Corp. | www.jrapid.com | info@jrapid.com

5.4 Subset
A subset is a restricted collection of instances (records) of an entity. The selection can be parameterized using Conditions and Restrictions. Each subset will provide an associated web service that will include only the specified instances showing specified properties. When showing the available information of the system, developers usually need to filter some way the instances shown. For example, when displaying employees of a company in a select box, it is not desired to display all the historic database of former employees, listing only the active ones. This can be achieved by defining a subset with a condition (active,true), and providing a name (onlyActive). Then, when referring to Employee entity, subset onlyActive can be specified. JRapids IDE Edit Subset window includes: Name: subsets name Mode: (basic/advanced/mixed) o o o Basic: generates conditions Advanced: generates restrictions Mixed: generates both conditions and restrictions

40

JRapid Corp. | www.jrapid.com | info@jrapid.com

5.5 Action
Actions link entities and properties to elements of the system: other entities, listings, JavaScript calls, reports, etc. Action (and its multiple uses) is the key element that distinguishes a JRapid application from a plain database web interface, by connecting screens with some level of intelligence. Actions can be of three types: JRapids IDE Edit Action window includes: Javascript: calls a custom javascript function sending information of the selected instance (row) as a parameter. The programmed function always receives the ID of the selected entity/s as the first parameter. Related-entity: opens another entitys form sending the selected instance as a parameter. The related entity must define a Defaultset expecting this parameter. Report: opens a Report sending information of the selected instance.

JRapids IDE Edit Action window includes: Name: actions name Type: (javascript/relatedentity/report) Location: (button/select/local/form) o o o o Button: button in the button bar of listings Select: select box in the button bar of listings Local: located inside views of listings Form: located in the button bar of forms

41

JRapid Corp. | www.jrapid.com | info@jrapid.com

5.6 Defaultset
Defaultsets assign a set of default values when creating an entity. They can be parameterized, so becoming some sort of "dynamic initializers" of entities. Developers find out that they need to define, for a specific entity, default values for each property. So when the application user wants to add a new instance of that entity to the system, these properties appear with a default value (e.g. when creating a new client company, set the current date as the default client company association date). JRapids IDE Edit Defaultset window includes: Name: defaultsets name Parameters: (optional) objects received that will then be used in expression for values Values: fixed or dynamic values (EL) to be set each time the entity is opened through the defaultset

5.7 Transient Entities: Implementing more than CRUD use cases


JRapid offers a simple way of taking generic use cases to the application. Generally, a use case involves inputs, outputs, preconditions, post conditions, and needs an interface to be executed by the appropriate actor. All these elements are provided automatically when using transient entities.

42

JRapid Corp. | www.jrapid.com | info@jrapid.com

5.7.1 Use case process


The suggested process for implementing a use case requirement with JRapid applications is as follows: There will be a process, consisting in three main stages: The first stage happens in the server, before showing the transient entity form. Preconditions must be calculated, and information that should be provided to the actor must be retrieved and prepared. In the client-side second stage, the form opens showing the initial data, and the actor interacts doing the input. When the actor finishes filling in the form, the validation is done and the information sent. Finally, the server receives the submitted form and processes it, and then calculates post conditions, thus completing the use case.

Having this abstraction, most complex use cases can be resolved by composition implementing simpler ones.

43

JRapid Corp. | www.jrapid.com | info@jrapid.com

5.7.2 Implementation
Although the architecture was still not properly presented, it will be enough by now to say that each transient entity will have a service class called EntityNameServices.java where find() and store() methods can be found. Find() method is called before the form is shown, and the object returned is the one which feeds the contents of the screen. When the form is submitted, the values are mapped to a Value Object class, and this is received as a parameter by store() method. These two simple methods provide the communications between the front and back end and allow the developer to complete the process described in the previous section. For example, transient entities can be used for selecting parameters of complex processes to be started. Another typical case is that of critical or massive updates: a transient entity with a collection of entities to be updated is shown, asking for confirmation before committing changes.

5.8 Embedded Listing


Listings can be embedded inside forms of any entity using Embedded Listings. Listings based on subsets are commonly used, where the container (parent) entity filters the results. JRapids IDE Edit Embedded Listing window includes: Entity: Entity to which the listing belongs Name: embedded listings name Listing: Listing of the child entity to import Subset: Subset used by the listing selected Defaultset: Defaultset to use when adding new child entity instances from the embedded listing.

44

JRapid Corp. | www.jrapid.com | info@jrapid.com

5.9 Report
Reports help JRapid developers including Jasper Report files, generating the connection to the applications database and an associated web service for easy access. Usually an action is used to open the report and send any parameters the report needs. JRapids IDE Edit Report window includes: Name: reports name Location: o o Application: jasper file will be uploaded in the application file structure Repository: jasper file will be uploaded to the files repository

File: File name (relative to application or repository root)

45

JRapid Corp. | www.jrapid.com | info@jrapid.com

6. Intermediate Tutorial
This tutorial is intended for giving users a first real contact with the concepts described in the previous chapter, and how easy it is to implement them with JRapid. Before starting, a preliminary step. Lets create 2 new entities: Employee and Industry Employee - firstName (display: primary) - lastName (display:primary) - company (type: Company) - gender (type: enum) We have to pay attention in the creation of this entity:

Company will not be of built-in type and it will be of entity-type. Type/Entity list shows all built-in types followed by the entities of the system. Gender will be of type enum. However, we will create a reusable Enumset and reference it. After creating the Entity, Click on Add Enumset button.

46

JRapid Corp. | www.jrapid.com | info@jrapid.com

Finally, open gender property and point to the recently created Enumset.

Industry - name (display: primary) - description (type: text) Now the application has 3 entities and looks a little bit like this:

47

JRapid Corp. | www.jrapid.com | info@jrapid.com

6.1 Collections
JRapid allows definition of collection properties for multi-valued attributes of an Entity.

6.1.1 Collection properties


We will start by changing our application by saying that a company can belong to different industries at a time. These Industries should be manageable by users of the system. Clearly, a fixed enum-type property (as we formerly had) is not the best choice. So, what we need to do is to convert industry property to a Collection of Industries (which now is an entity). The type of relation created here is a many-to-many collection, as a company can belong to several industries and an industry is referenced by many companies. This kind of relations can also be seen as strong, as the industries are meant to exist no matter if the companies that reference them survive or not. Lets start by loading some industries:

48

JRapid Corp. | www.jrapid.com | info@jrapid.com

Now we remove the industry property from entity and create a new one called industries.

The form now appears with a new box that will hold all the industries:

We can apply a CSS style to set a fixed width to this box. If you click on the box inside the preview panel, youll find that in the designer pane, the elements ID appears in a select box as all the parent elements.

49

JRapid Corp. | www.jrapid.com | info@jrapid.com

Enter width: 145px and youll see how the form changes its appearance

Now you can edit the companies you have and add industries. Use Add link and double click Industries in the pop-up window. Enter the following industries for each of our 3 Companies:

50

JRapid Corp. | www.jrapid.com | info@jrapid.com

51

JRapid Corp. | www.jrapid.com | info@jrapid.com

6.1.2 Embedded collections


Another type of collection is called embedded collection. In this case the term embedded is directly related to the User Interface (in fact it embeds the collection within the form), but also means that the child entity deserves to exist only in the context of the parent entity. Add a new property to Company named employees, which will be an embedded inline collection. Indicate company as the child property (the property in the child entity that connects the relation). You need to indicate that this collection will be extendable. Otherwise, no new rows can be added.

A little more make up changes: edit the new property and indicate position: fieldset.

So we can start entering employees from the Company form.

When we check the Employees listing, we see the employees created from the Company form.

52

JRapid Corp. | www.jrapid.com | info@jrapid.com

6.2 Adding filters to listings


In the conclusions of the basic tutorial an important limitation was presented: What will happen when there are too many companies listed so as to find them visually? Filters need to be added to shorten the time that takes getting to a specific searched entry.

6.2.1 Property filter


The simplest filter that can be imagined for Company entity is through the name property. Click on add Filter inside the Company box.

The Edit Filter window will pop up. Leave default mode (auto). Select name property. Selecting no flag will create a Begins-with filter.

53

JRapid Corp. | www.jrapid.com | info@jrapid.com

After generating all layers, we can test the filter in the preview pane, choosing List in company.

6.2.2 Other filters


Add a new filter, selecting basic mode. This will ask to enter conditions. Define 1 condition pointing to industries property, with contains operator. Value field can contain any EL, where you can use the name of the filter as the variable that holds the current value. In this case enter the simplest expression: industryFilter.

If you enter all the industries as suggested before, you can try this filter out and test the different results. For example, if you enter Food you get the 2 companies in Food industry. If you enter Candies, you get just the only one related.

54

JRapid Corp. | www.jrapid.com | info@jrapid.com

You may also combine filters, specifying criteria for 2 filters at a same time:

6.3 Implementing a Prizes use case (NOT FOR SHARED SERVERS2)


We will start by adding an entity named Prize, which will hold prizes to be given to companies.

6.3.1 Adding elements


These prizes will increase the value of a new property named points.

We create a new entity named Prize with properties: name and points (integer and required).

Shared servers do not allow manual edition of files. This section applies to projects created in dedicated servers. If moving from a shared server, you can copy-and-paste the source XML to migrate the application.

55

JRapid Corp. | www.jrapid.com | info@jrapid.com

And we enter 3 prizes: Gold: adds 30 points Silver: adds 20 points Bronze: adds 10 points

We want to add a new Transient Entity named AwardAPrize and an Action button named awardAPrize to the Company listing that will open the entitys form. We use a transient entity because we just need the UI form and the skeleton in the server where to insert our custom programming.

56

JRapid Corp. | www.jrapid.com | info@jrapid.com

We need to create a Defaultset for this entity that will receive a company as a parameter

And finally the Action that connects the listing with the transient entity

57

JRapid Corp. | www.jrapid.com | info@jrapid.com

If we generate all layers, we can select companies and click in the button

6.3.2 Implementing Java Service


We are now missing the step where we must tell our app the logic to be applied when submitting. Whenever the Award a Prize form is submitted, the selected Company should be modified, incrementing its points by the value indicated in the prize. The time has come when we need to enter some Java code. Choose AwardAPrizeServices.java from the preview pane.

58

JRapid Corp. | www.jrapid.com | info@jrapid.com

And override method storeForCompany like this:

The Java Code means that we get objects from database (Through DAO layer) and we increase the company points by the amount indicated in the selected prize. As the find method of Companys DAO returns a persistent object, we dont need to call the store method.

6.3.3 Running the use case


Now we choose a company from the list, we select a Prize, click OK and we go to the company form to see how it was updated to the new value.

59

JRapid Corp. | www.jrapid.com | info@jrapid.com

After finishing this tutorial, lets review some of the concepts we applied in this section: An Action of related entity type was added A Transient entity was added A Defaultset for this entity was defined Java Code was entered through the files view

We strongly encourage the user to have a look at the generated Java method (for example, AwardAPrizeAbstract.java, findForCompany method) to get a better understanding of how the design decisions affect the underlying code.

60

JRapid Corp. | www.jrapid.com | info@jrapid.com

6.4 Looking ahead: more server side programming


After finishing the intermediate tutorial, the user has discovered many of the most important JRapid features, and could start thinking about developing their own applications right now. However, there are still some doubts and some situations that havent been handled, and that are still quite common in enterprise-level applications: they are related to complex validation procedures, information provision depending on access level, custom pages development public sites- and calculations done at front-end screens.

6.4.1 Server side validation


Until this point, the validations done were client side validations, as they were executed in the browser (with just the downloaded data available). But many times it is necessary to manage a broader scope of information, which can only be found in the applications server. For example, when adding a new Company, it should be checked if there is no other company already loaded with similar name, warning the user in consequence.

6.4.2 Access level


In the generated application, all the information loaded is available for every user accessing it. It should be restricted through some authentication system, and it should also be filtered according to the permissions given to the authenticated user.

6.4.3 Custom pages


Most web applications need to be integrated with another site, of public access. The whole ERP of a Company could be a JRapid application, and a specific module could need to give access to external actors, like for example providers or clients, to enter information. Generally, this public-access site needs to have a corporative look & feel or structure that could differ from that of standard JRapid applications. Sometimes, JRapid applications just work as private CMS (Content Management System) for public web sites. JRapid allows the developer to easily create integrated web sites that access the information managed by JRapid applications.

6.4.4 Front end calculations


When programming specific forms where fields are related by formulas and logic business rules, it is interesting to have some kind of help to avoid doing complicated programming in browser scripting languages, such as JavaScript. JRapid integrates front-end and back-end expression languages transparently allowing definition of calculated values, expressions, formulas, etc. With all these elements, development of complex numeric forms (such as invoices) turns trivial.

61

JRapid Corp. | www.jrapid.com | info@jrapid.com

7. JRapid Architecture 7.1 Generated architecture


Applications generated with JRapid have a multi-tier architecture, based upon popular open source frameworks such as Hibernate, Castor XML, Jasper Reports, HTMLi, etc. Presentation layer includes HTMLi files. Logic tiers are basically Java files, organized in packages. For each entity, beans, services, persistence and XML marshalling files are created.

7.1.1 Presentation tier: HTML + JavaScript


Presentation tier includes HTML files. Each form and list (See 2.3 User interface) is generated as an HTML file. For example, for an entity named Company, JRapid will create Company_form.html and Company_list.html files. This approach results in zero-footprint and no need of extra components downloading. All JRapid apps also include jQuery3 library by default. This library comes in handy to extend behavior of HTML interfaces and also when including jQuery add-ons, as a prerequisite.

See http://jquery.com/ for more information about jQuery

62

JRapid Corp. | www.jrapid.com | info@jrapid.com

JRapid includes a JavaScript runtime library which handles all the user interaction: makes all AJAX requests and handles all responses too. It provides all the necessary programming that make JRapid apps run smoothly.

7.1.2 Logic tier


Java files are organized in packages. Apart from Java source files, packages include definition files required by third party frameworks, such as .hbm.xml Hibernate files and xml marshalling files for Castor framework.

- Entities: Java Beans that include all defined properties as getter/setters to access them. For Industry entity, the resulting class Industry.java will be:

package com.basic.entities; public class Industry extends IndustryAbstract } {

And IndustryAbstract.java will be:


/* AUTO GENERATED FILE: DO NOT EDIT!!! EDIT Industry.java INSTEAD! */ package com.basic.entities; import ; /** * */

63

JRapid Corp. | www.jrapid.com | info@jrapid.com

public abstract class IndustryAbstract extends com.jrapid.entities.Entity {

private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } public static DAO<Industry> DAO() { return MainDAOLocator.get().getIndustryDAO(); } @Override protected com.prodasoftware.prd.dao.DAO<? extends Entity> myDAO() { return Industry.DAO(); } @Override public String toString() { StringBuffer buf = new StringBuffer(); buf.append(name + " "); return buf.toString(); } }

- Services: Service classes provide methods for managing entities such as find(), store() and remove(). They have also methods that return collections, implementing default listing services, subsets, etc. Most of their methods are mapped to REST web services. For Industry entity, the resulting class IndustryServices.java will be:
package com.basic.services; public class IndustryServices extends IndustryServicesAbstract { }

And IndustryServicesAbstract will be:

64

JRapid Corp. | www.jrapid.com | info@jrapid.com

package com.basic.services; import ; public abstract class IndustryServicesAbstract extends com.prodasoftware.prd.services.Services { public Boolean remove(String id) { } public Boolean removeMany(Collection<String> ids) { } public Industry find(String id) throws ELException { } public Long store(String id, Industry voobj) { } public Collection<Industry> findPage(String storedFilter, String page, String pattern, String order) { } protected interface ListFilter { public List<Restriction> getRestrictions(DAO<Industry> dao, String param); } }

- XML (Castor files): Files needed for marshalling / unmarshalling Java objects to XML files returned by web services and vice versa. The contents of these files determine which properties from the Java files will be included in the XML results and the way they will be shown and formatted. Different handlers are defined according to each propertys data type. These handlers are helper classes included in JRapid runtime library. For Industry entity, the resulting file IndustryFull.xml will be:

<?xml version="1.0" encoding="UTF-8"?> <mapping xmlns:str="http://exslt.org/strings" xmlns:exsl="http://exslt.org/common"> <class name="com.prodasoftware.prd.entities.Entity"> <field name="id" type="long">

65

JRapid Corp. | www.jrapid.com | info@jrapid.com

<bind-xml name="id" node="attribute"/> </field> </class> <class name="com.basic.entities.Industry"> <field type="long" name="id"> <bind-xml node="attribute" name="id"/> </field> <field type="string" name="name" handler="com...castor.StringHandler"/> </class> </mapping>

- DAO (Hibernate files): Files used by Hibernate framework to accomplish Java objects persistence. Object types and relations are present here, and the mapped database table and column names. For Industry entity, the resulting file Industry.hbm.xml will be:

<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.basic.entities"> <class lazy="true" table="industry" name="Industry"> <id type="long" name="id"> <generator class="native"/> </id> <property type="string" column="name" name="name"/> </class> </hibernate-mapping>

- Controller: Includes the application main controller class. Users should work with this class when customizing the application adding new services through code. For an application consisting in just an entity named Industry, the resulting MainController.java file will be:
package com.basic.controller; import ; public class MainController extends MainControllerAbstract { @Override public void init(ServletConfig config) throws ServletException { super.init(config);

66

JRapid Corp. | www.jrapid.com | info@jrapid.com

FilterManager.registerFilter(Filter.BEGIN, new HibernateBeginFilter()); FilterManager.registerFilter(Filter.COMMIT, new HibernateCommitFilter()); FilterManager.registerFilter(Filter.ROLLBACK, new HibernateRollbackFilter()); } }

Which extends MainControllerAbstract.


package com.basic.controller; import ;

public class MainControllerAbstract extends FrontController { @Override public void init(ServletConfig config) throws ServletException { super.init(config); this.init(this); } @Override protected void init(FrontController controller) { controller.registerXmlRpcService(IndustryServices.class, "removeMany", "Industry.remove"); controller.registerXmlService(GET, "/Industry(?:)?", IndustryServices.class, "findPage", "com/basic/xml/default.xml"); controller.registerXmlService(POST, /Industry/(\\d+),validate", IndustryServices.class, "validate", "com/basic/xml/IndustryFull.xml"); controller.registerXmlService(GET, "/Industry/(\\d+)", IndustryServices.class, "find", "com/basic/xml/IndustryFull.xml"); controller.registerXmlService(POST, "/Industry/(\\d+)", IndustryServices.class, "store", "com/basic/xml/IndustryFull.xml"); } }

7.1.3 Data tier


For default online JRapid versions, data tier is implemented through MySQL database engine. However, developers can define their own connections to any commercial engine that supports JDBC.

67

JRapid Corp. | www.jrapid.com | info@jrapid.com

7.1.4 Modifiable and read-only files


JRapid CodeGen is well known to be not just a one-time code generator, but a tool that can be used repeatedly at any time of the development cycle, including the maintenance stage. This fact carries along the challenge of letting the developer customize the code but also keeping this customization when re-generating. There are two kinds of file generation: One-time generation, for modifiable files (modifiable by the user). Every-time generation, for read-only files (the user doesnt change them).

Once modifiable files are generated, they will never be overwritten again by the generator. Users can work on them, adding custom code. On the contrary, read-only files are generated each time and any changes made by the developer in them will be lost. For each layer, JRapid has a different approach. Presentation files: Forms and Lists HTMLs are overwritten on each generation. Server files: For server classes, JRapid Codegen takes advantage of OOP inheritance principle to keep two sets of classes: modifiable and read-only. Users will work on modifiable classes, overriding methods from super classes (named as *Abstract.java).

As a summary, the file structure can be divided as:

7.1.5 Extending presentation layer


You can access www.jrapid.com and find plenty of examples about extending presentation layer behaviour using jQuery.

68

JRapid Corp. | www.jrapid.com | info@jrapid.com

7.1.6 Extending Java classes


Users with Java programming knowledge can add behaviour by editing Java modifiable classes. It is common to have needs of manually programming business functionalities, as not everything in an application is structured. There are some typical situations in JRapid where a developer decides to create new classes, or to extend existing ones. Creating new packages and classes or including libraries, in general. Overriding generated methods from service classes and bean (Entity) classes. Adding Java Server Pages (JSP) to the application Scheduling processes to run periodically in the background

And so many other tasks, as the language allow infinite possibilities.

7.2. Languages
It often becomes necessary to write expressions in JRapid tags to indicate behavior. To define these expressions three different languages are used depending on the context: FPath EL HQL

7.2.1 F-Path: Forms X-Path


FPath is an XPath based language that is used in JRapid to navigate through the data in the displayed forms. For example, if I'm looking at a form of a Person and I want to access the age field, I may do this by using the expression age. If I want to see the postal code of the address I can use the expression address.zipCode. Else, if I want to know the amount of phone numbers that the form holds, I may use the expression count(phone).

<property name="totalPrice" calculated="sum(sale.lines[*].price)" /> <property name="finalPrice" calculated="totalPrice * 1.21" /> <property name="product" entity="Product" subset="forPriceList" subsetparams="priceList" />

7.2.2 Expression Language (EL)


EL is an expression language used in the JSTL standard that JRapid uses to resolve complex expression between entities of the same application. Unlike FPath, EL resolves the expressions getting the information from the database, while FPath has only access to the information on the displayed forms. For example, to access the last name of the contact with id=7 we could write Person(7).lastName.

69

JRapid Corp. | www.jrapid.com | info@jrapid.com

<property name="state" default="DefaultParams:find(1).defaultState" /> <subset name="forContact"> <subsetparam name="contact" entity="Contact" /> <condition field="company" value="contact.company" /> </subset>

The functions find(), findOneBy(), findManyBy() and findAll() are available to be used in EL expressions.

<property name="companies" default="Company:findAll()" /> <property name="type" default="Params:find(1).defaultType" /> <property name="companies" default="Company:findManyBy('user','paul')" />

7.2.3 HQL
HQL is a SQL based language used by Hibernate to make queries on the database.

7.3 JRapid runtime library


JRapid runtime library is, as its name suggests, the core library that makes JRapid applications work. It contains a set of classes that manage the integration of third-party frameworks, providing the unique multi-tier architecture. It can be found in WEB-INF/lib directory of JRapid applications. It is licensed so as to be freely distributed inside JRapid applications.

7.3.1 Controller: Request processing cycle


JRapid applications are web based, so they do all the server-side work in limited periods of time that start when an HTTP request is received and end when they return an HTTP response with the results. During this cycle, all changes are considered to be inside the same Hibernate transaction, so if anything fails, they will be rollbacked and the underlying database will not be affected at all. All the requests are processed by a Controller class, which will identify the desired service and invoke it with the proper input information obtained from the request. These services are classified depending on their nature, so there are different servers that take care of them:

70

JRapid Corp. | www.jrapid.com | info@jrapid.com

XML server: Handles entity services that accept or return an object, and in consequence, a marshaled xml. Some common services with these characteristics are the Entity/find services (return the instance as an XML) or the Entity/store services (receive the instance to store). XMLRpc server: Handles services that accept or return simple or void values, like an entity primary key. Examples of these services are the deletion services, where all the information needed is the key of that or those entities. Repository server: Handles the file management needs of applications. Automates the storing and retrieving of files (documents, pictures, etc.) uploaded to the server through file/image-type properties.

7.3.2 RESTful web services API


The controller provides a RESTful web services API, so as to let the HTMLi presentation layer access the back-end of the application. Developers can also program custom presentation layers in any platform compatible with web services calling (e.g. .Net, Macromedia Flash). Assuming that there is a JRapid application running at http://localhost/myapp, services can be accessed through the following URLs: http://localhost/myapp/xml/* for XML Services http://localhost/myapp/xmlrpc/* for XMLRpc Services http://localhost/myapp/upload/* for Upload Services

Services are registered in the controller class when it is initialized, stored in a services map, and then, when a request arrives, they are retrieved from there through its URL. JRapid CodeGen will register automatic services to feed the presentation layer lists and forms. These services return collections -for the lists- and single objects for the forms-. For an application consisting of an entity called Company, MainControllerAbstract.java will contain these lines in the init() method:

71

JRapid Corp. | www.jrapid.com | info@jrapid.com

The first service registered feeds the opening of a form. The regular expression just expects a number (the entity id), passing it to find() method in CompanyServices.class services class, and finally return the results marshaled through com/myapp/xml/CompanyFull.xml Castor mapping file. The next service feeds the list. The complexity of the regular expression is due to the different parameters needed when preparing data for a list (e.g. filtering, ordering, paging). All URLs matching the regular expression included will invoke findPage() method of CompanyServices.class services class, sending the matching groups as params, and finally return the results marshaled through com/myapp/xml/default.xml Castor mapping file. It also registers services that listen for POST requests, for the action of storing an entity, and receive the XML describing it as a part of the POST packet. When the developer works from Java, XML is never seen, as it properly marshals and unmarshals in the beginning and the end of the transaction, in a transparent way.

Attention When posting an entity from a form, an XML is sent to the server, including only the information that is available at the presentation layer. That is why generated store() method as a parameter named Value Object. Many developers get confused when inspecting this object because they not find deep information. Surely, if it represents a stored instance, they need to retrieve it from the database using the included primary key, and consider the information of the V.O. as the modified presentation layer updates.

7.3.3 Entities
The most important class in JRapid architecture, as it is the super class for all generated entities, is included in the runtime library. Entity: Entity class defines some general behavior methods for all entity beans, such as getId(), store() and remove(). It also overrides equals(), hashCode() and compareTo() methods to simplify the programming task defining that two entity objects are equal when their primary key is equal.

7.3.4 Exceptions
There are also Exception classes used to communicate easily exception messages to the presentation layer. JRapid provides the structure necessary to communicate this kind of exceptions to the end user and filters internal or unexpected exceptions caused by errors in the programming.

72

JRapid Corp. | www.jrapid.com | info@jrapid.com

ServiceException: Intended to inform exceptions that appear when applying business rules. For example, when validating inserted entities, when attempting to take unauthorized actions, etc. Because of their exception nature, they interrupt the transaction, so no changes are saved when they are thrown. ConfirmationException: They have a special behavior as, although they interrupt the transaction, they ask a confirmation from the end user, starting again another request including the answer. By managing a confirmations map, the code flow can take a different path, changing the result of the transaction. A very common example of use is the confirmation of storing entities where suspicious information was found.

7.3.5 Data Access Objects (DAO)


Data Access Object package provides method definitions for getting objects from the database, store and delete them. It also includes some helper classes very handy when defining advanced criteria for queries and database updates. JRapid includes an implementation for Hibernate framework of this interface, called HibernateDAO, which translates method invocations to HQL queries. DAOs for each entities are then obtained by calling:

EntityName.DAO()

This obtains the corresponding DAO from a generated DAO Locator class.

DAO Interface: It includes read-only methods, that return collections and single instances of entities: FindAll(), FindById(), FindByIds(), FindManyBy(), FindOneBy(), findAdvanced(), etc. It also includes some methods for counting like in a SQL count() query-instances that fulfill a criteria. Finally, it has write methods as store() and remove(). Some of these methods use the concept of restriction Order: Order class is used in DAO advanced methods, when there is a need of specifying the order of the retrieved records.

73

JRapid Corp. | www.jrapid.com | info@jrapid.com

Filter: Use filters to indicate restrictions to your queries done through DAO interface.

Attention Find methods return Hibernate persistent classes (See Hibernate manual chapter 4). This means that when you do changes to these objects (for instance, you use setters of properties), this changes will be persisted, even though you never call store() method of the Entity class.

7.3.6 Session
Runtime library contains a core class named Session that encapsulates information related to the user currents session: current Locale and current JRapids application user id if logged-. It is especially important in SaaS oriented applications, as it also stores the specific schema where the user is logged in. Finally, it also provides the current HTTPSession. It includes also some formatting methods that automatically get the current locale. These are very useful when formatting dates and numbers for users coming from different countries where they have different conventions. Usually, Session class is used for getting the HTTPSession (and then taking some action with it, as storing an object).
Session.getMySession().getHttpSession()

The logged-in user id can be queried with the following statement:


Session.getMySession().getUserId()

7.3.7 Stereotypes
After developing several applications it becomes clear that certain entities with specific behaviors are used repeatedly. Such is the case of entities created to manage users and their privileges and email management. JRapid provides stereotypes, which special of entities, to help the developer in the construction of these entities and to set a standard way to handle them. If you specify an entity to be of a stereotype, the generated readonly entity (*Abstract.java) will inherit from a superclass which implements methods that the developer will surely need for custom programming. For example, Email stereotype provides a send() method in its Entity superclass; User Services superclass provides login() and logout() methods. (See JRapid Server Library Reference for full specification).

74

JRapid Corp. | www.jrapid.com | info@jrapid.com

The developer may indicate that an entity implements stereotypes with the stereotype attribute of the entity element:

<entity name="AppUser" label="Application User" stereotype="User"> ... </entity>

When an entity sets a stereotype, it must include all the properties needed for the functionality of that stereotype. If it doesn't follow the predefined template the developer will be warned about the missing properties. The entity may add extra properties besides the required ones to fulfill the stereotype template. This feature is not exposed to the user in recent versions. If you are new to JRapid and want to integrate Email and User Management, use Template add-ons instead.

7.4. More about third party frameworks


7.4.1 Hibernate
Hibernate is an object/relational persistence and query service. It allows expressing queries in its own portable SQL extension (HQL), as well as in native SQL, or with an object oriented Criteria and Example API.

Home page: http://www.hibernate.org/

7.4.2 jQuery
jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development.

Home page: http:// jquery.com/

7.4.3 Castor XML


Castor XML is an XML marshalling framework. As its site declares:

75

JRapid Corp. | www.jrapid.com | info@jrapid.com

Castor XML is an XML databinding framework It can marshal almost any bean-like Java Object to and from XML. In most cases the marshalling framework uses a set of ClassDescriptors and FieldDescriptors to describe how an Object should be marshalled and unmarshalled from XML For those not familiar with the terms "marshal" and "unmarshal", it's simply the act of converting a stream (sequence of bytes) of data to and from an Object. The act of marshalling consists of converting an Object to a stream, and unmarshalling from a stream to an Object.

Home page: http://www.castor.org/

7.4.4 Log4J
Log4J is a logging service. It equips the developer with detailed context for application failures. It helps testing, and so provides quality assurance and confidence in the developed applications.

Home page: http://logging.apache.org/log4j/

7.4.5 Apache XMLRpc


As defined in its home page, Apache XML-RPC is a Java implementation of XML-RPC, a popular protocol that uses XML over HTTP to implement remote procedure calls.

Home page: http://ws.apache.org/xmlrpc/

76

JRapid Corp. | www.jrapid.com | info@jrapid.com

8. Advanced Tutorial
In the final tutorial some of JRapid boundaries will be explored and the advanced tools will be presented. Then, it is expected that, with the help of JRapid spec and real-world needs, the reader will go on using and discovering the platform and the infinite possibilities that it provides.

8.1 Writing advanced expressions


Advanced expressions appear as the way of solving complicated situations without coding. They are expressed in a declarative way, joining members that are in the end properties of the system and constants- with logical and algebraic connectors.

8.1.1 Default using EL and built-in function


Add a new entity called DefaultValues where system parameters will be stored. This entity will have generally one entry in the database, and will be useful for hard-coding business parameters

Enter the unique entry for this entity, with value 3000

Open salary property from Employee entity and go to default field. Enter the following expression.

77

JRapid Corp. | www.jrapid.com | info@jrapid.com

This expression is an EL expression. It references defaultSalary of the object returned by the function DefaultValues:find(1)

When created the default in chapter 6, fixed 3000 value was used, take it from default in employees company. Explain Company:find().

8.1.2 CalculatedValue
In JRapid site http://www.jrapid.com you will find lots of articles about calculated values.

8.1.3. DynamicValue
In JRapid site http://www.jrapid.com you will find lots of articles about dynamic values.

8.2 Writing application logic


The following step will be to do some advanced server side validations. When saving a new company, the application will check that there are no existing companies with the same name of the one entered.

8.2.1 ServiceException
Edit CompanyServices.java, overriding store() method, so it throws a ServiceException, that will be passed through to the interface and shown as an alert box:

78

JRapid Corp. | www.jrapid.com | info@jrapid.com

So when a company with an existing name is entered, the user will receive the message:

8.2.2 ConfirmationException
This is perhaps more restrictive that the desired behaviour, supposing that maybe the system should allow more than two companies with the same name that differ in the address (for example two branches of the same big company). In this case, instead of throwing a service exception, it should throw a confirmation exception, which will open a confirm box instead of an alert box.

79

JRapid Corp. | www.jrapid.com | info@jrapid.com

This time, when the user tries to save, it will be given the chance to go on anyway or abort.

80

JRapid Corp. | www.jrapid.com | info@jrapid.com

9. Add-Ons
JRapid users can create their own elements and share them at JRapid community site. There are 4 main types of add-ons in this kind of "free market place": Views, Widgets, Templates and Transformers.

9.1 Views

Views are new choices for displaying listings in JRapid applications. JRapid offers (between the built-in features) only 2 kinds of listings named table and thumbnails. For example, if a given Entity defines a property named address, it would be interesting to have a listing which presents the results of a search inside a map. Another case that appears frequently is having an Entity defining a date -e.g. date of an event- and the need of showing the results in a calendar.

81

JRapid Corp. | www.jrapid.com | info@jrapid.com

Some views, using jQuery Calendar, Google Maps and Google Charts.

9.1.1 The underlying concept


Views are used inside listings. Listings are composed visually by 3 sections: filters, view and actionbar. filters section contains all the specified filters, and is by default placed on top of the view. view section displays results in a certain way. The default view is called table: results are shown as a double entry table, with the defined properties as columns. Each row is a valid result of the query. actionbar section includes paging toolbar, custom actions and system default actions (which are the add action and the remove action).

Both the filters and the actionbar sections modify the results shown in the view actionbar, as they define user parameters that restrict the query. These parameters could be filter definitions, a page selection (e.g., results from the 51st to the 100th) or just the addition or removal of an existing record. Defining a new listing view is just replacing the view section with a custom one, where results are presented in a specific way.

82

JRapid Corp. | www.jrapid.com | info@jrapid.com

9.1.2 Using views


In order to add a community view, open Community menu and select Import View. The following window will open:

Once you choose the view to import, click on Import. If you look at the Entity Diagram, you will find the view inside the configuration box. This means that you will have the view available for any of your listings. Create or edit a listing and you will see the recently added view as an option. Views can also add required JavaScript libraries to the project. They are copied to the project structure and automatically added to the configuration box.

9.2 Widgets

Widgets are new options for offering easy data input/presentation in JRapid application forms. JRapid offers a number of built-in form widgets: input boxes, checkbox, radiobutton, textarea, etc. They generally map to standard HTML elements. Some widgets like selectdate and the default image and file widgets are composites of standard HTMLs.

83

JRapid Corp. | www.jrapid.com | info@jrapid.com

The web is full of great widget frameworks that offer a variety of mechanisms for entering information in user-friendly ways: Rich text editors, spinners, calculator widgets, masked inputs, password strengthners, etc. JRapid developers may include these widgets in their apps through widgets. Widgets act as some kind of connector that allow replacing the HTML part that would normally correspond to a property with arbitrary contents, defined by the widget. Widgets can also add required JavaScript libraries to the project. They are copied to the project structure and automatically added to the configuration box.

9.2.1 The underlying concept


When a JRapid form is created, widgets for each defined visible property are used, that altogether will provide the user interface for data input.

9.2.2 Using widgets


In order to add a community widget, open Community menu and select Import Widget. The following window will open:

Once you choose the widget to import, click on Import. If you look at the Entity Diagram, you will find the widget inside the config box. This means that you will have the widget available for any of your properties or filters. Create or edit a property and you will see the recently added widget as an option.

84

JRapid Corp. | www.jrapid.com | info@jrapid.com

9.3 Templates

Templates are Entity definitions that the user can simply add to each application. After adding a template, JRapid users can customize them. They turn out to be helpful when implementing common application patterns, for example User Management, Audit, Email administration, etc.

9.3.1 The underlying concept


Templates are quite a simple tool. They are Entities that can be added to the current entities and so be easily integrated as any of the other user-created ones.

9.3.2 Using templates


In order to add a community template, open Community menu and select Import Template. The following window will open:

85

JRapid Corp. | www.jrapid.com | info@jrapid.com

Once you choose the template to import, click on Import. If you look at the Entity Diagram, you will find the recently imported entities that compose the template

9.3.3 Developing templates


Anyone can define a template by taking a piece of source XML -containing entities, panels, enumsets, etc- with a well-defined meaning. An easy way of starting would be having a look at the sample templates gallery.

9.4 Transformers

Transformers are the way all developers can take advantage of the powerful code generator provided by JRapid. A transformer is a XSL transformation that will be applied to JRapid source.

86

JRapid Corp. | www.jrapid.com | info@jrapid.com

Any type of text file can be generated: HTML pages, Java files, XML, etc. For example, the community site provides transformers for generating UML diagrams, JUnit classes, HTML help files, etc. There are 2 kinds of transformers: all entities transformers and single entity transformers. UML diagram transformer creates a single file containing a class diagram with all the entities of the application. JUnit class transformer creates a single JUnit for each entity, and places them in the java sources folder of the web application.

9.4.1 Using Transformers


In order to add a community transformer, open Community menu and select Import Transformer. The following window will open:

Once you choose the transformer to import, click on Import. After this, each time an full (all-layers) generation is run, the transformer will be applied and the files, overwritten.

9.4.2 Developing Transformers


Transformers are defined through a XSL template considering that the whole source XML is received (in case of all-entities transformers, and in a single call). In case of creating a for-each-entity transformer, it will be called N times, receiving the current entity as another parameter. An easy way of starting is to have a look at the sample transformers in JRapid community site.

87

JRapid Corp. | www.jrapid.com | info@jrapid.com

10. Reports
JRapid provides integration with reporting tools. Initially, it allows developers to easily include reports designed for Jasper Reports. These reports can be fully parameterized through JRapid generated screens. This feature is much stronger when developing SaaS applications, because it allows managing a model where reports are deployed for each tenant.

10.1 About Jasper Reports


JasperReports is an open source Java reporting tool that can write to screen, to a printer or into PDF, HTML, Microsoft Excel, RTF, ODT, Comma-separated values and XML files. It can handle scriptlets in the report definition, subreports, and multiple datasources merging.

Home page: http://jasperforge.org/

10.2 Integration modes


Reports can be integrated in two main different ways: As application reports, and dynamically deploying them in the repository. When developing multi-tenant SaaS applications (a single instance of software serving multiple client organizations tenants-) it becomes necessary to identify the features that are common to all tenants from those who are specific for each one, and different integration models appear for each one of these cases.

10.2.1 Application
When working in single-tenant applications, with a limited scope of reports, application reports are the best option in seek of quick inclusion and easiness of administration. The way of deploying these reports is copying the compiled .jasper4 file to the web application. The most simple method is just adding a new folder reports/ in WEB-INF directory and saving the file there. Finally, committing changes in that folder through SVN will put the file in the server. Example After creating a report called companies with the report design tool, showing two fields (name and address) from a record set that is the result of bringing all the companies of the database.

Compiled .jasper files can be obtained using open source tools like iReport (http://ireport.sf.net)

88

JRapid Corp. | www.jrapid.com | info@jrapid.com

The resulting source code (companies.jrxml) is:

<?xml version="1.0" encoding="UTF-8"?> <jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="report name" pageWidth="595" pageHeight="842" columnWidth="535" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20"> <queryString> <![CDATA[select c.name, c.address from company c]]> </queryString> <field name="name" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="address" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <background> <band/> </background> <title> <band height="35"> <staticText> <reportElement x="50" y="0" width="151" height="20"/> <textElement> <font size="14" isBold="true" isItalic="true" isUnderline="false"/> </textElement> <text><![CDATA[Companies report]]></text> </staticText> </band> </title> <pageHeader> <band/> </pageHeader> <columnHeader> <band height="24">

89

JRapid Corp. | www.jrapid.com | info@jrapid.com

<staticText> <reportElement x="84" y="0" width="100" height="20"/> <textElement> <font isBold="true" isItalic="true"/> </textElement> <text><![CDATA[Name]]></text> </staticText> <staticText> <reportElement x="184" y="0" width="298" height="20"/> <textElement> <font isBold="true" isItalic="true"/> </textElement> <text><![CDATA[Address]]></text> </staticText> </band> </columnHeader> <detail> <band height="33"> <textField hyperlinkType="None"> <reportElement x="84" y="8" width="100" height="20"/> <textElement/> <textFieldExpression class="java.lang.String"> <![CDATA[$F{name}]]> </textFieldExpression> </textField> <textField hyperlinkType="None"> <reportElement x="184" y="8" width="298" height="20"/> <textElement/> <textFieldExpression class="java.lang.String"> <![CDATA[$F{address}]]> </textFieldExpression> </textField> </band> </detail> <columnFooter> <band/> </columnFooter> <pageFooter> <band/> </pageFooter> <summary> <band/> </summary> </jasperReport>

The report can be previewed from the development tool with the datasource of the tutorial of chapters 4,6 and 8, resulting in:

90

JRapid Corp. | www.jrapid.com | info@jrapid.com

In order to include the report inside the tutorial application, the compiled companies.jasper file must be uploaded. If WEB-INF is chosen as the containing folder, when adding the report through New > Report this folder should be specified. The following pop-up will appear.

The entity diagram will show:

Since this moment, the report can be accessed through the URL

http://SERVER_NAME.jrapid.com/APP_NAME/report/REPORT_NAME

Although this mode allows including reports really quickly, it is quite limited as the reports must be deployed by the developers of the system (new versions of the jasper file must be put in the same folders as the code) and also there is only one version of the report for all tenants (for all schemas of the application).

10.2.2 Repository
When there is a need for a custom version of reports for each schema, or it is just necessary letting the administrator to upload new versions, the repository integration mode turns useful. The way of activating this integration mode is choosing location = repository in the edit report window.

91

JRapid Corp. | www.jrapid.com | info@jrapid.com

After defining the jasper name, it can be uploaded for each repository. This means that it can have a design that varies for each tenant. If the application is sold as a service (SaaS) for 2 clients, and each one wants a custom design for the company list, these custom designs can be kept inside each ones own repository. So, in a multi-tenant application, there can be two different designs coexisting inside the application, as they are uploaded for each schema: Client 1 Schema. Client 1 has 3 companies in the database and a black & white design that just shows name & address (companies1.jasper in client 1 repository).

Client 2 Schema. Client 2 has 2 companies in the database, and uses a colorful design (companies2.jasper in client 2 repository).

92

JRapid Corp. | www.jrapid.com | info@jrapid.com

10.3 Parameterized reports


Reports need to be parameterized to make them really useful. The trick is using a transient entity together with the Next element. In the previous example, the report could receive a minimum amount of employees filter named fromEmployees

<entity name="GetCompanyReportParams" label="Companies report parameters" transient="transient"> <property name="fromEmployees" label="From Employees" type="integer"/> <next report="AllCompanies"/> </entity

So the resulting parameters window should look like any other transient entity, with the difference that when it is submitted, the values are converted to report parameters and they are sent automatically.

93

You might also like