Wednesday, June 15, 2011

JRapid Quick Tip 4: Easily Send Emails in Controller Actions

It’s a common requirement to send emails when certain action is performed in a web application. For example, send an email to a customer when his order has been confirmed.

This can be implemented in a few simple steps when using JRapid. All you need to do is import the Email template, configure your JRapid application to use an available outgoing email server and add a few lines of code.

Suppose we have a basic CustomerOrder entity that registers customer orders and has a property indicating if it has been confirmed. When this property is changed to “Confirmed”, an email should be sent to the corresponding customer notifying about this.

The entity definition:

<entity label="Customer Order" menu="Menu" name="CustomerOrder">
        <property display="primary" label="Customer" name="customer"/>
        <property display="primary" label="Email" name="email"/>
        <property label="Description" name="description" type="text"/>
        <property label="Confirmed" name="confirmed" type="boolean"/>
    </entity>


We add the SMTP configuration to the jrapid.properties files. In this case I’m using a Gmail account:



Import the Email template. Click on the Add-ons -> Import Template.


Select the Email template to import it.


This templates adds the Email entity that uses the Email stereotype. This adds the necessary methods for sending the message. Read more about email stereotype here

The last step is to add the Java code to the store method of the CustomerServices class to send the email. This is a simple implementation that is by no means production ready!




Now, when a user marks a customer order as confirmed and submits the changes, the web app sends an email notifying the customer.



Tuesday, June 7, 2011

jclouds: Java Open Source Library for managing Cloud Providers

jclouds announced the release of the 1.0.0 version of their open source library that helps developers get started in the cloud and reuse Java and Clojure development skills.

Their API currently provides developers with two abstractions: compute and blobstore. Compute helps bootstrap machines in the cloud. Blobstore helps manage key-value data.

Read their original post here: http://anyweight.blogspot.com/2011/06/jclouds-100-is-out.html

Monday, May 30, 2011

Apache Libcloud Graduates as a Top-Level Project

The Apache Software Foundation announced that Apache Libcloud has graduated from the Apache Incubator as a Top-Level Project (TLP).

Apache Libcloud is an Open Source library that provides a vendor-neutral interface to cloud provider APIs written in Python and Java. With one simple API, operations teams can write once and deploy anywhere, avoiding vendor lock-in.

The current Python version of Apache Libcloud includes backend drivers for more than twenty leading providers including Amazon EC2, Rackspace Cloud, GoGrid and Linode.

The Java version supports Amazon EC2, Eucalyptus, IBM Cloud and Rackspace.

Libcloud was originally started by the Cloudkick team, but has since grown into an independent free software project and now is a TLP.

Thursday, May 19, 2011

Add Minimize Functionality to JRapid Windows Using JQuery

Web applications generated using JRapid are, by default, single page applications that open floating windows with lists and forms. This means they behave and look much like a desktop native application.

In this post I’ll show you how to add minimize functionality to these windows. We’ll trigger this by double clicking on the window title. The window will be minimized to the bottom right corner of the browser window and will be restored by a single click on the docked element.




By adding custom JavaScript in the Main.js file as explained here, we will use the delegate method provided by JQuery to bind a function to the double click event on the window title.


This code creates a container for the minimized windows if it is not already present and adds new div elements for each minimized window after hiding them. It sets the label with the title of the window and attaches another function to the click event on this element that will remove the label from the minimized windows container and set the original window as visible again.

Some custom CSS has to be added too using the Main.css file as explained here. This is to provide some nice styling to the labels, but also to place the minimized windows container at the bottom right of the browser window.

A key concept here is the use of delegate. As described in the JQuery documentation, it attaches a handler to one or more events for all elements that match the selector, now or in the future, based on a specific set of root elements. This is what allows us to attach the handler function to windows that will be opened in the future.

Our Main.js looks like this:





And the Main.css includes this code:


Wednesday, May 11, 2011

JRapid Quick Tip 3: Adding Filters to Lists

