Toggle Menu [-]

Plugin or bean? Daddy or chocolate?

Published by admin on Friday, June 5, 2009 - 04:49:00 - Filed under Development, Plugins/beans, Servoy

I have been asked a few times lately: what is the difference between a plugin and a bean in Servoy?

Should i use one or the other? What are the advantages of one or the other?

I would like to add such and such feature, should I write a plugin? Or a bean?

How do you do that? Where do you start? Plugin or bean, plugin or bean?

It seems that people would like to understand the difference a little bit more.

OK, so here is my version of the classic dilemma: “Daddy or chocolate?”*

*The “daddy or chocolate” dilemma is coming from a story that a friend of mine told me about his daughter: The poor guy asked his 8 year old girl if she preferred daddy or chocolate. After a long period of reflexion where the little girl was repeating obsessively “daddy or chocolate? daddy or chocolate?”, she finally spitted it out: “Chocolate!”

- this just illustrates how, when you know the answer can be bad, you better not ask :))

But the answer to our dilemma is not that bad, really: it just depends on what you really want to achieve. (Now you really thought that I was going to give you the definitive answer here, didn’t you?)

Basically, you’ll need to ask yourself: does my feature has a UI, is this going to be an “element” on my form, will I need to interact with that UI, will I need to be able to set some properties on it, and give users a friendly way of setting them? If you answered yes to most of these questions, then you will end up writing a bean.

If your feature is a scriptable extension, some kind of library that will do processing of some sort, and will define a set of methods and functions, but won’t directly create a UI (or at least you don’t need end users to fiddle with some properties in the properties panel), then you are looking for a plugin.

The difference can be subtle… Look at the TreeViewBean for example, you insert it as a bean, but unless you script it, it’s not going to do much (unless you want to display a set of folders about colors, sports and food :), so it has all the features of a plugin too (in fact it does implement the IScriptObject interface).

A different example is the popupmenu plugin: you’ll find it in the “Plugins” node in the solution explorer and it won’t do a thing unless you start scripting it… but then it does create some sort of UI, either some Swing components (for the smart client), subclasses of JMenu and JMenuItem, or some Wicket components (for the smart client), basically Wicket behaviors integrating YUI (Yahoo) javascript menus.

BTW, you can see for yourself if you open the popupmenu plugin: the source code is included. I think that the Servoy engineers intended to leave the source there as example code - so kudos to them!

- except that the Servoy management staff never actually officially announced it - booh to them!

If you don’t know already, remember that .jar files are nothing else than zip archives with a .jar extension (short for Java ARchive - there are lots of these beasts in the java world, like .war for Web ARchive or .ear for Enterprise ARchive, all of them plain zip files in disguised). So you can open them up and unzip them with any compatible utility for your platform…

I’ve tried them all ;-) so to save you the trouble of opening them one after the other, here is the list of plugins with source code included (in Servoy 4.1.3):

- agent.jar

- amortization.jar

- default_validators.jar

- dialog.jar

- http.jar

- mail.jar

- pdf_output.jar

- popupmenu.jar

- rawSQL.jar

- scheduler.jar

- serialize.jar

- xmlreader.jar

Yes, that’s already a good amount of code to probe and get a little idea of how things are done “on the dark side”, take a look, it won’t byte, in fact you will see that some very powerful functions are sometimes coded with very little code (thanks to the powerful Open Source library that they are relying on).

And of course there is the servoy_jasperreports plugin which source code is downloadable on google code: http://code.google.c … asperreports-plugin/.

A note about the jasper reports plugin: it has just been updated to 3.0.0a (alpha version) by Rob Gansevles with a very important feature: the ability to pass a foundset to the plugin to use directly as a source for your report…

Alpha means that it is in its first testing phase. This also means that it’s up to every Servoy users to give it a try now and give feedback, if you want to get a reliable plugin.

Even if you don’t know it, you will need this one one day or another so take a plunge now, try it with your reports, build samples, try it in all possible environments and send bug reports and feedback.

We all need to get the best possible version of this one, with the best possible code coverage, remember that it is in your hands!

About other plugins and beans, you will find on Servoy’s site an official listing, also on the “Servoy guy” web site a fairly exhaustive list of plugins and beans and resources in general, and you will find some here too - the list will grow :)

For those of you who want more, I intend to write a series of step by step articles on how to write beans/plugins, on the Servoy Stuff site and on the java-servoy blog, so keep reading!

In the meantime, don’t forget the “Servoy developer mantra” (repeat each time you post on the forum, and every time you have contact with the Servoy management staff): please M. Servoy, could we have a decent doc, please? Please M. Aleman, could you do us a favor and answer our prayers? Please, please, please. We’ve been good, we sold users licenses, give us some candies so we can keep selling more!

I don’t know about you, but I do believe in Santa… and I still believe that my daughter loves me more than chocolate :))