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