Wednesday, April 30, 2008

Java 1.6 on OSX

I love my Mac even more today...Java SE 6 version 1.6.0_05 has finally been released (as if you hadn't already heard).  This is great news for any Mac Java developer!
Just remember, if you had installed a beta version of 1.6 then you will have to manually remove /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0 before you can get the update via Software Update.

Tuesday, April 29, 2008

Netbeans 6.1 - Out of the Box

I really haven't gotten too far into it yet, but I've just installed Netbeans 6.1 final edition.  So far, I can say that the start up time seems good, and I am glad that all of my libraries were migrated out-of-the-box.  I simply used the import prompt to grab all of my settings from 6.1 and I was good to go.  This is great news...it means that I can just start using Netbeans 6.1 with no additional configuration overhead.  

That's all for now...I'm looking forward to using another great product from the Netbeans team!

Wednesday, April 23, 2008

Grails - Coding and Accessing a simple custom controller method

If you've ever worked with Grails, then you know how easy it is to create domain classes which map to database tables. Similarly, it is easy to access the database via the automatically generated conroller methods that are available (create, list, delete, save, edit, show). However, if you need to perform a particular operation against the database which is not accomplished by using any of these automatically generated methods, it is still easy...but perhaps not very intuative. Once you learn how to accomplish this task then the entire power behind using hibernate and accessing your database is at your hands.

It really is as easy as 1, 2, 3 to create additional controller methods...especially if you know how to use the Groovy language itself. I will show you how to create a simple finder method which takes a parameter and searches a particular database table for the value of that parameter...then it returns the results.

As you already know, the list method for each Grails controller is already created for you...let's look at my list method for the "Test" domain class (database table):

def list = {

if(!params.max) params.max = 10
[ testList: Test.list( params) ]
}


This is all well and good, but it returns the entire dataset for the Test database table. What if I only wish to return all of the records which have foreign key id of 35? Let's say that our foreign key id variable is fkId to make it simple. So what we want is to return all members of the list returned using the "list" method above which have fkId == 35.

We need to first obtain the complete list of results, and then filter it out accordingly. This is where the power of Groovy comes into play. We could use Java and write a filter so that we iterate through each of the items in the complete list of results searching for instances where fkId == 35 and then adding those matching objects to another list. That would be lots of code though. Let's use a Groovy closure to accomplish the same thing. Take a look at the "find" method which does just that:

def find = {
def testList = Test.list( params)
[testSearch : testList.findAll{it.fkId == Integer.valueOf(params.fkId)}]

}

Ok, simplicity at it's finest! We first obtain the complete list from the database table into the testList object. Then, we use the Groovy "findAll" method to search that list for all instances where fkId == the value of our parameter which is passed in (params.fkId)...let's assume that the parameter equals 35. We store our results in the testSearch list.

Now, how do we access this method? Well, we have to create a Groovy Server Page named find.gsp to show our results. We also need to pass the fkId parameter to this method somehow. Here is a simple find.gsp which will iterate through all of the objects which are returned within the testSearch list.  Of course...this is just a quick page with ugly results...but you can clean it up to suit your needs.

find.gsp:

<g:each in="${testSearch}" status="i" var="test">
   FieldOne:  ${test.fieldOne}
   FieldTwo: ${test.fieldTwo}
</g:each>

Now, what is the URL which we use in order to access our new controller and page?  Assume that our application name is "site" and we are passing a parameter of fkId = 35...

http://localhost:8080/site/test/find?fkId=35

Easy enough, but it took me a bit of time to figure out when I first tried it.  Hopefully this post will save you some time and get you adding some much needed functionality to your standard Grails app.



Friday, April 18, 2008

Groovy - Grails Work

Onto new stuff...I have been working a lot with Grails lately. This is the technology that I have chosen to use for the implementation of the gathereventplanning.com website. While Grails is easy to use out of the box, I have found myself searching the net for information regarding customization. No doubt about it, unless you are creating your own simple CRUD application, you will want to customize the program in one way or another.

There have been many articles and blogs written about creating Grails applications and customizing them, but perhaps one of the best I have found so far is the Mastering Grails series...it has been quite helpful thus far.

I'm not going to get too technical in this brief post, but I will say that I have found a bug already. The issue resides in the Grails 1.0.2 release. I had created and customized a tiny CRUD application for testing purposes using the embedded database that comes with Grails. All was good until I attempted to "hook" my program to a PostgreSQL database instead. At that point the application was in read-only mode as it was unable to perform any batch inserts or updates to the database. Each time I tried to insert or update data, I received a stack trace stating that there was a SQL Grammar error.

I scratched my head for days on this one, looked at lots of hibernate documenation (since this is used behind the scenes in Grails), and even tried to change my domain model a bit to see if that would work. Eventually, I ended up downloading Grails 1.0.1 and trying to do the same thing. It works perfectly...no issues as yet. I have been able to successfully re-create my small application and use a PostgreSQL database without issues.

My guess is that this will be resolved with Grails 1.0.3 release, but we will see. So far, I love Grails as it is quite powerful and easy to use. Other than the bug I found, the only complaint I have is that Grails is so involved...many plug-ins are available and the Grails documentation is huge as it is. If you really want to become an expert Grails developer, you will be doing a lot of studying...but learning new technology like this is fun stuff.

Monday, April 14, 2008

Netbeans 6.1 Beta - Subtle Issues

I've been using Netbeans 6.1 beta for most of my development since it has become available. Until recently, I hadn't noticed any issues while using it. Late last week I think I've encountered a subtle, but time consuming issue.

I am in the process of migrating my Seam applications from 1.x to 2.0.1 at this time. In doing so, I am also adjusting libraries within Netbeans as necessary. As you may know, when moving from older versions of Seam you must update all JSF pages to comply with JSF 1.2 standards...so these libraries must be updated as well.

The issue arose when I attempted to deploy one of my applications to my test environment which is running Glassfish V2. Many class not found issues appeared in the server log each time I tried to deploy. At the bottom of the stack trace I received a misleading message stating that there were "Errors in the EjbDescriptor". This led me searching my ejb-jar.xml, pages.xml, and web.xml files looking for issues. As none were found, I tried to give it the old clean, rebuild, and deploy once again...same issue.

At this point I began comparing with another successful Seam 2.0 migration and there were really no apparent differences. I spotted the problem when I went to the file system and looked in the application's dist directory. None of my Seam 2.0 libraries were being packaged with the deployment.

As it turns out, if you repackage and change libraries for an existing application within Netbeans 6.1 beta, then you must do the following:

1) Right click on the project, and choose properties.

