primefaces 2.0.3 新组件学习--treetable



 由于以前项目采用richfaces的一个treetable存在性能问题,所以移植想找一个替代方案,primefaces的2.3日构建版本已经支持Treetable组件,测试了一下,性能还不错,

 

界面效果图:

primefaces 2.0.3 新组件学习--treetable

 

treetable.xhtml

 <p:treeTable value="#{documentsController.root}" var="document">
        <p:column>
            <f:facet name="header">
                Name
            </f:facet>
            <h:outputText value="#{document.name}"/>
        </p:column>

        <p:column>
            <f:facet name="header">
                Options
            </f:facet>
            <p:commandLink update="documentPanel" oncomplete="documentDialog.show()" title="View Detail">
                <p:graphicImage value="/resources/images/search.png"/>
                <f:setPropertyActionListener value="#{document}"
                                             target="#{documentsController.selectedDocument}"/>
            </p:commandLink>
        </p:column>

    </p:treeTable>

    <p:dialog header="Document Detail" fixedCenter="true" effect="FADE" effectDuration="0.3"
              widgetVar="documentDialog" modal="false">

        <p:outputPanel id="documentPanel">
            <h:panelGrid columns="2" cellpadding="5">
                <h:outputLabel for="name" value="Name: "/>
                <h:outputText id="name" style="font-weight:bold"
                              value="#{documentsController.selectedDocument.name}"/>

            </h:panelGrid>
        </p:outputPanel>
    </p:dialog>

</h:form>

 

Java代码:

 

@ManagedBean()
@SessionScoped
public class DocumentsController {


    //private static final Logger logger = Logger.getLogger(DocumentsController.class.getName());

    private TreeNode root;

    private TreeNode selectedDocument;

    public DocumentsController() {
        root = new DefaultTreeNode("root", null);
         listFile("c:\\temp",root);

    }

    public TreeNode getRoot() {
        return root;
    }

    public void setRoot(TreeNode root) {
        this.root = root;
    }

    public TreeNode getSelectedDocument() {
        return selectedDocument;
    }

    public void setSelectedDocument(TreeNode selectedDocument) {
        this.selectedDocument = selectedDocument;
    }

    public void onNodeSelect(NodeSelectEvent event) {
        selectedDocument = event.getTreeNode();
        //logger.info("Selected:" + selectedDocument.getData());
    }

    private long[] count = new long[]{0, 0};

    private File file;

    private long[] listFile(String path, TreeNode parent) {

        file = new File(path);
        File[] f = file.listFiles();
        for (int i = 0; i < f.length; i++) {
            if (f[i].isDirectory()) {
                TreeNode documents = new DefaultTreeNode(file, parent);
                this.listFile(f[i].toString(), documents);
            } else {
                TreeNode documents = new DefaultTreeNode(file, parent);
            }
        }
        return count;
    }


}

 

 

你可能感兴趣的:(C++,c,XHTML,Richfaces,F#)