Loading...

Thursday, July 30, 2009

Debugging single nodes in Yahoo! Pipes

With Yahoo! Pipes we can aggregate, change and mashup content from around the web. We build the pipes with an application running in our web browser. Each pipe consists of a source and output, but in between we can use different operations. With the Debugger window we can see the intermediate results of the pipe so we can verify the results of the operations.

Suppose we have a simple pipe, which gets the items from this blog, sorts it based on the title field and then gets the last 5 results. So see the results of the sorts operation we must select the Sort node. The Debugger window will now show the sorted content:

And to see the results of the Tail operation we must select the Tail node and look at the Debugger window:

Another way to see the output is clicking on the Debugger tab. The Yahoo! Pipes builder opens a popup window with a list of all nodes. We only have to select the node from this list to see the output in the Debugger window:

Tuesday, July 28, 2009

Change scaffolding templates in Grails

The scaffolding feature in Grails is impressive, especially when we want to show off Grails to other developers. Seems like magic is happening with only a minimal of code. But what if we don't like the default pages Grails generates for us. Of course there is a way to have another layout for the dynamically generated pages.

First we start with a simple, one domain object application:

$ grails create-app scaffold-sample
$ cd scaffold-sample
$ grails create-domain-class message
$ grails create-controller message

We open grails-app/domain/Message.groovy and add the following simple attribute with a small constraint:

class Message {
    String text

    static constraints = {
        text maxLength:140
    }
}

Next we add the magic code to the grails-app/controllers/MessageController.groovy:

class MessageController {
    def scaffold = true
}

We are ready to run the application and we are able to view, add, update or delete messages:

$ grails run-app

We see the default layout we get from Grails. To see which GSP files Grails uses to generate these pages we only have to invoke one command:

$ grails install-templates

After the script is finished we have a new directory src/templates. In this directory we find the scaffolding directory with a couple of GSP files. To change the layout of the pages we only have to make our changes here. Every controller which uses scaffolding will get these changes. Let's create a new CSS file and use it in the create.gsp, edit.gsp, list.gsp and show.gsp files.

We create a new file scaffold.css in the web-app/css directory:

body {
    background-color: #EFE14E;
}
.logo {
    font: 28px bold Georgia;
    color: #006DBA;
    padding: 0.3em;
}
table {
    background-color: #F3EFC9;
}

We open the files create.gsp, edit.gsp, list.gsp and show.gsp and add the following line in the HTML head section:

<link rel="stylesheet" href="\${resource(dir: 'css', file: 'scaffold.css')}"/>

Now when we run the application again we see that the dynamically generated pages are using the new CSS file:

Besides a simple change like this, we can of course do anything we want with the GSP files that are used for scaffolding. In the above screenshot we can see for example we have removed the default Grails logo and replaced it with our own text.

Show test failures only in NetBeans 6.7

The Test Results tab in NetBeans has an option to only show failed test methods. This will give a better overview when we are testing and only interested in the methods that fail.

In the left gutter of the Test Results tab we have an icon for showing failures only:

When we click the icon we only see the failed methods for the test class. We focus on these to remove the failures from the test class:

Unit testing with Maven and NetBeans 6.7

The JUnit test runner has improved a lot in NetBeans 6.7. Now we can run single test methods and we get better feedback.

Let's start with a simple Maven project. We go to File | New Project | Maven | Maven Project. We select the Maven Quickstart Archetype (1.0) from the list of archetypes. We fill in all required fields and press the OK button. NetBeans creates a new Maven project in the IDE. The Quickstart Archetype already created a JUnit test class for us, so we can immediately see the new NetBeans JUnit testrunner. We go to Run | Test Project. And in the Test Results tab we get the good news that alls tests have passed:

Okay for this example it is pretty obvious, but in NetBeans 6.7 we can right-click on the method name and select Run Again. Now only this method is tested and not the whole class:

We can imagine this is especially useful for methods that do not run successful. Let's add a test method that will fail. We open the AppTest class and add the following method, which will fail during test:

public void testFailure() {
    fail("Deliberate fail...");
}

When we test the class again our Test Results output has changed:

