5 Replies Latest reply on Jul 4, 2006 11:48 AM by hdslkf hklsdg

    Beginner's question: Simple passing of data from page to pag

    hdslkf hklsdg Apprentice


      I have a general question that maybe even others might have ;).

      I work with JSF + Spring + Hibernate + ADF Faces, but since JSF + Seam + EJB3 is so much easier, I wanna know it better ;). But what confuses me (even when looking at the documentation - which is not complete yet - or the examples) are the different scope types of JSF beans (application, session, request), the Seam stuff (Event, Conversation, ...) and EJB beans (stateful, stateless).

      I'd like to implement a simple example for learning Seam, but I wasn't able to make it work, though trying every combination of Annotations (Scope, Stateful, Stateless, In, Out, ...) that seemed sensible to me.

      Maybe you could give me a hint, what to do with the following code to make it work. Let me explain you the example. I call it "ping pong". A user enters something into a textfield on a page called ping.jsp. After that, he's being led to a page called pong.jsp. There is another textfield and the user enters something in it. After that, he's being taken back to ping.jsp.... and so on. Everything the user types shall be shown under the textfields, with a remark on which page he entered it. It should look a little like a chat:

      [_Textfield__] [__Send button__]

      Ping: Hello
      Pong: Hello, too
      Ping: Test
      Pong: Lala

      Now here's the code:

      PingBean.java (I think I don't need to post the Local Interface here ;))

      public class PingBean implements Ping {
       //That's the line the user enters
       private String line;
       //That's the whole chat
       @In(required=false) @Out
       private String chat;
       //This one is being called after the user clicks send
       public String send() {
       //The line the user typed in is being attached to the whole chat
       chat += "Ping: " + line + "<br /">;
       //And the outcome to navigate to pong.jsp is being returned
       return "pong";
       //getters and setters

      PongBean.java is the same, just replace pong by ping and vice versa ;)

       <h:inputText value="#{ping.line}" />
       <h:commandButton value="Send" action="#{ping.send}" />
       <br />
       <h:outputText value="#{ping.chat}" />

      pong.jsp is similar, and the navigation rules should be clear (no redirect) ;).

      Now: How to annotate the example to make it work?

      At the moment:
      - chat is always "Ping: null null" or "Pong: null null"
      - the textfield says #{ping.line} (so the variable isn't being resolved :() (this explains the first null)
      or in a nutshell: I can't bind the line-String to the JSF file and I can't pass the chat-String to the other page. Only the call of the action method works.

      Please keep in mind that I just want to pass the chat variable from one page to the other. And as I want to have multiple instances of this "dialog" open, there shouldn't be any use of sessions. Just passing from one page to another (just like ADF Faces' "process scope", if you maybe know it).

      I'd be thankful for any help :).

      PS: If you wonder what this example is good for: There are many applications where to pass something from one page to another. E.g. if you have a list of customers. You select one and you want to navigate to his orders to create a new one. Then the software should be aware of which customer you want to add this order to.

        • 1. Re: Beginner's question: Simple passing of data from page to
          hdslkf hklsdg Apprentice

          I tried the following annotations:

          @Scope(ScopeType.EVENT) // @Scope(ScopeType.CONVERSATON) // @Scope(ScopeType.SESSION)
          public class PingBean ....{
           @In(required=false) @Out(required=false)
           private String talk = "";
           @In(required=false) @Out(required=false)
           private String line = "";
          // means that I tried all those Scopes.

          Well, and still I can't even get #{ping.line} resolved in the JSP, though the bean is stateful (I do know that stateless beans can't provide properties to JSF) and has getters/setters (which are also defined in the Local Interface).

          And talk still is "Ping: null null"

          Only the getTalk-method gets called, but there's no call on set/getLine or setTalk (found out via @AroundInvoke and logging).

          This just doesn't make sense to me...

          • 2. Re: Beginner's question: Simple passing of data from page to
            hdslkf hklsdg Apprentice

            Sorry, I do mean "chat" instead of "talk" in the above post. My fault, please don't get confused ;).

            • 3. Re: Beginner's question: Simple passing of data from page to
              Gavin King Master

              Do you have seam.properties in the root of the archive where the Ping component is deployed?

              • 4. Re: Beginner's question: Simple passing of data from page to
                hdslkf hklsdg Apprentice

                Well, guess that's it. The file isn't in the webapp dir, though I got it in my Eclipse project (in /resources dir). Thanks for that hint. I almost threw my laptop out of the window as I didn't get the simplest examples to work :D.

                Now, I even just saw that hint on page 105 of the 1.0.1 reference documentation.

                But there is one final item you need to know about. You must place a seam.properties file in the root of any archive in which your Seam components are deployed (even an empty properties fiel will do).

                Btw, it's funny that I copied build.xml from the registration example (with little modifications), and when inserting the registration example files into my project... THEY WORK *argh*. Well ok, I think I know why: The registration example uses the properties of an EJB3 entity (user), whilst I use properties of a Seam component (and as seam.properties misses, those components don't work), right?

                However, after that long day of irritation and confusion I had a look at my build.xml, but I couldn't find out why Ant didn't deploy my seam.properties file. Maybe you could have a little look?
                <?xml version="1.0"?>
                <project name="Ratespiel" default="deploy.tomcat" basedir=".">
                 <!-- Example name -->
                 <property name="Name" value="Seam Ratespiel"/>
                 <property name="example.name" value="jboss-seam-ratespiel"/>
                 <!-- WAR -->
                 <zipfileset id="example.war.docroot"
                 <include name="**/*"/>
                 <zipfileset id="example.war.webinf"
                 dir="resources/WEB-INF" >
                 <patternset refid="meta.files"/>
                 <zipfileset id="example.war.webinf.lib"
                 <include name="_NONE_"/>
                 <zipfileset id="example.war.webinf.lib.extra"
                 <include name="_NONE_"/>
                 <zipfileset id="example.war.webinf.lib.extra"
                 <!-- EJB3 -->
                 <fileset id="example.ejb3.root"
                 <include name="import.sql"/>
                 <include name="seam.properties"/>
                 <include name="META-INF/ejb-jar.xml"/>
                 <include name="META-INF/persistence.xml"/>
                 <!-- EAR -->
                 <zipfileset id="example.ear.resources"
                 <include name="*"/>
                 <exclude name="META-INF/persistence.xml"/>
                 <exclude name="META-INF/jboss-beans.xml"/>
                 <exclude name="META-INF/ejb-jar.xml"/>
                 <fileset id="example.ejb3.lib" dir="../../lib">
                 <include name="_NONE_"/>
                 <!-- Test -->
                 <fileset id="example.resources" dir="resources">
                 <include name="**/*.*"/>
                 <!-- Tomcat build -->
                 <zipfileset id="example.tomcat.war.webinf"
                 dir="resources/WEB-INF" >
                 <include name="web.xml"/>
                 <include name="components.xml"/>
                 <include name="faces-config.xml"/>
                 <fileset id="example.tomcat.resources"
                 <include name="seam.properties"/>
                 <include name="META-INF/persistence.xml"/>
                 <include name="META-INF/ejb-jar.xml"/>
                 <include name="META-INF/jboss-beans.xml"/>
                 <!-- Deploy -->
                 <fileset id="example.deploy"
                 <include name="ratespiel-ds.xml"/>
                 <!-- Undeploy -->
                 <patternset id="example.undeploy">
                 <include name="ratespiel-ds.xml"/>
                 <!-- Overrides -->
                 <property name="src.java.dir" value="src"/>
                 <property name="src.test.dir" value="src"/>
                 <property name="test.classpath" value="test.eejb.classpath"/>
                 <property name="tomcat.conf" value="eejb.conf"/>
                 <import file="../../build.xml"/>

                PS: The registration example doesn't deploy seam.properties either. Ok, it seems like the example doesn't need it. But when someone uses this one as a template for his own project (as suggested) and tries to extend it then he will surely go mad ;).

                • 5. Re: Beginner's question: Simple passing of data from page to
                  hdslkf hklsdg Apprentice

                  I forgot: I use Tomcat 5.5.17 - not the JBoss AS