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;

No comments:

Post a Comment