Nov
11
2008
0

SpringSource and G2One

It is pretty incredible to read this morning on groovyblogs.org that G2One, the company behind Groovy and Grails, has been aquired by SpringSource, the company behind Spring. The press release is here.

It is going to be a great fit because both companies have succeeded in changing the face of Enterprise Java. Congratulations to SpringSource and G2One.

Written by R.J. Salicco in: Commentary | Tags: , ,
Oct
19
2008
1

Editable Flex Datagrid and Grails

I have been really digging into Flex lately and I have been complimenting Flex’s incredibly nice UI capabilities with services written on Grails. I am extremely impressed with Flex and Grails really helps me get things up and running very quickly (you already know this if you are using Grails). Let’s look at a quick example of where I am using one domain class and a few simple Grails actions in a controller in order to provide search and editing capabilities to a simple Flex application based on a datagrid.

The Grails domain class, Item.groovy:

...
class Item {

        String name
        String brand
        String line
}
...

The Grails controller class ItemController.groovy:

...
class ItemController {

    def search = {
	    if(!params.max) {
        	params.max = 100
        }
        if(!params.name) {
        	params.name = ""
        }

        def itemList = Item.findAllByNameLike("$params.name%",[max:params.max])

        render(contentType:"text/xml") {
        	items {
        		for(i in itemList) {
        			item {
        				id(i.id)
        				name(i.name)
        				brand(i.brand)
        				line(i.line)
        			}
        		}
        	}
        }
    }

	def save = {
		if(params.id) {
			def item = Item.get(params.id)

			if(item) {
				item.properties = params
				if(!item.hasErrors() && item.save()) {
					render ""
				}
				else {
					render ""
				}
			}
	  	}
	}
}
...

I also added this to the conf/BootStrap.groovy so I would have some data to work with once I started up the Grails applicaiton. The code below creates 1,000 items during start-up:

...
     def init = { servletContext ->

     	(1..1000).each {
     		new Item(name: "Item $it", brand: "My Brand", line: "My Line").save()
     	}
     }
...

I mostly worked with only 1,000 items, but I increased this up to 100,000 items to put it through some tests and it worked very nicely.

Now let’s dive right into the MXML. Here is the entire itemlist.mxml file:

...
<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">

    <mx:Script>
        <![CDATA[

            import mx.controls.Alert;
            import mx.events.DataGridEvent;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.events.ResultEvent;

            [Bindable]
            private var itemId:String;

            [Bindable]
            private var itemName:String;

            [Bindable]
            private var itemBrand:String;

            [Bindable]
            private var itemLine:String;

            private function sendItemData(event:DataGridEvent):void
			{
                var myEditor:TextInput = TextInput(event.currentTarget.itemEditorInstance);
				itemName = myEditor.text;

                itemId = event.currentTarget.editedItemRenderer.data["id"];
				itemBrand = event.currentTarget.editedItemRenderer.data["brand"];
				itemLine = event.currentTarget.editedItemRenderer.data["line"];

				itemSaveService.send();
            }

			protected function filterList():void
			{
				itemSearchService.send();
			}	

			private function fault_Handler(event:FaultEvent):void
			{
				Alert.show(event.fault.message, "Could not load items.");
			}
        ]]>
    </mx:Script>

    <mx:HTTPService
        id="itemSaveService"
        method="POST"
        url="http://localhost:8080/itemlist/item/save"
  		resultFormat="e4x"
  		fault="fault_Handler(event);"
  		showBusyCursor="true">
			<mx:request xmlns="">
				<id>{itemId}</id>
				<name>{itemName}</name>
				<brand>{itemBrand}</brand>
				<line>{itemLine}</line>
			</mx:request>
  	</mx:HTTPService>

    <mx:HTTPService
        id="itemSearchService"
        method="GET"
        url="http://localhost:8080/itemlist/item/search"
  		resultFormat="e4x"
  		fault="fault_Handler(event);"
  		showBusyCursor="true">
			<mx:request xmlns="">
				<name>{searchBox.text}</name>
			</mx:request>
  	</mx:HTTPService>

    <mx:Panel title="Item List" height="100%" width="100%" paddingTop="10" paddingLeft="10" paddingRight="10">

		<mx:Label text="Search:"/><mx:TextInput id="searchBox" enter="filterList();"/>

        <mx:DataGrid id="dg" width="100%" height="50%" rowCount="5"
        	dataProvider="{itemSearchService.lastResult.item}"
        	editable="true"
			itemEditEnd="sendItemData(event);">
            <mx:columns>
            	<mx:DataGridColumn dataField="id" headerText="Id" editable="false"/>
                <mx:DataGridColumn dataField="name" headerText="Name"/>
                <mx:DataGridColumn dataField="brand" headerText="Brand" editable="false"/>
                <mx:DataGridColumn dataField="line" headerText="Line" editable="false"/>
            </mx:columns>
        </mx:DataGrid>

    </mx:Panel>
</mx:Application>
...

Now that all of the code is out on the table, we can start to dissect what is happening with the Flex UI.

When the application starts up:

Once we type in “Item ” and press enter:

When we click on a value under the “Name” column in our datagrid:

