Thursday, February 14, 2013

ASO in Tapestry

I am into the third chap of this nice book Tapestry 5: Building Web Applications and ran into NPE while running the example that introduces Application State Object (ASO).  Even though I annotated it correctly (@ApplicationState) the object was not getting injected.

    @ApplicationState
    User user;

Action handler:
    Object onFormSubmit() {
        System.out.println("Handling form submission!");
        String[] words = getMessage().split(" ");
        if (words.length > 0) {
            user.setFirstName(words[0]);
            if (words.length > 1) {
                user.setLastName(words[1]);
            }
        }
        another.setPassedMessage(message);
        return another;
    }

Was getting NPE in my handler.  After trail and error what I realized is the access specifier for the variable must be private.  Only then the framework would inject.  Checked with @InjectPage as well.  Even if you provide setter method it is not working.

    @InjectPage
    private Another another;
    @ApplicationState
    private User user;

maven archetype catalog

I was playing around with tapestry and when I try to do a quick start as of today the number of archetypes that maven shows is about 726 and I didn't know what number to pick.  Then I realised that I can filter the list after the initial listing.

726: remote -> uk.ac.rdg.resc:edal-ncwms-based-webapp (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): 251: org.apache.tapestry:quickstart
Choose archetype:
1: remote -> org.apache.tapestry:quickstart (-)
Choose a number or apply filter (format: [groupId:]artifactId, case sensitive contains): : 1
Choose org.apache.tapestry:quickstart version:

I already know how to use the archetype:create if I know the archetype details as below:
mvn archetype:create -DarchetypeArtifactId=quickstart -DarchetypeGroupId=org.apache.tapestry -DarchetypeVersion=5.3.6 -DartifactId=quickstart -DgroupId=com.phani -Dversion=1.0 -DpackageName=com.phani.quickstart

We have few interesting options with archetype:generate -DarchetypeCatalog=??? as below (source):
archetypeCatalog:
The archetype catalogs to use to build a list and let the user choose from. It is a comma separated list of catalogs. Catalogs use following schemes:
  • 'file://...' with archetype-catalog.xml automatically appended when pointing to a directory
  • 'http://...' or 'https://...' with archetype-catalog.xml always appended
  • 'local' which is the shortcut for 'file://~/.m2/archetype-catalog.xml'
  • 'remote' which is the shortcut for Maven Central repository, ie 'http://repo1.maven.org/maven2'
  • 'internal' which is an internal catalog
For tapestry we can say
mvn archetype:generate -DarchetypeCatalog=http://tapestry.apache.org