7 Replies Latest reply on Mar 7, 2006 1:11 PM by Cory Virok

    Advice on reusable jPDL and SFSB components

    Cory Virok Newbie

      I'm trying to get a better handle on this jPDL stuff and was hoping to get some feedback.

      In my example, I'd like to allow a user to be able to search for other users to add to his buddy list as well as search for music files in some DB to add to his "playlist". Both the search for users/music actions need to be reusable across the site and not just in the context of adding buddies and making a playlist.

      So the approach I'm taking is to have 2 entites, 1 for the User and another for a piece of music, (with some associative tables for the buddy list and the playlist.)

      I'll also have two SFSB, 1 for the user search and another for the music search. They'd look something like this:

      @Stateful
      @Name("userSearch")
      @Conversational(ifNotBegunOutcome = "login")
      @Scope(ScopeType.CONVERSATION) //better off making this session??
      @Interceptors(SeamInterceptor.class)
      public class UserSearchBean implements UserSearch, Serializable {
      
       @DataModel
       private List<User> userList;
      
       //Used for selecting more than one user at a time
       @Out(Scope = ScopeType.CONVERSATION, required = false)
       private Map<User, Boolean> selectedUsers;
      
       public Map<User, Boolean> getSelectedUsers() {
       return selectedUsers;
       }
      
       @Begin(join = true)
       public String search() {
       userList = entityManager.createQuery(...);
       }
      
       @End
       public void done() {}
      }
      

      and Music search would be pretty much the exact same thing.

      Now, say I wanted to make a wizard-type bean that would guide the user through the initial setup of adding users and creating a playlist. So I create a pageflow:

      <pageflow-definition name="wizard">
      
       <start-state name="start">
       <transition to="addUsers">
       <action expression="#{wizard.start}"/>
       <transition>
       </start-state>
      
       <page name="addUsers" view-id="/userSearch.jsp" redirect="true">
       <transition name="addUser" to="addUsers">
       <action expression="#{wizard.addUser}" />
       </transition>
       <transition name="done" to="addMusic" />
       </page>
      
       <page name="addMusic" view-id="/musicSearch.jsp" redirect="true">
       <transition name="addMusic" to="addMusic">
       <action expression="#{wizard.addMusic}"/>
       </transition>
       <transition name="done" to="done">
       <action expression="#{wizard.done}"/>
       </transition>
       </page>
      
       <page name="done" view-id="/done.jsp" redirect="true">
       <end-conversation />
       </page>
      
      </pageflow-definition>
      


      And now for my Wizard bean:

      @Name("wizard")
      @Stateful
      @Scope(ScopeType.CONVERSATION)
      @Conversational(ifNotBegunOutcome = "login")
      @Interceptors(SeamInterceptor.class)
      public class WizardBean implements Wizard, Serializable {
      
       @In(create = true)
       private UserSearch userSearch;
      
       @In(create = true)
       private MusicSearch musicSearch;
      
       @In
       private User user;
      
       private Boolean doneUsers = false;
       private Boolean doneMusic = false;
      
       //Getters and setters for doneXXX fields...
      
       @Begin(pageflow = "wizard")
       public void start() {}
      
       public String addUser() {
       if(user != null) {
       List<User> selectedUsers = userSearch.getSelectedUsers();
       this.user.addUsers(selectedUsers);
       }
       if(doneUsers) return "done";
       return "addMusic";
       }
      
       //same for addMusic...
      
       @End
       public void done() {}
      }
      


      So after I have the JSP pages setup to display the search and currently selected users/music, my wizard will kickoff the page flow after it's initial start() method is called and all of the subsequent page navigation will be completely controlled by jPDL... right?

      What if I wanted to reuse the wizard pageflow but in the context of a larger operation? Ex: what if I wanted to write a transition process that would basically "loop" through the wizard pageflow but with different Users each time? This sounds like what jBPM is good for...

      Lastly, is there any JBoss IDE support for doing something like "New" -> "Pageflow"? I've seen the "New" -> "Process Definition/Project" but I only want to make a new pageflow file, just like in the numberguess example.

      I appreciate your time with this long-winded question/request for assistance. My main concern is reusability with my SFSBs. So any advice or feedback/criticism is definitely welcome.

      Thanks!
      - Cory