We have 2 HTTPService’s setup to send requests back to our Grails controller at http://localhost:8080/itemlist/item/save and http://localhost:8080/itemlist/item/search. The first service call will send all the item data to the ItemController’s save action and the second one will send our search box’s text to the ItemController’s search action. We have ActionScript functions that handle the “Enter” key press event on the search box and we also have a function that will be called after the datagrid field has been edited.

Most of the code is pretty self explanatory but if you have any questions, feel free to contact me. Also, Marcel Overdijk has some great posts on Grails and Flex that can really help out when you get stuck.

Written by R.J. Salicco in: Development | Tags: , ,
Oct
14
2008
0

Groovy/Grails Experience 2009?

Does anyone know where and when the Groovy/Grails Experience will be in 2009? I attended the conference in Reston, VA this year and I want to make sure that I make it out to the event next year. So as this is my pre-announcement post for this event, I would like to mention some topics or areas of interest that I would like to see at Groovy/Grails Experience 2009:

- State of Groovy/Grails:
No doubt, a must have presentation on where Groovy/Grails is now and will be going.

-  DSL’s with Groovy:
I understand the concept but how do I apply DSL’s to let’s say Enterprise Integration or Business Process Management?

- Dynamic Productivity for Java Developers:
I am reading Venkat Subramaniam’s book Programming Groovy and I want more.

- Meta Programming:
I liked what I saw at this past event, but now I would like to see it in practice. 

- Griffon:
I have heard quite a bit about it, I have it downloaded, but I haven’t had the time to dig in just yet.

That is a quick list of topics I am looking forward to learning more about. There will probably be more concepts that I will be privy to and interested in by the time the event comes along as I am learning and experimenting every week.

Written by R.J. Salicco in: Commentary | Tags: ,
Jul
10
2008
0

Groovy, Grails and JetBrains IntelliJ IDEA

I might be late in the game with this post, but I have to comment on some niceness I have experienced when working with Groovy, Grails and IntelliJ IDEA 7.0. I received a license for IntelliJ IDEA when I attended the Groovy/Grails Experience in February 2008. That ended up being a very cool event; learning from the creators and contributors and getting software to make life easier all in one weekend.

I downloaded the JetGroovy plugin using IntelliJ’s plugin manager and I was on my way. First, I created a new Grails project and ran it to see that everything was setup properly with the plugin. Everything worked as I had expected and I was up and running with my new Grails project. Instead of working with this new project from scratch, I imported my Grails POC code and started working to make some minor changes to see how IntelliJ and Grails work together. I opened up one of my domain objects and noticed that the controller, views and tests were now just a click away on the toolbar while I was looking at my domain object.

If you are already familiar with the Grails world, above is a selector with the application’s domain objects, a quick link to the controller, views and tests that correspond to the domain object selected. Very nice.

Code completion, highlighting and refactoring are other nice features supported in IntelliJ via the JetGroovy plugin that we usually take for granted in the Java IDE space. The JetGroovy plugin does a great job of exposing a new Groovy developer to an environment that most seasoned Java developers are already accustomed to. So, if you are a Java developer who is interested in learning Groovy/Grails and would like to exploit the comforts of IDE support, IntelliJ 7.0 and the JetGroovy plugin will get you started on the right path.

Written by R.J. Salicco in: Development | Tags: , ,
May
22
2008
0

Sharing My POC of Grails

I recently signed up with a Java hosting provider. I needed to put something together to prove to myself and clients that Grails would be a viable solution to create some quick custom applications. I have seen Groovy and Grails do some great things and I have written a few applications to test the technology, but I have mostly run the applications in hosted mode.

I thought that a good test would be to create a simple account/address/contact management application because that is a pretty common business application. I just kept it in line with what I have seen out there and I was guided by some requirements in my head. It is really simple, but it is definitely prettier, more intuitive, and easier to maintain than a lot of code I have seen that has taken 10x longer to build.

I spent about 8-10 hours putting it together and running it through some tests. I spent another 1-2 hours getting it deployed on my JBoss 4 server with a MySQL JNDI datasource configured and managed within JBoss. I don’t think the application will change the world, but it just confirms my belief that Grails is an incredible technology/tool set that keeps you focused on solving business problems rather than fighting technology.

url: http://www.axiomaticit.com/accountManager
email: admin@admin.com
password: admin

Written by R.J. Salicco in: Projects | Tags: ,
Apr
09
2008
0

JMX for Groovy

A friend of mine, Vladimir Vivien, has done something really cool and very useful with JMX and Groovy. He has created a Groovy JMX Builder. For those of you who are not familiar with Java Management Extensions (JMX), it is a core J2SE 5.0 feature that allows direct access to your exposed classes at runtime for monitoring and management. For those of you not familiar with Groovy, it is a dynamic scripting language that runs on the JVM and it supports Domain-Specific Languages which allow you to write more succinct code to do more with less. So if you put Groovy and JMX together you get monitoring and management of your code at runtime minus the overhead of learning all of the implementation details of the technology, like JMX. If you are writing Groovy code, you should go check it out.

Written by R.J. Salicco in: Commentary | Tags: ,

Axiomatic IT Incorporated | Aeros Theme | TheBuckmaker.com WordPress Themes