0 Replies Latest reply on May 17, 2007 11:18 AM by Mathieu Avoine

    How to use the @Factory annotation?

    Mathieu Avoine Newbie

      Hi,

      I'm new to Seam and I'm trying to use the @Factory annotation to initialize the properties of a Managed Bean upon request of a jsf page, no matter if the request comes from a JSF context or not (ex. from another servlet).

      My bean is super simple (see included code below), it only has 2 properties (postDate and postText) which need to be initialized to a value fetched from the database. I'd like to make the initialization take place when the page is requested using a Factory method (myFactory). The page gets displayed but the method myFactory is never called. What am I doing wrong?

      Thanks!
      Math

      ...
      
      @Name("newsBean")
      @Scope(ScopeType.SESSION)
      public class NewsBean implements Serializable {
      
       private static final long serialVersionUID = 1L;
       @In
       ToolbarBean toolbarBean;
       @In
       SessionBean sessionBean;
       @Out(required=false)
       Date postDate;
       @Out(required=false)
       String postText;
      
       public String process(){
      
       try {
       // update toolbar
       toolbarBean.setCurrentReport(ToolbarBean.CURRENT_REPORT_NOT_SET);
       toolbarBean.setPrinterFriendlyPath("/dynamic/faces/dataview/newsPF.jsf");
       toolbarBean.setShowExportToExcel(false);
       toolbarBean.setReportName(TextResource.getTextResourceString(new TextKey("News"),null,sessionBean.getCurrentLocale()));
       toolbarBean.setRefreshAction("newsBean.process");
      
       Language language = LanguageDAO.getInstance().findByPk(sessionBean.getLanguageCode());
       News news = NewsService.getInstance().findCurrentNews();
       postDate = news.getNewsTime();
       postText = news.getNewsDescription().getText(language);
      
       } catch (Exception ex){
       MessageHandler.handleGenericException(ex);
       return "error";
       }
      
       return "success";
       }
      
       @Factory("postDate")
       public void myFactory(){
       process();
       }
      
      ...