Technology

I'm speaking at...

I teach and consult for

Spring, Hibernate, Grails, Rails and Maven training from the experts!
Training Calendar

Roo in Action

Soon in print!

Spring Roo in Action
MEAP Available Now!

Author, Roo in Action - in MEAP now
Manning Book Forum
My Roo Blog Entries
Srini Penchikala InfoQ

Twittery!

@krimple
@techcast
@gdickens
@RooInAction

I host the
Chariot TechCast

Sunday
Jan082012

Roo, Selenium WebDriver,Failsafe and JUnit - Smores, anyone?

S'Mores are about the perfect mix of sugar, sugar and chocolate. So, the programming equivalent would be getting your Selenium tests separated from your unit tests, and running in an API that just needs a web server, not a separate Selenium server, right?

(Ok, I'm stretching it).

A WebDriver test

First, here is an integration test, ITCourseSelenium.java that uses the Selenium WebDriver API. Look how simple the code is:



Next up, we have the Maven configuration for the various plugins to install Selenium (forget the current Selenium Roo add-on for this, it only sets up HTML tests and doesn't include the Java API, plus doesn't install WebDriver and needs to run on a port, which is tricky):

Selenium Configuration

Add these elements to your pom.xml file to set up the configuration:



These fragments configure a jetty web server, which starts up before integration testing. They also configure the maven-failsafe-plugin, which is attached to the integration-test and verify Maven lifecycle phases.

Running the tests

To run your tests, just issue the mvn verify command. All tests starting or ending with IT will run after the web application starts, and will be recorded as test results in target/failsafe-reports.

Enjoy.

Ken

Tuesday
Oct182011

Roo (in the) Corner - new features in trunk...

I've been spending my time readying Roo in Action for publication. Turns out, the Roo team had other ideas - including lots of new things you may want to be aware of if you are looking to support Roo 1.2 once it is released.

Keep in mind these changes are in-flight. If you don't need to work on trunk, DO NOT WORK ON TRUNK. This is something other platform afficianados do - for example, the Rails development community commonly calls this working on the "edge". So, let's get edgy.

There are some really, really cool things in here. I've seen them move toward opening up for all modes of development - some want JSF, so there is a JSF add-on. They use PrimeFaces, and a dialog motif for adding new elements. I'm sure they will tweak this as it goes along, but it looks more like the GWT or Flex mode of editing I saw before.

Breaking Changes (so far) - you may need to edit your code - I know I have to for now, but this is a temporary pain for some consistency gain within Roo.


  • @RooEntity -> @RooJpaActiveRecord

  • @RooWebScaffold - now a .scaffold. package after .controller.

  • @RooConversionService - now a .converter. package after .controller.


Additions


  • New @RooEquals - and a shell command for equals - this has been here for a little while, but is something that can be of use when defining models or other objects that need to be compared. You can exclude fields from the factoring of the comparison.

  • new entity flags (recent anyway) to set entity name, table, and other attributes on entities - this is great, and includes the ability to define transaction manager names for cases where you are working with multiple JDBC datasources - nice! Also, it lets you specify the entity manager - so if you have two persistence units to separate transaction managers (reporting database -vs- transactions) you have that option. Again, not a huge deal, but lets you stay within Roo to get things done, without digging into code for a configuration option. You can even set the table name, entity name, etc...

  • New settings for the json command - --deepSerialize and --rootName - I am not sure if these have been here long, but they are good to know about.

  • New —packaging element in project - includes POM or JAR right now. Also includes --parent. This could be great, as I think they are going to implement multi-pom support in Roo 1.2. We'll stay tuned on that, and perhaps write a quick blog entry on what we've found.

  • New support for database dot com - a new database provider - I don't know much about it.

  • New date field support for both dateTimeFormatPattern AND dateFormat - I am unsure that the scaffold would deal with dateTimeFormatPattern.

  • JSF scaffolding in place - uses PrimeFaces for the widgets - this is interesting, and has a different look and feel, native to PrimeFaces. But, it does exactly the same work as the scaffold in MVC. So, if you're looking at complexities and benefits of each, go for it. The CI build server is here, and you just need to follow these rules to get it to use trunk.


It was so easy to switch between JSF and MVC for my testing, I used these two scripts:

Roo with MVC

 

project --topLevelPackage foo.bar.mvc --packaging JAR --projectName mvcrules
jpa setup --database HYPERSONIC_PERSISTENT --provider OPENJPA
entity jpa --class ~.model.Course --testAutomatically
field string --fieldName name
field date --fieldName runDate --type java.util.Date --dateFormat SHORT
web mvc setup
web mvc all --package ~.mvc quit
Roo with JSF
project --topLevelPackage foo.bar.jsf.sortarules --packaging JAR --projectName jsfsortarules
jpa setup --database HYPERSONIC_PERSISTENT --provider OPENJPA
entity jpa --class ~.model.Course --testAutomatically
field string --fieldName namefield date --fieldName runDate --type java.util.Date --dateFormat SHORT
web mvc setupweb mvc all --package ~.mvc
quit

I will attempt to update this article as I find new things... No promises, as the primary artifact is the book. But hopefully this is a warning shot across the bow that change is indeed a-coming.

Tuesday
Oct182011

Living on the Edge of a Roo - working on the trunk

Let's say you're an add-on developer or someone who wants to stay current with the refactorings of Roo 1.2. Since it is in active development, you need to do two things to make your project work with the latest code. Remember, this is bleeding edge, so don't be surprised if your Maven gets ahead of your snapshot builds...

Install the CI build

First, download the most recent build from the CI server at http://static.springsource.org/downloads/nightly/snapshot-download.php?project=ROO Install it as roo in your symlinks (unix/OS X) or add to the path for Windows.

On my OS X system, I call it rooss, and I keep M1 as roo.

Set up your snapshot repo and Roo version

Next, edit your pom.xml file and change the roo.version to 1.2.0.BUILD-SNAPSHOT - the punctuation is very important to Maven here. You'll need to add the Roo snapshots repository to your repository list:

 <repository>
    <id>spring-roo-repository</id>
    <name>Spring Roo Repository</name>
    <url>http://spring-roo-repository.springsource.org/release</url>
</repository>

Then, you can do a mvn package and you should be on your way.

Thursday
Oct132011

Webflow on Grails and jQuery UI with Grails at the Philly on Grails User Group Meeting

Note - what follows is incoherent. It was a long day. I hope to edit this and make more sense in the article tomorrow. For the intrepid, there's cool projects lurking in here...

Today Jason Gritman @gritman and Bob Rodini had a Philly Grails meeting at Chariot Solutions.

Spring Webflow under Grails

Bob Rodini showing Grails and WebFlowWe started with Bob Rodini's presentation on using the Spring WebFlow framework, which in typical Grails fashion is provided using a Groovy-based DSL. Bob is working on Grails in his work-a-day life, and walked us through the conventions, communication with the scopes, and other things.

We discussed the Grails approach for WebFlow -vs- regular XML WebFlow as well. A good summary of the benefits of this unique platform.

Bob is offering a Grails continuing education course at Penn State Great Valley Campus - if you are near that area, register and you can benefit from evening training from him.

jQuery and Grails

Jason (JSON?) Gritman answering UG questionsJason Gritman's talk on jQuery and Grails was very useful. He gave us a great tutorial on jQuery, jQuery UI and jQuery validator. Cool things to remember:

  • jQuery UI Theme Roller/Builder - Don't forget to Bookmark the URL when you are done theming - you can run that bookmark (a very long URL) to restore your settings and continue theming.
  • jQuery validator - you have control over where and when the validation fires. It has internationalization. etc...
  • Looking forward to jQuery UI's upcoming table component - sounds interesting to me!
  • Apparently custom validators can work - such as validating a credit card using Ajax - according to a discussion here at the talk.

Then Jason showed the validator user interface - before with Grails, after with jQuery validator.


Grails 2.0 Static Resources

Jason showed us how you can create a modules element in Grails 2.0 - create a resource set - closures:

modules = {
  validation {
    dependsOn 'jquery'
    resource url: 'js/jquery.validate.js'
    resource url: 'foo/bar.js'
  }

  ..
}

That's SUUUPER cool.

jQuery Validators

I really like those - he showed us the concept of adding a validation:


  $.validator.addMethod("name", function(params) { ...});

So you can write your own custom validators, and there are a number built in.

DataTables

This is a jQuery plugin that has a ton of features in it, and Jason has used it on projects. For Ajax consumers, it has a very specific JSON format and is, as he says, pretty complex. However, it is extremely powerful.

We got into a discussion of grid APIs, and obviously horses for courses...

The cool thing about the DataTables plugin is that it binds to jQuery UI theming, and you can just actively bind it to a statically built HTML table. Very good stuff (don't be surprised if you see a nice, dynamic grid on Chariot's training pages soon).

Calendaring

Jason is my hero... Such as good presentation even 1/2 way through. He showed us the FullCalendar project - another AWESOME jQuery UI plugin. Think of Google Calendar...

You can use the Full Calendar project to show a full page calendar. Loaded via JSON.

$.getJSON("uri", function(events) {
  $('#divname').fullCalendar({
  theme: true,
  events: events});
});

dynatree

Another nifty library. You can load it via JSON or HTML. Looks very sophisticated and event-driven. Everything binds with JSON. It looks very interesting. It doesn't necessarily hook into jQuery UI, so it is a one-off component.

BBQ

Stands for "Back button & query library" - this is something similar to the way the Showoff project uses the # parameter to show and switch slides. The hashtag will turn into a query string, and you can interact like with your request query string. You can push state for single items too.

BBQ isn't actively maintained, but Jason likes the concept. My head hurt looking at it, but it seems like you can fire up $.deparam and $.param to extract or add a parameter. Hashchange event is an HTML thing, and this project can emit it / react to it.

Wrap-up

Jason's code examples are at Grails Five jQuery Plugins Demo - and a blog entry is probably coming soon. Great job, JSON! I'll link to his blog article as soon as it is available.

Ken

Tuesday
Sep272011

Keeping and showing Jetty JSP source

FYI...  Did you know that you can keep the generated source files for your JSPs when running Jetty from maven?

Just add this to your web.xml file:

<servlet id="jsp">
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
   <init-param>
        <param-name>keepgenerated</param-name>
        <param-value>true</param-value>
   </init-param>
 </servlet>     
     

Then your JSP generated source, along with the class file, is located in target/tmp.