0 Replies Latest reply on Jun 10, 2010 4:05 PM by shwetank

    Some times ModelPanel Open and Some times not Open

    shwetank







      hi All,
      
      Problem Description.
      There is a JTree Tag which is rendering  directory structure hierarchy(files and folders).
      But when i right click on node and choose create new folder option than , some times create folder model panel appear but some times not appear.
      
      This is my tree.xhtml code
      
      <h:form>
                          <h:outputText value="Location Tree" />
      
                          <a:outputPanel id="treeId" ajaxRendered="true">
                               <rich:tree style="width:300px" switchType="ajax" ajaxSingle="true"
                                    nodeSelectListener="#{locationTreeAction.processSelection}"
                                    ajaxSubmitSelection="true" id="pic">
                                    <rich:recursiveTreeNodesAdaptor roots="#{sourceRoots}" var="item"
                                         nodes="#{item.children}">
                                         <rich:treeNode icon="img/iconFolder.gif"
                                              iconLeaf="#{(item.type == 'node')? 'img/iconFolder.gif' : 'img/iconLeaf.gif'}">
                                              <h:outputText value="#{item.name}" />
      
      
                                              <rich:contextMenu event="oncontextmenu" attached="true"
                                                   submitMode="ajax" rendered="#{item.type == 'node'}">
      
      
                                                   <rich:menuItem  id="add#{item.id}" ajaxSingle="true">
                                                        <a:commandLink
                                                             action="#{locationTreeAction.getCreateNewFolderDialog(item)}"
                                                             reRender="addNewFolderPanel" style="margin-right: 5px;">
      
                                                             <h:outputText>New Folder #{item.id}</h:outputText>
                                                        </a:commandLink>
                                                   </rich:menuItem>
      
      
      
                                                   <rich:menuSeparator />
      
                                                   <rich:menuItem id="delete#{item.id}" ajaxSingle="true">
                                                        <a:commandLink
                                                             action="#{locationTreeAction.deleteFolder(item)}"
                                                             style="margin-right: 5px;">
      
                                                             <h:outputText>Delete #{item.id}</h:outputText>
                                                        </a:commandLink>
                                                   </rich:menuItem>
                                                   <rich:menuItem  id="upload#{item.id}" ajaxSingle="true">
                                                        <a:commandLink
                                                             action="#{locationTreeAction.getCreateUploadFileDialog(item)}"
                                                             reRender="uploadFilePanel" style="margin-right: 5px;">
      
                                                             <h:outputText>Uplode #{item.id}</h:outputText>
                                                        </a:commandLink>
                                                   </rich:menuItem>
      
                                                   <rich:menuSeparator />
      
      
                                              </rich:contextMenu>
      
                                              <rich:contextMenu event="oncontextmenu"   attached="true"
                                                   submitMode="ajax" rendered="#{item.type != 'node'}">
      
                                                   <rich:menuItem id="fdownload#{item.id}" ajaxSingle="true">
                                                        <a:commandLink
                                                             action="#{locationTreeAction.downloadFile(item)}"
                                                             reRender="treeId" style="margin-right: 5px;">
      
                                                             <h:outputText>Download #{item.id}</h:outputText>
                                                        </a:commandLink>
                                                   </rich:menuItem>
                                                   <rich:menuItem id="fdelete#{item.id}" ajaxSingle="true">
                                                        <a:commandLink
                                                             action="#{locationTreeAction.deleteFolder(item)}"
                                                             style="margin-right: 5px;">
      
                                                             <h:outputText>Delete #{item.id}</h:outputText>
                                                        </a:commandLink>
                                                   </rich:menuItem>
      
                                              </rich:contextMenu>
      
                                         </rich:treeNode>
                                    </rich:recursiveTreeNodesAdaptor>
                               </rich:tree>
                          </a:outputPanel>
                     </h:form>
                </rich:panel>
      
      
      
      
                <a:outputPanel id="addNewFolderPanel">
                     <rich:modalPanel id="addNewFolderMp" styleClass="modalPanel" top="10"
                          autosized="true" minWidth="600" minHeight="200"
                          headerClass="modalPanel-header"
                          keepVisualState="#{locationTreeAction.showOverlay}"
                          controlsClass="modalPanel-controls">
                          <f:facet name="header">
                               <h:outputText value="Add/Edit Ticket" />
                          </f:facet>
                          <f:facet name="controls">
                               <h:form>
                                    <a:commandLink action="#{locationTreeAction.closeOverlay}"
                                         oncomplete="Richfaces.hideModalPanel('addNewFolderMp')">
                                         <h:outputText>Close</h:outputText>
      
                                    </a:commandLink>
                               </h:form>
                          </f:facet>
                          <s:div styleClass="modalPanel-panelGrid-container-div">
                               <h:panelGrid styleClass="modalPanel-panelGrid">
                                    <a:outputPanel ajaxRendered="true">
                                         <h:message styleClass="message" for="addNewFolderPanel" />
                                    </a:outputPanel>
                                    <a:form id="addNewFolderForm">
                                         <h:panelGrid columns="1" border="0"
                                              columnClasses="formLabel,formValue" rowClasses="formLabel">
      
                                              <s:decorate id="unameDecoration" template="layout/edit.xhtml">
                                                   <ui:define name="label">Folder Name<h:outputText
                                                             class="asterik" />
                                                   </ui:define>
                                                   <h:inputText id="foldername" value="#{location.name}"
                                                        required="true" requiredMessage="Please Enter Folder Name" />
                                              </s:decorate>
      
      
                                         </h:panelGrid>
      
                                         <h:panelGrid width="330" id="save">
                                              <a:commandButton id="saveNewFolder" value="Create"
                                                   reRender="addNewFolderPanel,treeId"
                                                   action="#{locationTreeAction.addNewFolder}"
                                                   onclick="this.disabled=true" style="margin: 3px"
                                                   oncomplete="hideModalPanel('addNewFolderMp'),this.disabled=false" />
      
                                         </h:panelGrid>
                                    </a:form>
                               </h:panelGrid>
                          </s:div>
                     </rich:modalPanel>
                </a:outputPanel>
                <a:outputPanel id="uploadFilePanel">
                     <rich:modalPanel id="uploadMp" styleClass="modalPanel" top="10"
                          autosized="true" minWidth="600" minHeight="200"
                          headerClass="modalPanel-header"
                          keepVisualState="#{locationTreeAction.showOverlay}"
                          controlsClass="modalPanel-controls">
                          <f:facet name="header">
                               <h:outputText value="Upload File" />
                          </f:facet>
                          <f:facet name="controls">
                               <h:form>
                                    <a:commandLink action="#{locationTreeAction.closeOverlay}"
                                         oncomplete="Richfaces.hideModalPanel('uploadMp')">
                                         <h:outputText>Close</h:outputText>
      
                                    </a:commandLink>
                               </h:form>
                          </f:facet>
                          <s:div styleClass="modalPanel-panelGrid-container-div">
                               <h:panelGrid styleClass="modalPanel-panelGrid">
                                    <a:outputPanel ajaxRendered="true">
                                         <h:message styleClass="message" for="uploadFilePanel" />
                                    </a:outputPanel>
      
      
      
      
      
                                    <h:form id="uploadFileForm" enctype="multipart/form-data">
                                         <h:panelGrid columns="1" border="0"
                                              columnClasses="formLabel,formValue" rowClasses="formLabel">
      
                                              <s:decorate id="file" template="layout/edit.xhtml">
                                                   <ui:define name="label">Folder Name<h:outputText
                                                             class="asterik" />
                                                   </ui:define>
                                                   <h:inputText id="foldername" value="#{location.name}"
                                                        required="true" requiredMessage="Please Enter Folder Name" />
                                                   <s:fileUpload data="#{locationTreeAction.fileData}"
                                                        fileName="#{locationTreeAction.fileName}" style="height:20px;" />
      
      
                                              </s:decorate>
      
      
                                         </h:panelGrid>
      
                                         <h:panelGrid width="330" id="saveFile">
                                              <h:commandButton id="saveNewFolder" value="Upload"
                                                   oncomplete="Richfaces.hideModalPanel('uploadMp')"
                                                   action="#{locationTreeAction.persistFileToSystem}" />
      
                                         </h:panelGrid>
                                    </h:form>
                               </h:panelGrid>
                          </s:div>
                     </rich:modalPanel>
                </a:outputPanel>
      
      
      
      
      My LocationTreeAction.java code 
      
      
      @Stateful
      @Name("locationTreeAction")
      @Scope(ScopeType.CONVERSATION)
      public class LocationTreeAction implements LocationTree {
      
           @PersistenceContext(type = PersistenceContextType.EXTENDED)
           EntityManager entityManager;
      
           List<Location> locationList = null;
      
           @In
           FacesMessages facesMessages;
      
           private boolean showOverlay = false;
      
           @BypassInterceptors
           public boolean isShowOverlay() {
                return showOverlay;
           }
      
           public void setShowOverlay(boolean showOverlay) {
                System.out.println("show Overlay");
                this.showOverlay = showOverlay;
           }
      
           public void closeOverlay() {
                showOverlay = false;
           }
      
           @In(required = false)
           private Location location;
      
           public Integer getId() {
                return id;
           }
      
           public void setId(Integer id) {
                this.id = id;
           }
      
           @In(required = false)
           @Out(required = false)
           private Location loc;
      
           public Location getLoc() {
                return loc;
           }
      
           public void setLoc(Location loc) {
                this.loc = loc;
           }
      
           @In(required = false)
           private Integer id;
      
           @org.jboss.seam.annotations.datamodel.DataModel
           List<Location> list1 = null;
      
           private Location selectedLocation;
      
           @Factory(autoCreate = true, scope = ScopeType.CONVERSATION)
           public synchronized List<Location> getSourceRoots() {
      
                if (locationList == null) {
                     locationList = entityManager.createQuery(
                               "select l from Location l where l.parent is null and l.status =0 ")
                               .getResultList();
                }
      
                System.out.println("locationList.size " + locationList.size());
      
                return locationList;
      
           }  
      
           @Factory("list1")
           public void showlist() {
      
                if (list1 == null) {
                     list1 = entityManager.createQuery(
                               "select l from Location l where l.parent is null and l.status =0")
                               .getResultList();
                }
      
                System.out.println("locationList.size " + list1.size());
      
           }
      
           public void processSelection(final NodeSelectedEvent event) {
      
                final HtmlTree tree = (HtmlTree) event.getComponent();
                selectedLocation = (Location) tree.getRowData();
      
                System.out.println("Selected Node is " + selectedLocation.toString());
      
           }
          @Begin(join = true)
           public void getCreateNewFolderDialog(Location loc1) {
                System.out.println(loc1.getId());
                loc = entityManager.find(Location.class, loc1.getId());
                          System.out.println("Overlay true");
                showOverlay = true;
           }
      
           public void addNewFolder(){
                System.out.println(location.getName());
                System.out.println("add new folder");
      //          System.out.println(loc.getId());
      
                // location=entityManager.find(location.class,id);
                location.setParent(loc);
      
                location.setType("node");
      
                entityManager.persist(location);
      
                facesMessages.addFromResourceBundle("Folder has been created");
                showOverlay = false;
           }
           
      
           public void deleteFolder(Location loc1){
                loc1.setStatus((int )loc1.getId());
                loc1.setParent(null);
                System.out.println("&&&&&&&&&&&&&&&&&&&&&&&&&&"+loc1.getId() +"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
                entityManager.merge(loc1);
           }
           @Begin(join = true)
           public void getCreateUploadFileDialog(Location loc1){
                System.out.println("File upload Menu");
                loc = entityManager.find(Location.class, loc1.getId());
                showOverlay = true;
           }
           public void uploadFile(Location loc1){
                System.out.println("File save upload Menu");
           }
           
           @Logger
           private Log log;
           
           @Resource
           SessionContext ctx;
           
           private byte[] fileData;
           private String fileName;
           
           public byte[] getFileData() {
                return fileData;
           }
      
           public void setFileData(byte[] fileData) {
                this.fileData = fileData;
           }
      
           public String getFileName() {
                return fileName;
           }
      
           public void setFileName(String fileName) {
                this.fileName = fileName;
           }
           
           public void persistFileToSystem() {
           
                try {
                     if (fileName.equals("") || fileData.length == 0) {
                          facesMessages
                                    .addFromResourceBundle("In valid");
                     } else {
                          Integer extPos;
                          extPos = fileName.lastIndexOf(".");
                          String fileType = fileName.substring(extPos);
                          log.info("before validating fileType Type: " + fileType); 
                          if ((fileType.equalsIgnoreCase(".jpg")) || (fileType.equalsIgnoreCase(".png"))
                                    || (fileType.equals(".bmp")) || (fileType.equals(".txt"))|| (fileType.equals(".jpeg"))) {
      
                               log.info("After validating fileType");
                               StringBuffer dirName = new StringBuffer("");
                               SeamResourceBundle sRB = new SeamResourceBundle(); 
                               // getting path from resource bundle
                               dirName.append(sRB.getString("imageUploadPath"));
                               Calendar calendar = Calendar.getInstance();
                               @SuppressWarnings("unused")
                               //mestamp currentTimestamp = new java.sql.Timestamp(calendar.getTime().getTime());
                               long time=calendar.getTime().getTime();
                          
                               dirName.append(fileName+"-");
                               dirName.append(time);
                               dirName.append(fileType);
                               File saveTo = new File(dirName.toString());
                               //File saveTo = new File(dirName.toString().replace(" ", "").replace("-", "").replace(":", ""));
      
                               log.info("before writing");
                               log.info("File Data : " + fileData);
                               // Writing file
                               FileOutputStream writer = new FileOutputStream(saveTo);
                               writer.write(fileData); 
                               // new file name
      
                               String tempFileName="file-"+time+fileType;
                               log.info("logoname");
                               // setting companyLogo
                               location.setName(fileName);
                               log.info("filename");
                               location.setParent(loc);
                               log.info("setlocation");
                               location.setType("file");
                               log.info("sefile");
                               
                               location.setS3name(tempFileName);
                               // peristing company logo
                               entityManager.persist(location);
                               showOverlay = false;
                               
                               
                              S3conn s3 = new S3conn();
                              String bucketName = "seamFramework.newbucket12345";
                              String key = "file-"+time;
                              bucketName = bucketName.toLowerCase();
                              System.out.println("$$$$$$$$$$$$$$$$$$$ Bucket Name : "+bucketName);
                              //s3.createBuckets(bucketName);
                              s3.uploadObjects(bucketName,key,fileType,fileData);
                              //s3.listObjects(bucketName);
                              //s3.downloadObjects(bucketName,key);
                     
                               facesMessages
                                         .addFromResourceBundle("File have been uploded successfully."); 
                          } else {
                               facesMessages
                                         .addFromResourceBundle("message.companyLogo.wrong.extention");
                               log.info("extention validation failed");
                          }
                     }
                } catch (Exception e) {
                     log.info("Exception===" + e.getMessage());
                     ctx.setRollbackOnly();
      
                }
                
                
           }
      
           @Destroy
           @End
           @Remove
           public void destroy() {
           }
      
      
      Thanks in Advance!
      shwetank
      
      }