13 Replies Latest reply on Sep 30, 2008 7:53 AM by Dean Hiller

    should this project even be done with seam?

    Dean Hiller Expert

      first, I love seam but am wondering if I am running into a use case where perhaps there is a better technology to use then seam.  I would like some advice here(any advice).  Basically, we have a backend where our customer service can login and create a script flow and dialog that an agent will follow when on the phone such as


      Agent: Hello Mr. Customer, do you like red or blue
      Customer: blue
      At this point Agent, check marks blue on the GUI and clicks next
      Agent: Where were you born?
      Customer: Michigan
      Agent now types in Michigan


      These scripts are all created, more and more of them...all different, and all custom per client.  This means we almost have this single common.xhtml page where it needs to be filled in differently depending on the script.


      I can see doing the script creation in seam, but what technology best suits these dynamic web pages...I come to think of ASP.NET in that case where I can add components to the page in code behind.  That doesn't seem to possible in Seam though.  any thoughts on the best technology here?  (I would still like to use seam on script creation, but I am not sure that will work with the technology I will need to use for running the scripts with the live agent to enter their data).


      any ideas here?
      thanks,
      Dean

        • 1. Re: should this project even be done with seam?
          Daniel Roth Apprentice

          I have done something similar in a really big project. We used <h:panelGrid bind="#{...}"/> and added stuff programtically. The reason for this was that the parts in the panelGrid could affect each other (if the user's script instructed so).

          • 2. Re: should this project even be done with seam?
            Dean Hiller Expert

            How do you add components programmitically?  Do you just insert the html into the document or how do you handle this?


            I am also thinking about velocity/turbine as well as I am not sure the best thing here.
            thanks,
            Dean

            • 3. Re: should this project even be done with seam?
              Francisco Jose Peredo Noguez Master

              Dean Hiller wrote on Sep 29, 2008 20:55:


              first, I love seam but am wondering if I am running into a use case where perhaps there is a better technology to use then seam.  I would like some advice here(any advice).  Basically, we have a backend where our customer service can login and create a script flow and dialog that an agent will follow when on the phone such as:



              Agent: Hello Mr. Customer, do you like red or blue

              Customer: blue

              At this point Agent, check marks blue on the GUI and clicks next

              Agent: Where were you born?

              Customer: Michigan

              Agent now types in Michigan




              These scripts are all created, more and more of them...all different, and all custom per client.  This means we almost have this single common.xhtml page where it needs to be filled in differently depending on the script.



              I can see doing the script creation in seam, but what technology best suits these dynamic web pages...


              I have created dynamic forms read from definition in database using seam, and they are working fine and were not hard to build.


              I come to think of ASP.NET in that case where I can add components to the page in code behind.


              I was really expecting that you were going to say that you were thinking about using OpenLaszlo, or Flex, or  ExtJs and basically build everything client side, but if you are attracted to ASP.NET server side code behind then first let me tell you that you do not need direct access to JSF component tree to create dynamic forms, but if you do want to do it that way, you can, using Seam and JSF binding, please read this specially the section Binding a component to the controller


              That doesn't seem to possible in Seam though.


              It is 100% possible. You can read about how to do that in the page I recommended before


              any thoughts on the best technology here?  (I would still like to use seam on script creation, but I am not sure that will work with the technology I will need to use for running the scripts with the live agent to enter their data).



              any ideas here?




              Use Seam, with some help of RichFaces and you should be fine.


              thanks,


              Dean




              Click HELP for text formatting instructions. Then edit this text and check the preview.

              • 4. Re: should this project even be done with seam?
                Daniel Roth Apprentice

                   public UIForm getForm()
                   {
                      UIForm form = new UIForm();
                      form.setId("form");
                
                      final UIInput username = new UIInput();
                      username.setId("password");
                      username.addValidator(new Validator()
                      {
                
                         public void validate(FacesContext arg0, UIComponent arg1, Object arg2) throws ValidatorException
                         {
                            String value = (String) arg2;
                            if (value.length() < 5)
                               throw new ValidatorException(new FacesMessage("must be > 4 chars"));
                
                         }
                      });
                
                      form.getChildren().add(username);
                      return form;
                
                   }
                
                




                People familiar with wicket may like this way of (ab)using JSF :-)

                • 5. Re: should this project even be done with seam?
                  Dean Hiller Expert

                  COOL!!  so then how do I get the page that is being requested.  I mean, I am guessing I will have a scriptTemplate.xhtml page and I will need to add checkboxes or inputText's or radio buttons depending on the data in the database.  I suppose I just need to get an instance of that page and then add components to it like the above code was showing, correct?


                  thanks for all the help!!!!
                  Dean

                  • 6. Re: should this project even be done with seam?
                    Daniel Roth Apprentice

                    somePage.xhtml


                    ...
                    <h:form bind="#{myBean.form}"/>
                    ...
                    



                    MyBean.java


                    @Name("myBean")
                    public class MyBean {
                    
                       public UIForm getForm() {
                          .. insert components depending on db here...   (see above)
                       }
                    
                    }
                    


                    • 7. Re: should this project even be done with seam?
                      Dean Hiller Expert

                      sweet, that is pretty cool!!!
                      thanks,
                      Dean

                      • 8. Re: should this project even be done with seam?
                        Francisco Jose Peredo Noguez Master

                        Or you can do it as I did it here and you do not even need to write java code.

                        • 9. Re: should this project even be done with seam?
                          Dean Hiller Expert

                          to be honest, I don't see how I could do it that way since I don't know if I need a checkbox, radio button, pulldown menu, inputText box until runtime when I pull the script from the database.  How can I do it your way when I don't know which widget I need?


                          your way is great for dyanmic forms of all inputText boxes, but in our case, the controls change sometimes.

                          • 10. Re: should this project even be done with seam?
                            Daniel Roth Apprentice

                            That is similar to what we had. But we also had custom controls like choose a user, and admin defined select-boxes. On top of that there were plugin-methods to achive dynamic stuff like if user does X to contol Y, control Z should take data from N. And all that stuff could be added by admin-users. Furthermore, the admin-users (and the given controls) would define a workflow (specific to each 'task') where different people had to do admin-defined tasks to progress in the flow. And so on.


                            It was in other words extremely complex (I really can't see how one could make it more complex, even if I wanted to), and we did it with seam/jsf, so I'm convinced so could you.

                            • 11. Re: should this project even be done with seam?
                              Dean Hiller Expert

                              Daniel, I totally get your solution and LOVE it. I had already started down that path after your post.  I just didn't get the other solution with the a:repeat as that seems to be for one single control someone would want to repeat(which is a great solution for another project I was working on though).
                              thanks,
                              Dean

                              • 12. Re: should this project even be done with seam?
                                Francisco Jose Peredo Noguez Master

                                Dean Hiller wrote on Sep 29, 2008 23:47:


                                to be honest, I don't see how I could do it that way since I don't know if I need a checkbox, radio button, pulldown menu, inputText box until runtime when I pull the script from the database.



                                The way recommand build handles checkboxs, radio button, pulldown menu, inputText box, and many more controls (I know it from experience).



                                How can I do it your way when I don't know which widget I need?



                                In both cases you need to know the widgets you need in advance, you will have have to use conditionals to choose what are you going to generate next, and, those conditonals will have to be hard coded somewhere. You can do it using the bind and create a hard dependency between JSF and your controller code, or do it my way, and have no dependency with JSF in you controller:

                                 <a:repeat value="#{controller.fieldList}" var="field">
                                      <h:outputText value="#{field.name}"/>
                                      <h:inputText rendered="#{field.isTextField]" #{controller.valueMap[field]}/>
                                      <h:otherControl rendered="#{field.isOtherKindOfField]" #{controller.valueMap[field]}/>
                                      </s:decorate>
                                    </a:repeat>
                                
                                



                                note the rendered="#{field.isTextField]" attribute, with that you can conditionally render only the appropiate control for the type of the field (or any condition you like). This has the advantage of separation the View from your datamodel (if you need to support a new control for an already existing type of fied, you only have to modify the .xhtml file.




                                your way is great for dyanmic forms of all inputText boxes, but in our case, the controls change sometimes.



                                They can change as much as you like, rendered does the magic that if will do in your code, but IMHO in a much cleaner way.





                                Click HELP for text formatting instructions. Then edit this text and check the preview.

                                • 13. Re: should this project even be done with seam?
                                  Dean Hiller Expert

                                  very interesting!!!  thanks for replying.  I get it now.  I should have thought of that rendered trick!!  definitely an eye-opener...great trick.
                                  thanks,
                                  Dean