Hi Scott,
I solved that problem. It was basically java Script problem that has been
solved. However two more requirements:
1) I have to expand the tree by clicking the nodes.
2) When the web application will be first loaded, then the tree will be
expanded with only first level. That means:
If    A
      --->B
            ----->D
      ---->C
             ---->E

is a tree then my requirement is(When application is first loaded):
      A
       ----->B
       ------>C

I'm sure it can be done. Can u help me with some direction and sample code?

Thanks

On Mon, Nov 19, 2012 at 12:50 PM, Scott O'Bryan <darkar...@gmail.com> wrote:

> http://myfaces.apache.org/**trinidad/trinidad-api/apidocs/**
> org/apache/myfaces/trinidad/**context/RequestContext.html<http://myfaces.apache.org/trinidad/trinidad-api/apidocs/org/apache/myfaces/trinidad/context/RequestContext.html>
>
> Look up addPartialTarget.
>
> To do it declaratively you need to look in the tag doc under
> partialTriggers.
>
> Hope that helps.
>
> Scott
>
>
> On Mon Nov 19 10:45:45 2012, Muhibbul Chowdhury wrote:
>
>> Hi,
>> Thanks. Can you please send a sample code how to add trinidad
>> component as a partial target?
>>
>> On Mon, Nov 19, 2012 at 11:29 AM, Scott O'Bryan <darkar...@gmail.com
>> <mailto:darkar...@gmail.com>> wrote:
>>
>>     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:
>>
>>         <trh:cellFormat valign="top">
>>                          <tr:panelHeader>
>>                              <script type="text/javascript"
>>         src="CollapsibleLists.js"></__**script>
>>                                      <tr:tree var="node"
>>         value="#{fileTreeHandler.__**treeModel}">
>>
>>                                        <f:facet name="nodeStamp">
>>                                          <tr:panelGroupLayout>
>>                                              <tr:commandLink text =
>>         "#{node.description}"
>>
>>         actionListener="#{__**fileTreeHandler.downloadFile}"**__/>
>>
>>                                          </tr:panelGroupLayout>
>>                                        </f:facet>
>>                                      </tr:tree>
>>                          </tr:panelHeader>
>>                        </trh:cellFormat>
>>
>>         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<FileNode> nodes = new ArrayList<FileNode>();
>>                  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<List> clickedNodePath = (List<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
>>
>>
>>
>>
>>
>>
>
>

Reply via email to