The progress bar is no longer green, we have a 50% green and 50% red part. We also see the testFailure method has failed. The good thing is we can only run the failed method again by right-clicking on the method and selecting Run Again. To go directly to the source code we must right-click on the method and select Go to Source. NetBeans opens the source code file and jumps to the right position in the editor. The Go to Source on a method only works when we create a NetBeans Java project, if we use a Maven project only if we select Go to Source on the class name we jump right to the source code of the test class.

Thursday, July 23, 2009

Space for next page in web browsers

In most web browser we can use Space to scroll a page down, and Shift-Space scrolls one page up. When we my hands are on the keyboard the Space is right under my thumbs, so I can access it quickly.

Wednesday, July 22, 2009

Weekly Sightings

My M&M's
A great way to personalize your own candy! Pick your color, add a text or photo and print them on M&M's. How cool is that?

Thursday, July 2, 2009

Add Maven dependency in NetBeans

Maven support has improved a lot in NetBeans 6.7. One of the small, but important, features is the possibility to add a new dependency to a Maven project. In the previous version of NetBeans we could add a new library, but then we had to know the artifact and group name ourselves. In NetBeans 6.7 we can search for dependencies in the repositories, add an opened project or use the dependency management features of Maven.

To add a new dependency we right-click on the Libraries node of a Maven project and select Add Dependency....

NetBeans opens a dialog window where we can do several things to a dependency to our project. We can fill in the input fields ourselves and choose the scope from the Scope combobox.

But we can also search for a dependency in the repositories. To do this we must type text in the Query input field. The Search Results shows found libraries as we type. We select the library we want and press the OK button to add it to our project.

Instead of using a query we can use the Dependency Management tab. This tab is enabled if our project's POM contains a dependencyManagement section (or the parent POM most likely). The tab shows all available artifacts that are defined in the dependencyManagement. We select the artifact we want to add to our project and press the OK button to add it to our POM.

And finally we can even select the artifact from one of the open Maven projects in NetBeans. If we have more than one Maven project in the Projects window the Open Projects tab of the Add Dependency dialog window is enabled. To add the project's artifact to our POM we select the project and press the OK button.

Weekly Sightings

Gelaskins
Can't wait to order one of these cool laptop skins. Getting rid of the dull look of my HP laptop and just stand out with one of the coolest skins I've seen. An as a bonus I can even pimp my little Nintendo DS.

Generate code with code completion in NetBeans

The code completion for Java in NetBeans 6.7 also includes options for code to be generated. In previous versions we had to use Source | Insert Code..., but now we only have to press Ctrl+Space and we get to see which code can be generated by NetBeans.

Suppose we have the followings simple class:

package javaapplication11;

public class MyObject {
    private String netbeansRules;
}

We press Ctrl+Space (in Windows) to activate code completion (or select Source | Complete Code.... NetBeans shows the code completion popup:

At the top we see the code NetBeans can generate for us. We see constructors, methods to override from java.lang.Object and get/set methods for our property:

We select the option we want to let NetBeans generate the code.

Wednesday, July 1, 2009

Auto popup code completion in NetBeans

In NetBeans 6.7 we can get code completion as we type. Normally we must invoke code completion with Ctrl+Space. To get auto popup code completion we go to Tools | Options | Editor | Code Completion. We select Java from the Language combo box. The option dialog window shows the option Auto Popup on Typing Any Java Identifier Part (What is in a name?). We must select the checkbox to get auto popup code completion.

Now when we write code in the Java editor the code completion popup window shows when we stop typing characters.

Change output font in NetBeans

In the new NetBeans 6.7 we can easily change the font of the output window. We must right-click in the output window and we get a popup menu. We select the option Choose Font... and we get a dialog window where we can choose the font for the output window.

Changing the size of the font is also very easy. If we right-click in the output window we get a popup menu with the options Larger Font and Smaller Font. The default shortcut keys in Windows are Ctrl+Plus and Ctrl+Minus. So if we have a lot of text in the output window and we have good eyes we can make the font really small to get it all in one output window.

A two week holiday and NetBeans 6.7 is released

Wow, I come back from a two week holiday and found out NetBeans 6.7 is released. So the first thing I do today is download NetBeans 6.7 and start playing around with it.