2) Navigate to Libraries and make necessary changes.

3) YOU MUST check and uncheck the package checkbox within the libraries configuration...even if it is checked by default. This must update the build script for Netbeans because this was checked by default, but my libraries were not included.

After I unchecked the library package box and then re-checked it everything worked fine. The necessary JAR files that are contained within my included Netbeans libraries were deployed with my app and it works fine now.

Not a big issue, but an issue that is definitely not obvious and took me some time to figure out. I still recommend Netbeans 6.1...but I am not moving to RC1 at this time. I will probably wait for the production release because I do not want to migrate my libraries manually...

Happy NetBeaning....

Monday, April 07, 2008

Shameless Self-Advertising

Time for a bit of shameless self-advertising. I'd like to let everyone know about a new hosting service I've started to assist individuals in event planning. If you or anyone you know needs to plan an event sometime soon, please take a look at my site and see if it will help out. Gather Event Planning offers individuals their own dedicated web site for organizing an event. The website includes a news blog, member registration, member forum, email contact lists, and much more to help aid in the process of planning an organized event.

There is no fee to try the service...only an email address is required. If you use the service for less than 30 days then it is free. This will allow anyone to plan a short-term event (such as a surprise party) without incurring any charges. There are plans available for those who wish to host a long-term event site for class reunions and such.

Enough gabbing about the service, feel free to give it a try and then let me know what you think.

Visit the site at http://www.gathereventplanning.com for more details.

SeamFramework.org - In case you did not know...

I wanted to let everyone know about another great JBoss SEAM resource, it is the seamframework.org website. This site includes a lot of documentation, as well as a community for SEAM developers.

Another good reason to use the SEAM framework!

Jython Monthly Call for Articles - April 2008

The April 2008 edition of the Jython Monthly newsletter is scheduled for distribution on April 15, 2008.

Please post any articles or contributions for the April 2008 distribution of the Jython Monthly newsletter at the following link:

http://wiki.python.org/jython/JythonMonthly/Articles/April2008

Visit http://wiki.python.org/jython/JythonMonthly/Articles/Submitting for details regarding newsletter artical submittals.

All contributions are appreciated! Please feel free to contact me if you have any questions.

Tuesday, April 01, 2008

Groovy Netbeans Plugin

After searching for a while to find information regarding the Groovy and Grails Netbeans plugin, I determined that it is only available if you download and use a nightly build. You must download a nightly build and then go to the plugin manager to find it.

Ok, that is good news, so now I will get to try out the plugin and see how it works. One slight reminder though, if you download and use a Netbeans nightly build then none of your created libraries will be carried forward. I've got too many libraries created so I plan on using the nightly build to evaluate the Groovy plugin only...I will continue my day-to-day development on the NB 6.1 release.

I wonder if a Jython plugin is in the future? One would think that since a couple of Jython gurus have been hired by Sun, we may have some hope for good Jython support in a future Netbeans release...let's hope so!