4 Replies Latest reply on Oct 11, 2010 11:00 AM by Will Piasecki

    Strange Groovy Seam component

    Bertrand Goetzmann Newbie
      Hello,

      In my Seam 2.1.1 application, I use a Groovy Seam component defined like this:

      Name("inSession")
      @Scope(ScopeType.SESSION)
      class InSession {

        String prop = 'Salut !'

        public InSession() {
          println "InSession called at ${new Date()} !"
        }

      }

      So, in a simple xhtml view I do this:

      <h:outputText value="#{inSession.prop}"/>

      When nagigating to the view the text "Salut !" is well displayed, but in the console I get 2 traces:

      16:55:41,514 INFO  [STDOUT] InSession called at Tue Feb 10 16:55:41 CET 2009!
      16:55:41,545 INFO  [STDOUT] InSession called at Tue Feb 10 16:55:41 CET 2009!

      For me InSession was invoked twice!

      Any explanation for this?


      Thank you.

      Bertrand.
        • 1. Re: Strange Groovy Seam component
          Bertrand Goetzmann Newbie
          I would like to correct a point in my previous message and add an extra information.

          First, I just forgot the @ of the Name annotation; so the Seam Groovy is:

          @Name("inSession")
          @Scope(ScopeType.SESSION)
          class InSession {

            String prop = 'Salut !'
           
            public InSession() {
              println "InSession called at ${new Date()} !"
            }

          }

          The first time the view is displayed, two instances of the InSession class are createed (its constructor is called twice!).

          The second point is that, as this component is hot deployed, if you change it and/or explode your Seam application, and navigate to the view, you get an exception from Seam:

          java.lang.IllegalStateException: Two components with the same name and precedence - component name: inSession, component classes: com.lsy.clink.visualizations.InSession, com.lsy.clink.visualizations.InSession

          Any idea about this? Is a Seam bug?


          Thank you,

          Bertrand.
          • 2. Re: Strange Groovy Seam component
            Will Piasecki Newbie

            Hello.


            I'm having the same problem: the component keeps getting recreated and can't save it's state (a println in the constructor is called all the time some action in page happens)


            Is this a bug? Does anyone know something about it?



            Thanks :)

            • 3. Re: Strange Groovy Seam component
              Yasser Hawari Newbie

              seam proxies your object to make it a seam component. it may create you object number of time especially in clusters. don't put ur initialization code in the constructor. leave the constructor empty and create another function that is annotated with @Create. this function will act as an initialization function and will be called once only.

              • 4. Re: Strange Groovy Seam component
                Will Piasecki Newbie

                Solved the problem, it was a dumb mistake of mine: didn't made the conversation start through 'filename.pages.xml' or through the @Begin/@End annotations.