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:

      @Conversational(ifNotBegunOutcome = "login")
      @Scope(ScopeType.CONVERSATION) //better off making this session??
      public class UserSearchBean implements UserSearch, Serializable {
       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(...);
       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}"/>
       <page name="addUsers" view-id="/userSearch.jsp" redirect="true">
       <transition name="addUser" to="addUsers">
       <action expression="#{wizard.addUser}" />
       <transition name="done" to="addMusic" />
       <page name="addMusic" view-id="/musicSearch.jsp" redirect="true">
       <transition name="addMusic" to="addMusic">
       <action expression="#{wizard.addMusic}"/>
       <transition name="done" to="done">
       <action expression="#{wizard.done}"/>
       <page name="done" view-id="/done.jsp" redirect="true">
       <end-conversation />

      And now for my Wizard bean:

      @Conversational(ifNotBegunOutcome = "login")
      public class WizardBean implements Wizard, Serializable {
       @In(create = true)
       private UserSearch userSearch;
       @In(create = true)
       private MusicSearch musicSearch;
       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();
       if(doneUsers) return "done";
       return "addMusic";
       //same for addMusic...
       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.

      - Cory