5 Replies Latest reply on Jul 5, 2007 11:58 AM by bdillon

    Using non-EJB annotated POJO as backing bean

    bdillon

      Hi,

      I am trying use non-EJB annotated POJOs as my seam backing beans, but I when I access the object using

      <h:outputText value="#{FirstPageBB.name}"/>

      I get the following error;

      javax.servlet.ServletException: Cannot get value for expression '#{FirstPageBB.name}'
      javax.faces.webapp.FacesServlet.service(FacesServlet.java:152)

      My bean is annotated and declared like;

      @Scope(ScopeType.SESSION)
      @Name("FirstPageBB")
      public class FirstPageBB implements Serializable {

      Since the example/test I am working does not rely on the data being persisted I wanted to get this working without using EJB or JPA. Can POJOs be used as backing beans with seam or is this limited to Entitys (either EJB or POJOs) ?

      Thanks,

      Brian

        • 1. Re: Using non-EJB annotated POJO as backing bean
          azalea

          Do you define a getter method for "name" property?

          • 2. Re: Using non-EJB annotated POJO as backing bean
            bdillon

            HI,

            The getter method is;


            public String getName() {
            System.out.println(" FirstPageBB.getName() > "+name);
            return name;
            }

            I can see in Tomcat the following;

            Initialising FirstPageBB !
            FirstPageBB.getName() > initialValue
            16:06:16,142 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
            javax.faces.el.EvaluationException: Cannot get value for expression '#{FirstPage
            BB.name}'
            at org.apache.myfaces.el.ValueBindingImpl.getValue(ValueBindingImpl.java
            :402)
            at javax.faces.component.UIOutput.getValue(UIOutput.java:77)
            at org.apache.myfaces.shared_impl.renderkit.RendererUtils.getStringValue
            (RendererUtils.java:217)


            Thanks,

            Brian

            • 3. Re: Using non-EJB annotated POJO as backing bean
              monkeyden

              Could you post the code for the backing bean?

              • 4. Re: Using non-EJB annotated POJO as backing bean
                bdillon

                Hi,

                Here is the code;

                package com.bd.test;

                import java.io.Serializable;

                import org.jboss.seam.annotations.*;
                import org.jboss.seam.ScopeType;

                @Scope(ScopeType.SESSION)
                @Name("FirstPageBB")
                public class FirstPageBB implements Serializable {

                @Out
                private SecondPageParameters params;

                private String name = "initValue";

                public FirstPageBB() {
                System.out.println(" Initialising FirstPageBB !");
                }


                public String getName() {
                System.out.println(" FirstPageBB.getName() > "+name);
                return name;
                }

                public void setName(String name) {
                System.out.println(" FirstPageBB.setName("+name+")");
                this.name = name;
                }

                //Action Button
                public String submit() {
                System.out.println(" FirstPageBB.submit() called ");
                params = new SecondPageParameters();
                params.setName(name);
                return "NavigationScen1";
                }
                }

                Thanks,

                Brian

                • 5. Re: Using non-EJB annotated POJO as backing bean
                  bdillon

                  Hi,

                  I tried removing the @out parameter and I can get the page to display. Is there something specific I should have done for this ?

                  Thanks,

                  Brian