1 Reply Latest reply on May 7, 2009 1:58 PM by khalid Horri

    data not populate in the form with edit action

    khalid Horri Newbie

      Hello,
      I have some problems with my application:
      1- When I click to edit a row from the datatable, the form is shown but is empty w/out data
      2- If I add new record the datatable is not updated


      the SessionBean:


      @Stateless
      @Name("manageDocument")
      @Scope(ScopeType.SESSION)
      public class ManageDocumentAction implements ManageDocument {
      
           private static String  documentName;
           @In(required=false) 
           private Document document;
           @PersistenceContext
           private EntityManager em;
           
           @DataModel
           private List<Theme> themes;
           @DataModel
           private List<Directory> directories;
           @DataModel
           private List<Document> documentList;
           
           @Override
           public String addDocument() {
                this.document.setDocument(this.getDocumentName());
                em.persist(document);
                return "/managedocument.xhtml";
      
           }
           
           
           @SuppressWarnings("unchecked")
           @Factory("directories")
           public void findDirectories() {
                directories = em.createQuery("FROM Directory d").getResultList();
                
           }
           @SuppressWarnings("unchecked")
           @Factory("themes")
           public void findThemes() {
                themes = em.createQuery("FROM Theme t").getResultList();
                
           }
           
           
           @Remove
           public void destroy() {}
      
      
           @Override
           public void listener(UploadEvent event) throws IOException {
                
                UploadItem item = event.getUploadItem();
                File srFile = item.getFile();
                String dtFile = PropertiesRniim.getProperty("DOC_REPO")+File.separatorChar+item.getFileName();
                FileUtils.copyfile(srFile.getAbsolutePath(), dtFile);
                this.setDocumentName(dtFile);
                 
               
      
           }
      
      
           public String getDocumentName() {
                return documentName;
           }
      
      
           public void setDocumentName(String documentName) {
                this.documentName = documentName;
           }
      
      
           @SuppressWarnings("unchecked")
           @Factory("documentList")
           public void findDocuments() {
                this.documentList = em.createQuery("from Document d").getResultList();
                
           }
      
      
           @Override
           public String editDocument(Document doc) {
                this.document = doc;
                return "/adddocument.xhtml";
           }
      
      
           @Override
           public String addOrUpdateDocument() {
                if(document.getIdDoc()== 0)
                     return this.addDocument();
                else
                     return this.updateDocument();
                
           }
      
      
           @Override
           public String updateDocument() {
                
                String update ="UPDATE Document d SET d.title='"+this.document.getTitle()+"' where d.idDoc="+this.document.getIdDoc();
                em.createQuery(update);     
                return "/managedocument.xhtml";
           }
      
      
           @Override
           public String deleteDocument(Document doc) {
                String delete ="DELETE FROM Document d WHERE d.idDoc='"+doc.getIdDoc()+"'";
                em.createQuery(delete);
                return "/managedocument.xhtml";
           }
           
           
      }


      the editpage.xhtml


      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <ui:composition xmlns="http://www.w3.org/1999/xhtml"
          xmlns:s="http://jboss.com/products/seam/taglib"
          xmlns:ui="http://java.sun.com/jsf/facelets"
          xmlns:f="http://java.sun.com/jsf/core"
          xmlns:h="http://java.sun.com/jsf/html"
          xmlns:rich="http://richfaces.org/rich"
          xmlns:a4j="http://richfaces.org/a4j"
          template="layout/template.xhtml">
      
                <ui:define name="body">
      
          <h:form>
      
                  <f:facet name="header">Ajouter un nouveau document</f:facet>
      
      
                  <div class="dialog">
                      <h:panelGrid columns="2" rowClasses="prop" columnClasses="name,value">
                          <h:outputLabel for="title">Titre</h:outputLabel>
                          <h:inputText id="title"
                                    value="#{document.title}"/>
                             
                          <h:outputLabel for="ref">reference</h:outputLabel>
                          <h:inputText id="ref"
                                      value="#{document.ref}"/>
                          
                          <h:outputLabel for="summary">resume</h:outputLabel>
                          <h:inputTextarea id="summary"
                                      value="#{document.summary}"/>
                                     
                           <h:outputLabel for="theme">theme</h:outputLabel>
                          <h:selectOneMenu id="theme" 
                                      value="#{document.theme}">
                                      
                              <s:selectItems value="#{themes}" 
                                             var="theme"
                                             label="#{theme.themeName}"/>
                                      <s:convertEntity />       
                          </h:selectOneMenu>
                           
                          <h:outputLabel for="keyWords">Mot cle</h:outputLabel>
                          <h:inputText id="keyWords"
                                      value="#{document.keyWords}"/>
                                      
                          <h:outputLabel for="directory">repertoire</h:outputLabel>            
                          <h:selectOneMenu id="directory" 
                                      value="#{document.directory}">
                                     
                              <s:selectItems value="#{directories}" 
                                             var="directory"
                                             label="#{directory.directoryName}"/>
                                    <s:convertEntity />          
                          </h:selectOneMenu>
                          
                    <h:outputLabel for="directory">Document</h:outputLabel>
                           <rich:fileUpload fileUploadListener="#{manageDocument.listener}"
                      id="upload" immediateUpload="true">
                      <a4j:support event="onuploadcomplete" reRender="info" />
                      <f:facet name="label">
                            <h:outputText value="{_KB}KB from {_MB}MB uploaded --- {mm}:{ss}" />
                         </f:facet>
                      
                  </rich:fileUpload> 
                  
                      </h:panelGrid> 
                  </div>
               <h:inputHidden id="id" value="#{document.idDoc}"/>
              <div class="actionButtons">
                  <h:commandButton value="Valider" action="#{manageDocument.addOrUpdateDocument}"/>
              </div>
      
          </h:form>
      
       </ui:define>
      </ui:composition>


      the managedocument.xhtml


      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets"
            xmlns:rich="http://richfaces.org/rich"
            xmlns:s="http://jboss.com/products/seam/taglib"
            xmlns:a="http://richfaces.org/a4j">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
           <ui:composition template="layout/template.xhtml">
                <ui:define name="body">
      
              <h1>Bienvenue </h1>
              <rich:panel>
                  <h:panelGrid columns="2">
                  
                         <h:graphicImage value="/img/document_new.png" alt="Seam logo"/>
                         <h:outputLink value="adddocument.seam">
                              <f:verbatim>Ajouter documents</f:verbatim>
                                                      
                         </h:outputLink>
                      
                  </h:panelGrid>
              </rich:panel>
             
           <h:form>
              <rich:dataTable value="#{documentList}" var="doc"  columnClasses="center"
              rows="15" reRender="ds">
                  <f:facet name="header">
                      <h:outputText value="Ref"/>
                  </f:facet>
                  <rich:column sortBy="#{doc.ref}"> 
                      <f:facet name="header">
                          <h:outputText value="Ref"/>
                      </f:facet>
                      <h:outputText value="#{doc.ref}"/>
                  </rich:column> 
                  <rich:column sortBy="#{doc.title}">
                      <f:facet name="header">
                          <h:outputText value="titre"/>
                      </f:facet>
                      <h:outputText value="#{doc.title}"/> 
                  </rich:column>
                  <rich:column>
                      <f:facet name="header">
                          <h:outputText value="Mot cle"/>
                      </f:facet>
                      <h:outputText value="#{doc.keyWords}"/> 
                  </rich:column>
                  <rich:column>
                      <f:facet name="header">
                          <h:outputText value="Resumé"/>
                      </f:facet>
                      <h:outputText value="#{doc.summary}"/> 
                  </rich:column>
                  <rich:column>
                      <f:facet name="header">
                          <h:outputText value="Lien"/>
                      </f:facet>
                      <h:outputText value="#{doc.document}"/> 
                  </rich:column>
                  <rich:column>
                      <f:facet name="header">
                          <h:outputText value="Theme"/>
                      </f:facet>
                      <h:outputText value="#{doc.theme.themeName}"/> 
                  </rich:column>
                  <rich:column>
                      <f:facet name="header">
                          <h:outputText value="Mot cle"/>
                      </f:facet>
                      <h:outputText value="#{doc.directory.directoryName}"/> 
                  </rich:column>
                  <rich:column>
                     <f:facet id="ActionFacet" name="header">Action</f:facet>
                     <s:link id="viewDoc" value="Modifier" action="#{manageDocument.editDocument(doc)}"/>&ensp;&ensp;
                     <s:link id="removeDoc" value="Supprimer" action="#{manageDocument.deleteDocument(doc)}"/>
                  </rich:column>
                  <f:facet name="footer">
                      <rich:datascroller id="ds"></rich:datascroller>
                  </f:facet>
              </rich:dataTable>
          </h:form>
          </ui:define>
           </ui:composition>
      
      </html>


      please help me


      Regards HORRI