Creating user-filterable listings is both incredibly useful in professional interfaces, and a snap to do with JRapid. Filters can be added to any listing and allow the user to limit the viewable records of particular entities by any number of their properties. Lists by default have three sections, the filter which if not specified will not be included, the view section displaying the particular records, and an “actionbar” section at the bottom allowing users to page through results and displaying default buttons and often custom actions.





JRapid services will automatically be created to select your records from the database and handle pagination of the results in the actionbar. When you create a filter, it will automatically create the back-end service to limit the results based on the parameter the user enters into the filter. JRapid delivers projects that adhere to the Model-View-Controller architecture.

These filters can quickly and easily be added to any entity in your project. All you have to do is right-click on the entity and select filter. You will then see a pop-up which will let you specify a name for this filter locally in your project, a label for the filter in the user interface and at the bottom a property of the entity to link to. Each entity can have as many or as few filters as you would like, and they support displays, so you have control over the screen layout of the individual filter controls.




Allowing users to limit their own search results is normally a fairly difficult task and something that you wind up duplicating time and time. Visit JRapid, try it out for yourself, and see how easy and quick a professional application can be to produce!


Try a sample app and see how filters work here.

Tuesday, May 10, 2011

JRapid Quick Tip 2:Include JRapid forms in your public website

Using JRapid you can get your web application up and running in an incredibly short amount of time. You can define the models (entities) that represent the information your app must manage and get the necessary lists, forms and panels generated. This is what, in many applications with a public and an administration front end, is referred as the “admin”. See previous post on generating admin with reverse engineering.

What if you want to reuse one of the generated forms to let the users in the public front end enter data? You can do this very easily using the JRapid JavaScript library.

Suppose we define an entity in our project to register visitor’s messages, in other words a Contact form. The entity looks like this:

        


The next function specifies the name of a JavaScript function to execute after the form is successfully submitted. This is used to show a message to the user.

In our project we have create a public folder in the WebContent where we’ll store all of our public front end files. To simplify things we’ll just create an index.html file to include the contact form. This is how the HTML looks like:



Note the inclusion of the JRapid JavaScript libraries and the usage of the jrapid.form() function. It takes the name of the entity as a parameter and a canvas, that is the DOM element in which the form will be included. It also takes the name of the module, which is always ‘Main’ if you have only one module. The last parameter, target, takes the value “replace” to indicate that the content of the canvas must be replaced by the form.

The resulting form included in the HTML page looks like this.


And after the form is submitted, the users sees the message.



From the admin of the web app, you can access the records created from the public page.



You can also include lists using the JRapid JavaScript library, but I'll leave this for a future quick tip.

Monday, May 9, 2011

JRapid Quick Tip 1: Link Lists in Panels

Entites defined in a JRapid project generate default forms and lists to allow end users to perform CRUD operations. These are HTML files that are stored in a folder in the WebContent public directory of your application. Panels are used to tie all these files together and offer the end user a way of accessing the different lists and forms without having to type the URL into their browser’s address bar.

Panels may include a generated menu bar that provides access to every entity’s list that defines a menu attribute value. The menu options are grouped according to the value of this attribute and order alphabetically. Panels can also make use of the menu attribute so that the user may jump from one panel to another.


Take a look at the code for the Sample CRM here to see this attribute in use.

Another very useful feature of Panels is that you may embed listings or forms into them. You can include as many listings as you need and use accordions to visually stack them.


This is done by using the accordeonitem and listing elements.

And last, the main purpose of this quick tip is to show how two listings can be linked. In the CRM sample app the Customers and Opportunities listings in the Index panel are linked together. When a customer is selected in the Customers listing, the Opportunities lists only the records that belong to this customer.





You can also embed forms into your panels and link them with listings. Use the form element for this.

You may also include raw HTML in your panels. If you need a higher level of customization, you can always create your own HTML files and implement your panels as needed.


Visit JRapid, sign up and give it a try!