Vaadin – the platform of choice for Notes developers – JavaScripts, Agents and DEMO – IV. part

In the first part of our series I’ve focused on overall reasons why we’ve chosen Vaadin as a next development platform for our future applications. The second part shows how to navigate and work with views and in the third part we went through variety of form components. Today we set the attention to Java Script components, agents and access rights. At the end is a link to our simple demo in Vaadin.

JavaScript Components

As mentioned earlier programming in Vaadin means that everything is done in Java on the server. There is no need to write HTML, Javascripts, call Ajax. The code in Java can interact with client side, so your code can have a function which gets a document from the database, then displays confirmation message box to the user, wait on his decision and processed with the backend operations. To do this in standard web application (in Xpages for example) you need to involve not only backend classes like Java or PHP, but also Javascripts and Ajax calls.

But there are a bunch of very useful Javascript libraries out there, which would be very nice to use in Vaadin applications. For example Full Calendar, Google charts, Canvas3D and others. Good news is, that there is a way how to do this. Here is detailed description. Basically you need to connect client-side with server-site in both directions:

·        RPC calls from client to server

·        Shared state and RPC from server to client

We did it, for example to Full Calendar. Java code fetches the events from the database and send it to Full Calendar for the display. On the other hand, when clicking on the day in Full calendar, user fires the request which is captured by Java and that displays the event dialog form draw by Vaadin. In the same way you can implement whatever JavaScript library into your application.

Image:Vaadin - the platform of choice for Notes developers - JavaScripts, Agents and DEMO - IV. part

Agents

The basic concept of agents is to run the task at specific time and interval and do some job. In Notes we used agents for that. The similar functionality you can achieve by scheduled component in Vaadin. It is a class in Java again with the code which is doing what we want. The schedule is set up very easily by annotation @Scheduled followed by time and interval. It can be fixed rate every x milliseconds or you can set up the time schedule by well know cron syntax. See examples here:

@Scheduled(fixedRate = 1*60*60*1000, initialDelay=30)

@Scheduled(cron =”0 4 * * * ?”)

Image:Vaadin - the platform of choice for Notes developers - JavaScripts, Agents and DEMO - IV. part

Access rights

That is the most challenging part when you come from Notes environment because the system does not do it for you. You have to include access rights to the application logic. But Notes experience are very handy here. We’ve implemented those rules:

1.        Every document has multivalued fields “authors” and “readers”.

2.        Those fields are computed on each save and are based on the application logic. Sometimes we need to put there an author, sometime an approver etc. The same is in Notes.

3.        Every request to the database to display the view, open document for reading or viewing, checks users credentials against “authors” and “readers” field. Fortunately that can be written in the basic class which is inherited to every single part, so it cannot be forgotten somewhere.

4.        User’s credentials consist of login ID, his roles and groups set by admin in administration part of the application. Similar to Notes.

That seems to be quite difficult to maintain ACL but in fact, it is not. Due to centralized classes taking care about access, it is works quite straightforward. Actually it brings some benefits as well, because as a designer you can allow the user to write to the document which he can’t normally edit. For instance you need to set a new status of the document depended on user’s action (approval, comments). In Notes you need to solve that situation by agent with higher rights, because there is no other way to do this.

Image:Vaadin - the platform of choice for Notes developers - JavaScripts, Agents and DEMO - IV. part
Image:Vaadin - the platform of choice for Notes developers - JavaScripts, Agents and DEMO - IV. part

Demo version

To see a glimpse of the application in Vaadin, go to our demo page and login with john.hill@demo.com, password: demo. It is not designed to catch all possible errors but I think that it is enough to get a flavour of applications in Vaadin.  

Posted in: