Did you see this post. @Zuluru points out the need to write your code in a Command rather than a Controller. Perhaps the discussion and links will set you on the right path.