2 Replies Latest reply on Aug 25, 2009 4:58 PM by Ranju Vaidya

    Error with Seam converations

    Ranju Vaidya Newbie

      Hello,


            I am new to Seam and currently working on an application using Seam 2.1.2 deployed on JBoss 4.2.2 . I am trying to implement a flow where the first page  shows the list of available templates. Clicking on any of the available templates takes the user to the edit screen with update option. I have tried to implement this using Seam conversation with a POJO Action Handler.
      Here is the code snip of the action





      @Name("templateAction")
      @Restrict("#{s:hasRole('Admin')}")
      @Scope(ScopeType.CONVERSATION)
      public class TemplateAction implements Serializable
      {
           /**
            * 
            */
           private static final long serialVersionUID = 1L;
      
      
           @Create
           public void init() {
                getLanguages();
           }
           
           @Logger private Log log;
      
      
           @In
           Users user;
           
           @In("#{commonService}")
           CommonServicesImpl commonServiceImpl;
           
           @DataModel
           private List<Template> templateList = null;
      
           @DataModelSelection
           Template templateSelection;
           
           
           Template templateObject;
           
           
           public Template getTemplateObject() {
                return templateObject;
           }
      
           public void setTemplateObject(Template templateObject) {
                this.templateObject = templateObject;
           }
           
      
           @Factory(value = "templateList")
           @Begin(join=true)
            public void getTemplates()
           {
      
                log.info("TemplateAction.getTemplates action called ");
                try {
      
                 templateList = commonServiceImpl.getTemplateList();
      
                     log.info("Searchlist Size :" + templateList.size());
      
                } catch (ServiceException exception) {
                     log.error(exception);
                }
      
           }
      
          public String editTemplate()
          {
           log.info("templateAction.editTemplate action called");
           templateObject = templateSelection;
           return "edit";
          }
           
             
          @End
          public String updateTemplate()
          {
               log.info("templateAction.updateTemplate action called");
               
              return "success";
          }
      
      }



      The conversation begins with the search and ends with update or cancel.


      Here is the snip of  edit xhtml




      <h:panelGrid id="editPanel" columns="2" rowClasses="prop" rendered="#{!empty templateAction.templateObject.id}" style="width : 600px;">
                               
                               <h:outputLabel for="template" styleClass="label">
                                    <h:outputText id="templateText"
                                         value="#{messages['template.template']}" />
                               </h:outputLabel>
                               <s:decorate>
                                    <f:facet name="afterInvalidField">
                                         <s:message styleClass="requiredMsg" />
                                    </f:facet>
                                    <h:inputText id="templateValue" required="true"
                                         value="#{templateAction.templateObject.name}" styleClass="text" />
                               </s:decorate>
      
                               <h:outputLabel for="headerURL" styleClass="label">
                                    <h:outputText id="headerURLText"
                                         value="#{messages['template.headerurl']}" />
                               </h:outputLabel>
                               <s:decorate>
                                    <f:facet name="afterInvalidField">
                                         <s:message styleClass="requiredMsg" />
                                    </f:facet>
                                    <h:inputText id="headerURLValue" required="true"
                                         value="#{templateAction.templateObject.headUrl}" styleClass="text" />
                               </s:decorate>               
      
                               <f:facet name="footer">
                                    <h:panelGroup style="display:block; text-align:right">
                                         <rich:separator />
                                         <h:commandButton id="templateEdit" styleClass="actionbutton"
                                              value="Update Template" action="#{templateAction.updateTemplate}">
                                         </h:commandButton>
                                    </h:panelGroup>
                               </f:facet>
      
                          </h:panelGrid>





      Everything works fine till the edit page, however when I click update, throws the error



      14:21:54,040 WARN  [lifecycle] /pages/editTemplate.xhtml @42,74 value="#{templateAction.templateObject.id}": Target Unreachable, 'templateObject' returned null on 'TemplateAction_$$_javassist_seam_3'
      javax.el.PropertyNotFoundException: /pages/editTemplate.xhtml @42,74 value="#{templateAction.templateObject.id}": Target Unreachable, 'templateObject' returned null on 'TemplateAction_$$_javassist_seam_3'


      and shows the same page with all values blank.


      With some debugging what I find is that another instance of the templateAction is created when I click Update and then destroyed , even though the first (original)instance is still available in the conversation context.





      14:21:24,650 INFO  [TemplateAction] ******TemplateAction Created******:TemplateAction@4b9e08
      14:21:24,650 INFO  [TemplateAction] TemplateAction.getTemplates action called - Search called
      14:21:24,682 INFO  [TemplateAction] Searchlist Size :1
      14:21:24,682 INFO  [TemplateAction] CONVERSATION Started
      14:21:24,682 INFO  [TemplateAction] id: 7; isLongRunning true; viewId: /pages/template.xhtml
      14:21:31,556 INFO  [TemplateAction] templateAction.editTemplate action called -  Edit page
      14:21:53,993 INFO  [TemplateAction] ******TemplateAction Created******:TemplateAction@15f7447 - when "Update" is clicked
      
      14:21:54,040 WARN  [lifecycle] /pages/editTemplate.xhtml @42,74 value="#{templateAction.templateObject.id}": Target Unreachable, 'templateObject' returned null on 'TemplateAction_$$_javassist_seam_3'
      javax.el.PropertyNotFoundException: /pages/editTemplate.xhtml @42,74 value="#{templateAction.templateObject.id}": Target Unreachable, 'templateObject' returned null on 'TemplateAction_$$_javassist_seam_3'
       
      14:21:54,040 ERROR [lifecycle] JSF1054: (Phase ID: PROCESS_VALIDATIONS 3, View ID: /pages/editTemplate.xhtml) Exception thrown during phase execution: javax.faces.event.PhaseEvent[source=com.sun.faces.lifecycle.LifecycleImpl@18925c9]
      14:21:54,072 INFO  [TemplateAction] ******TemplateAction Destroyed******:TemplateAction@15f7447





      Any ideas why this is happening ? Is this the reason for the error or is it something else that I am missing ?


      Any help will be greatly appreciated.


      -Thanks