Crazy Idea?: Programmatic Navigation (Static or Dynamic)
luxspes Oct 16, 2008 6:56 PMHi!
I while ago I wrote a post in my blog about navigation the way WebObjects use to do it. So far I have not found a framework with such a simple and at the same powerful way for dealing with navigation and exchange of data between pages (sadly webobjects didn't support the concept of Long running conversations, but I think its navigational API could evolve to become a really good fit for Seam conversational model). Lately I have been having some doubts about the way navigation works in Seam, specially when dealing with nested conversations combined with @PerNestedConversation.
The other day Tim Evers wrote that he would also like to have some kind of programmatic navigation, and it seemed similar to what I been thinking about, but he was unable to visit my blog due to firewall restrictions.
Therefore I am posting here part of my blog post because I would like to discuss this different way of doing navigation in a more programmatic way:
Here is a pseudo code example (In WebObjects, both pages and reusable fragments are WOComponents):
public WOComponent gotoProfilePage(){ ProfilePage profilePage = new ProfilePage(); profilePage.setUser(this.getSelectedUser()); return profilePage; }
I think it is pretty self explanatory, it is an action that navigates to the ProfilePage, but it has all the advantage of static typing and object orientation, or course we could make it more dynamic if we need to:
public WOComponent gotoProfilePage(){ WOComponent profilePage = this.getPageWithName("ProfilePage"); profilePage.takeValueForKey(this.getSelectedUser(),"user"); return profilePage; }
Therefore, using an API similar to this one as a basis we could have a programmatic and object oriented way of navigating that can work in a dynamic way if needed.
Here is example of how this could look like if altered to be more Seam/RESTEasy like:
@Path('/profile.xhtml') @Scope(ScopeType.PAGE) public class ProfilePage{ //Other stuff in ProfilePage controller public void setUser(User user){...}; } @Path('/home.xhtml') @Scope(ScopeType.PAGE) public class HomePage{ //This is an action linked to a JSF control public ProfilePage gotoProfilePage(){ ProfilePage profilePage = new ProfilePage(); profilePage.setUser(this.getSelectedUser()); return profilePage; } //Other Stuff in ProfilePage public User getSelectedUser(){...}; }
A Seam interceptor could detect that the action returned an object annotated with @Path('/home.xhtml') and redirect to that page sending the currently selected user in HomePage to the ProfilePage using a Temporary Conversation.
What do you guys think? Would it work? Do you notice any major flaws with this model?