Announcement Announcement Module
No announcement yet.
Querying object from persistence layer before binding FBO & optional path variable? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Querying object from persistence layer before binding FBO & optional path variable?


    Default behaviour of Roo-generated controllers is to instantiate a new command object prior to binding. I want the command object to be queried from the persistence layer before binding. This is necessary because I dont want to bind all attributes in the web form as it is essentially one page in a wizard. It should be straightforward but Ive hit a snag: the formBackingObject is called before every request-mapped method, but it must not be when creating a new entity because the path variable will be null:

    public User formBackingObject(@PathVariable("id") Long id) {
    	if (id == null) return null;
    	User user = User.findUser(id);
    	if (user == null) throw new IllegalArgumentException("User "+id+" not found");
    	return user;
    This is the problem described here but Im posting it here on the Roo forum because it applies to Roo-generated RESTful controllers and Im pretty sure other Roo users have come up across this problem.

    It seems it should be possible to make the PathVariable optional. I have tried to extract the path variable manually but unfortunately the logic is buried in private methods of AnnotationMethodHandlerAdapter, so I would have to copy & paste internal Spring code. So the only workaround I can see is to split it into 2 controllers and abandon REST URLs messy and contrary to the Roo ethos of elegant simplicity. Roo should be making life easier not harder. Any suggestions?