Tuesday, December 29, 2009

Dynamic updates to ComboBox in Griffon

Ok, I've been trying to update a ComboBox in a Griffon app using the bind object on either items or dataModel.  I did get some success using the dataModel (if I bind to items, I get a no properties error when I try to update the model).  However, binding to the dataModel would not update the dropdown box and you had to repaint the frame to get it to display at all.

However, this works, simply set the items property to something in the View
    comboBox(items: ["Select"], id: "combo", ....

Then in the controller, remove all the items (if needed) and add the items
    view.combo.removeAllItems()
    view.combo.addItem("Combo 1")
    view.combo.addItem("Combo 2")

I'm not sure this is very Groovy, but this got me to a working version, which is what I need now.  If there is a better way, feel free to post it.  If I find a better way, I'll make another post.

Friday, October 2, 2009

New place for Programming thoughts

This blog was created to allow people who just want to read what little I have to offer the programming community, without having to deal with how I feel about politics, religion, or gluten intolerance.  If you are interested in those thinks, feel free to check out my Just Thinking blog.

I've imported the programming posts from my other blog, Just Thinking.

Friday, September 25, 2009

Griffon framework is great for quick utilities

I've been very successful this week in throwing together a quick application to read a Excel file and update a Web Service. Typically I would have done this in Groovy as a command line app. But I really wanted to put some of the information in a text field and have buttons to initiate different functions. Griffon allowed me to very quickly build a swing app.

I've not used Griffon for anything in the past. I have put together a couple of apps with Grails, but it's really not the same (close, but not the same). I've been waiting for Gorm to be ported to Griffon to use it for anything, but this project did not need any database access.

BTW, I used Poi for reading the Excel file and GroovyWS for accessing the Web Services. GroovyWS needs more work (especially in error handling), but it was sufficient for what I need to do. I covered another problem with GroovyWS here, and I dearly wish that one was fixed in the library itself.

Griffon is a Groovy-based framework for developing standalone Java applications similar to Grails. http://griffon.codehaus.org/

Grails is a Groovy-based framework for creating Web Applications. http://grails.org/

Groovy is a great programming language. http://groovy.codehaus.org/


Monday, August 17, 2009

Writing Unit-Tests for Java in Groovy: Great for Web Services

Written over at Closed Loop: Writing Unit-Tests for Java in Groovy: Not so brilliant after all?

I've been using Groovy to Unit test Web Services for several months now. Groovy WS allows me to quickly put together a Unit Test for a Web Service, saved in a text file so when I need to document my tests, I have it handy. Also, if I have to change something, I can test that change quickly.

Thursday, May 21, 2009

Complex elements in Groovy WS

I've been trying to use GroovyWS to test Web Services we are creating. Because of the way we coded the Web Services, I could not use the examples that are online, even the ones that are labeled "Complex objects".

If I used :
object.value = "value"
I would get an exception about not being able to convert the value to a javax.xml.bind.JAXBElement

I finally got to a point that I really needed to use some type of scripting language to access the Web Services, or create an entire application in Java to do it. I decided to take a good look at why I could use Groovy. Here is an example as to how I got it to work. It may not be very Groovy, so any suggestions as to how to make it more Groovy are appreciated. I hope this helps someone.

import groovyx.net.ws.WSClient

def getProxy(wsdl, classLoader) {
new WSClient(wsdl, classLoader)
}

def element(tagName, value) {
new javax.xml.bind.JAXBElement(new javax.xml.namespace.QName(tagName), value.class, value)
}

proxy = getProxy('http://localhost/ServicePort?WSDL', this.class.classLoader)
proxy.initialize()

def sampleData = proxy.create("com.sample.application.Sample")

sampleData.name = element("Name", "Item One")
sampleData.type = element("Type", "Misc");

result = proxy.store(sampleData)

println result.

Friday, January 9, 2009

Grails comes through

I am responsible for tracking the members of my local SCA group that fight (see here and here for explanations).  The previous marshal (the person responsible) had tracked the information in a Excel spreadsheet.  That's not a bad way of doing it, but come on, I'm a Java programmer.  Tracking information in a spreadsheet just isn't my way of doing things.

I had moved all the information into a MySql database.  I had been using Groovy scripts to generate the reports I needed to turn in quarterly.  The scripts would generate an html page with the report, and then I would use Mac OS X's ability to create PDF's to create something I could email in.

Recently I used Grails to create a quick front-end for editing the information.  Took all of an afternoon because I didn't like the generated pages.  (I could have had an entire CRUD application in minutes if I did like the generated pages).  I had modified the Groovy scripts to run under Grails to give me my report.  This basically involved creating a gsp page instead of a html builder.

Then I found the Jasper Plugin.  That was not completely clean to setup and the concepts of designing the pages gave me enough headaches, I almost gave up.  But I persisted and now have the ability to create the reports I need directly in PDF and Excel (and other formats if I need), although I'm still trying to create an Excel report that spans only one page, but have the PDF span multiple pages.

It only took me a few man-hours to create the whole thing.  If the objective was to allow others to use the app, I would need a few more man-hours to clean it up, but it would fine for me as is.  I will have to ask the next marshal if he wants to use this before I spend any time cleaning it up.

Once Griffon includes GORM, I intend on porting the entire application from Grails to Griffon, because I think this would be a better standalone application than a webapp.  I would like to get it to run on a USB drive, using hsqldb as the database instead of MySQL.  Then the entire application and database can be passed to the next marshal as a self-contained USB drive.

Friday, December 12, 2008

Griffon vs JavaFX

I'm looking at the difference bectween using Griffon and JavaFX to create a desktop application to keep track of information on the fighters in our Barony.  I currently have a Grails application in front of a MySQL database that I would like to migrate to a desktop app.

One of the things I really like about Grails is GORM, the builtin database interface.  Griffon does not have that yet (it's due in a future version).  I was a little surprised that there is not an equilvant technology in JavaFX.  A good object relational manager like GORM talking to HSQLDB or JavaDB would speed up Desktop programming considerably.