3 Replies Latest reply on Dec 4, 2007 3:18 AM by amorfis

    What to do to make @Factory method working?

    amorfis

      Hi,

      I have an enterprise application, and web module inside. In this module, I have some jsf page, in which I am referring to #{article.title}. I have also ArticlesManagerBean with @Factory("article") method and private variable article. In this method I am initializing variable. It should be called if I call #{article.title} in my JSP, but it is not. What can be the reason? I have done it like in example 1.11 from http://docs.jboss.com/seam/1.2.1.GA/reference/en/html/tutorial.html.

      Best regards
      Paweł Stawicki

        • 1. Re: What to do to make @Factory method working?
          andygibson

          Do you have your bean setup as a seam component with a @Name annotation? It should be like :

          @Name("articleManager")
          @Scope(ScopeType.Conversation)
          public class ArticlesManagerBean ....... {
          
           @Factory("article")
           public Article getArticle() {
           <init code if necessary>
           return article
           }
          }
          


          Can you reference your bean from the page?

          Try putting in something like :

          <h:outputText value="#{articlesManager}"/>
          


          to see if it can pick up your articles manager bean.

          Also, is your getArticles() method defined in your interface that the bean implements?

          Other than that, if you post some code, it should be easy to spot. Did you create the app with Seam Gen, and if not, do you have anything working that would indicate whether the app is set up properly?

          Cheers,

          Andy

          • 2. Re: What to do to make @Factory method working?
            amorfis

             

            "Andy Gibson" wrote:
            Do you have your bean setup as a seam component with a @Name annotation? It should be like :

            @Name("articleManager")
            @Scope(ScopeType.Conversation)
            public class ArticlesManagerBean ....... {
            
             @Factory("article")
             public Article getArticle() {
             <init code if necessary>
             return article
             }
            }
            



            Yes, I have something exactly like this.


            Can you reference your bean from the page?

            Try putting in something like :

            <h:outputText value="#{articlesManager}"/>
            


            to see if it can pick up your articles manager bean.


            I just tried, and it doesn't work. Looks like my app doesn't see this bean.


            Also, is your getArticles() method defined in your interface that the bean implements?

            Yes, it is.


            Other than that, if you post some code, it should be easy to spot. Did you create the app with Seam Gen, and if not, do you have anything working that would indicate whether the app is set up properly?


            The code is exaclty like in your examples. I am using eclipse and this project is downloaded from CVS of my friend, so I didn't generate it with Seam Gen. My task is to add web module. Application seems to be working, I can access jsp, just expressions like #{articlesManager} evaluate to empty string. If I put some gibberish there (like #{asefbadfe}) there is also empty string, so it behaves like this variables are not existing.

            I have components.xml like this:
            <components xmlns="http://jboss.com/products/seam/components"
             xmlns:core="http://jboss.com/products/seam/core">
             <core:init jndi-pattern="@jndiPattern@"/>
            </components>
            

            in WEB-INF. There is also faces-config.xml:
            <?xml version="1.0" encoding="UTF-8"?>
            <faces-config version="1.2"
             xmlns="http://java.sun.com/xml/ns/javaee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd">
            
             <!-- Facelets support -->
             <application>
             <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
             </application>
            
            </faces-config>
            

            and of course web.xml:
            <?xml version="1.0" encoding="UTF-8"?>
            <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
             <display-name>inka-web</display-name>
             <welcome-file-list>
             <welcome-file>index.html</welcome-file>
             <welcome-file>index.htm</welcome-file>
             <welcome-file>index.jsp</welcome-file>
             <welcome-file>default.html</welcome-file>
             <welcome-file>default.htm</welcome-file>
             <welcome-file>default.jsp</welcome-file>
             </welcome-file-list>
             <listener>
             <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
             </listener>
             <context-param>
             <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
             <param-value>client</param-value>
             </context-param>
             <servlet>
             <servlet-name>Faces Servlet</servlet-name>
             <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
             <load-on-startup>1</load-on-startup>
             </servlet>
             <servlet-mapping>
             <servlet-name>Faces Servlet</servlet-name>
             <url-pattern>*.jsp</url-pattern>
             </servlet-mapping>
            </web-app>
            


            If you need any other data I can put it here. I just don't know what is wrong.

            Best regards
            Pawel Stawicki

            Cheers,

            Andy

            • 3. Re: What to do to make @Factory method working?
              amorfis

              Ok, it looks like seam was not even started. I had put jboss-seam.jar file to web module to WEB-INF/lib. Now when I moved it to main project it is starting, but another problem occurs. When seam tries to instantiate it's component (one with @Name annotation) I get exception with "No application context active" message.

              Best regards
              Pawel Stawicki