4 Replies Latest reply on Jun 26, 2008 12:31 PM by mail.micke

    JavaBeans and SEAM Actions

    coolex

      Hi!


      While reading the SEAM tutorials I got confused with the term JavaBean. Is this the same like the SEAM Actions? Or what does JavaBeans in the SEAM tutorials mean.
      I'm asking this because I want to rebuild the examples myself.


      Thx.

        • 1. Re: JavaBeans and SEAM Actions
          norman

          JavaBean means POJO - just a regular Java object.  (as opposed to an EJB3 component)

          • 2. Re: JavaBeans and SEAM Actions
            coolex

            Aaah, ok. Thank you very much.
            Do I have to make some configuration in SEAM to make them available in my JSF files, e.g. to make entries in the components.xml? Should I create an interface like SEAM does it for actions?
            Do I have to create them in a special directory?
            I'm asking that question because I created a simple Java File that just return a single String value, lets say Hello World. This value I wanted to print in my JSF Files but I don't see anything.


            • 3. Re: JavaBeans and SEAM Actions
              coolex

              OK, I solved the problem. Now my simple (POJO) JavaBean does what I want: simple printout of a string on my JSF site.


              BUT now I'm really confused about the difference of JavaBeans and SEAM Actions? The only difference I see is the interface that is created with when you create a new action. Additionally I wasn't able to make simple printouts out of the action in my JSF site like I can do it with simple JavaBeans.


              Please give some hints.

              • 4. Re: JavaBeans and SEAM Actions
                mail.micke

                Hi


                I think you need to pick up a book and/or read some tutorials on this subject!


                But here is a little bit more information for you.


                Actions in JSF are typically methods on beans called backing beans (or more usually components in Seam).


                The backing bean (typically called backing bean because it backs a page with data) might contain POJOs or simple Objects which are accessed when rendering the page.


                A very simple Example:


                (not compiled so probably full of errors)


                @Name("hellWorldBacking")
                @Scope(ScopeType.PAGE)
                public class HelloWorldBacking implements Serializable{
                
                   private MyBean myBean = new MyBean();
                
                   public String myAction(){
                      System.out.println("Doing something with myBean: " +myBean.getId() );
                      return "";
                   }
                
                   //skipping code for getter/setter for myBean
                }
                




                public MyBean{
                  private long id;
                
                  //skipping code for getter/setter for id
                }
                



                The page using the backing bean could look like this:



                <p>
                Value of the id property of myBean is : #{helloWorldBacking.myBean.id}
                </p>
                <h:form>
                  <h:inputText value="#{helloWorldBacking.myBean.id}"/>
                  <h:commandButton value="Set id" action="#{helloWorldBacking.myAction}"/>
                </h:form>