Return-Path: X-Original-To: apmail-myfaces-users-archive@www.apache.org Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id CB368DEEE for ; Mon, 19 Nov 2012 23:46:02 +0000 (UTC) Received: (qmail 94441 invoked by uid 500); 19 Nov 2012 23:46:02 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 94378 invoked by uid 500); 19 Nov 2012 23:46:01 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Delivered-To: moderator for users@myfaces.apache.org Received: (qmail 32805 invoked by uid 99); 19 Nov 2012 17:30:21 -0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of darkarena@gmail.com designates 209.85.210.53 as permitted sender) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=wh6fWlyXUt5Dejmcxdr0cJe58X2wMUfjd2aOIkq/KAA=; b=hkKahebRhGJR+2IGzu+SpIkxsNP31Oi4qHXnJ7ulcj9krGqAF8ICwg2V440Bz/MBVX I2+gRcdEftsmCFyfIFgGBJf3D2JkHhKPsw9JQtLg79z4qWSPmJS/PEGJi/578zGC8VDo ab8sCX1DMIe8Y6P6N6yQMg/H2a3oaeK0gXEh1KzbaCjWf3c9HqC/55aQ1nZY06pmbm89 U8lOI5qF7VLHIORzEFBHhXTSH3GYiMLNdM94e5rw3kWdPFaAJl4uwhx7HGTtho5SURDJ KXcSEjYb6xnSAdTt6jgAfPRprkm9LI+oKQqxPzBE07SB0b69DYs/xFNwkqCpTsub44wV cC9Q== Message-ID: <50AA6C89.10107@gmail.com> Date: Mon, 19 Nov 2012 10:29:45 -0700 From: Scott O'Bryan User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 MIME-Version: 1.0 To: MyFaces Discussion CC: muhibd23 Subject: Re: Need help in trinidad tree component References: <34684793.post@talk.nabble.com> In-Reply-To: <34684793.post@talk.nabble.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org I don't have time to look through the entire thing, but I think if you add your tree component as a partial target, it might give you what you want. I believe your model is being updated properly but I'm not sure the changes to the component are being sent. This is just a quick suggestion based on the symptom. On Thu Nov 15 15:03:20 2012, muhibd23 wrote: > > Hello, > I am working on a web application. Everything is working fine. I just need a > simple help. I have populated a tree using JSF/trinidad tree component. > However, I want to expand the tree branches by clicking (+) sign and > collapse the tree branches by clicking (-) sign. It's not working properly. > What's happening is that, I have to click the (+) sign and then click the > root node to expand the next branch. Similarly, While collapsing, I have to > click the (-) sign and then click the child node to collapse it, but I want > to expand/ collapse nodes by clicking (+) or (-) sign. > > My jsp side code: > > > > > value="#{fileTreeHandler.treeModel}"> > > > "#{node.description}" > > actionListener="#{fileTreeHandler.downloadFile}"/> > > > > > > > Here is the filetreehandler code: > > import org.acegisecurity.Authentication; > import org.acegisecurity.context.SecurityContextHolder; > import org.apache.log4j.Logger; > import org.apache.myfaces.trinidad.component.core.data.CoreTree; > import org.apache.myfaces.trinidad.event.FocusEvent; > import org.apache.myfaces.trinidad.model.ChildPropertyTreeModel; > import org.apache.myfaces.trinidad.model.RowKeySet; > import org.apache.myfaces.trinidad.model.TreeModel; > > import javax.faces.context.ExternalContext; > import javax.faces.context.FacesContext; > import javax.servlet.http.HttpServletResponse; > import java.io.*; > import java.util.ArrayList; > import java.util.Iterator; > import java.util.List; > > /** > * A Simple tree model used to create a graphical tree representation for a > * given directory. > * > * @author Ric Smith, Oracle Corp. > */ > @SessionScoped > public class FileTreeHandler implements Serializable { > > /** Apache tree model. */ > private TreeModel treeModel; > private static final long serialVersionUID = 1L; > > /** Was a node found. */ > private boolean foundDirectory = false; > > //private RowKeySet disclosedEntries; > private CoreTree tree; > private Object clickedNodeRowKey; > > > /** Logging for the class. */ > private Logger logger = Logger.getLogger(this.getClass()); > > /** > * Constructor. > * Reads the given directory. > * Sets the treeModel nodes for all files and directories in the > * input directory. > * > * @param baseDirectory > */ > //RowKeySetImpl rowKeySet = new RowKeySetImpl(); > public FileTreeHandler(String baseDirectory) { > logger.debug("In constructor"); > List nodes = new ArrayList(); > Authentication authentic = > SecurityContextHolder.getContext().getAuthentication(); > String username = authentic.getName(); // Storing logged in username > into String > String dir = baseDirectory + "/" + username; > FileNode rootNode = buildFileTree(dir); > if (rootNode.getChildCount() == 0) { > setFoundDirectory(false); > } else { > setFoundDirectory(true); > } > nodes.add(rootNode); > treeModel = new ChildPropertyTreeModel(nodes, "children") { > public boolean isContainer() { > return ((FileNode) getRowData()).getChildCount() > 0; > } > }; > > //UIXHierarchy tree = (UIXHierarchy)treeModel.getRowData(); > // RowKeySet disclosedEntries = new RowKeySetTreeImpl(); > //disclosedEntries.setCollectionModel(treeModel); > } > > /** > * Simple action event used to init the download of a file within the > tree. > * > * > * @param evt > * @throws IOException > */ > public void downloadFile(String evt) throws IOException { > FileNode selectedNode = ((FileNode) treeModel.getRowData()); > if (!selectedNode.isDir()) { > File selectedFile = selectedNode.getFile(); > downloadFile(selectedFile); > } > } > > /** > * A helper method to setup the current session for the download. > * > * @param file > * @throws IOException > */ > private static void downloadFile(File file) throws IOException { > > FacesContext facesContext = FacesContext.getCurrentInstance(); > ExternalContext extContext = facesContext.getExternalContext(); > Long length = file.length(); > > HttpServletResponse response = (HttpServletResponse) extContext > .getResponse(); > //response.setContentType("applicatiion/octet-stream"); > response.setHeader("Content-Disposition", "attachment;filename=\"" > + file.getName() + "\""); > response.setContentLength((int) length.intValue()); > > InputStream in = new FileInputStream(file); > OutputStream out = response.getOutputStream(); > > byte[] buf = new byte[4096]; > int count; > while ((count = in.read(buf)) >= 0) { > out.write(buf, 0, count); > } > count = 0; > while ((count = in.read(buf)) >= 0) { > out.write(buf, 0, count); > } > in.close(); > out.flush(); > out.close(); > facesContext.responseComplete(); > } > > /** > * Generates a tree of FileNodes for a given dir. > * > * @param dirpath > * @return > */ > private static FileNode buildFileTree(String dirpath) { > File root = new File(dirpath); > return visitAllDirsAndFiles(root); > } > > > /* public void handleRowDisclosure(RowDisclosureEvent rowDisclosureEvent) > throws Exception { > Object rowKey = null; > UIXHierarchy rowData = null; > String viewDefName = null; > TreeModel treemodel = (TreeModel)rowDisclosureEvent.getSource(); > RowKeySet rks = rowDisclosureEvent.getAddedSet(); > if (rks != null) { > int setSize = rks.size(); > if (setSize > 1) { > throw new Exception("Unexpected multiple row disclosure row > sets"); > } > > if (setSize == 0) > return; > rowKey = rks.iterator().next(); > treemodel.setRowKey(rowKey); > rowData = (UIXHierarchy)treemodel.getRowData(); > > if (rowData.getContainerRowKey() != null) { > viewDefName = > rowData.getContainerRowKey().g; > } > } > } */ > > /** > * Recurses over a given directory. > * > * @param dir > * @return > */ > private static FileNode visitAllDirsAndFiles(File dir) { > FileNode parentNode = process(dir); > if (dir.isDirectory()) { > String[] children = dir.list(); > for (int i = 0; i < children.length; i++) { > FileNode childNode = visitAllDirsAndFiles(new File(dir, > children[i])); > parentNode.getChildren().add(childNode); > } > } > return parentNode; > } > > /** > * Creates a file node for a given file. Any file processing should be > done > * here. > * > * @param dir > * @return FileNode > */ > public static FileNode process(File dir) { > FileNode node = new FileNode(dir); > return node; > } > > public void clickTree(FocusEvent event) > { > RowKeySet rks = getTree().getDisclosedRowKeys(); > rks.invert(); > > List clickedNodePath = (List) clickedNodeRowKey; > Iterator i = getTree().getDisclosedRowKeys().iterator(); > > boolean closedNode = false; > while (i.hasNext()) { > List openNodePath = (List) i.next(); > if (openNodePath.equals(clickedNodeRowKey)) { > rks.remove(clickedNodePath); > closedNode = true; > } > } > > // open clicked node > if (!closedNode) { > rks.add(clickedNodePath); > } > > } > /*public void handleRowDisclosure(RowDisclosureEvent event) > { > RowKeySet added = event.getAddedSet(); > RowKeySet removed = event.getRemovedSet(); > if(disclosedEntries == null) > { > disclosedEntries = added; > } > else > { > if(!added.isEmpty()) > { > disclosedEntries.addAll(added); > } > if(!removed.isEmpty()) > { > disclosedEntries.removeAll(removed); > } > } > }*/ > > public void setTreeModel(TreeModel treeModel) { > this.treeModel = treeModel; > } > > public TreeModel getTreeModel() { > return treeModel; > } > > public boolean getFoundDirectory() { > return foundDirectory; > } > > public void setFoundDirectory(boolean foundDirectory) { > this.foundDirectory = foundDirectory; > } > > public void setTree(CoreTree tree) { > this.tree = tree; > } > > public CoreTree getTree() { > return tree; > } > public void setClickedNodeRowKey(Object clickedNodeRowKey) { > this.clickedNodeRowKey = clickedNodeRowKey; > } > public Object getClickedNodeRowKey() { > return clickedNodeRowKey; > } > > /* public RowKeySetImpl getRowKeySet() > { > return rowKeySet; > } > > public void setRowKeySet(RowKeySetImpl rowKeySet) > { > this.rowKeySet = rowKeySet; > } */ > > > } > > However, I'm using Spring here. I know I'm doing something wrong, but no > idea. Please help. > > Thanks > >