⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 firsttree3.html

📁 经典Tapestry教程 经典Tapestry教程
💻 HTML
字号:
<html jwcid="@Shell" title="Using The Tapestry Tree Control" stylesheet="ognl:assets.stylesheet"><head jwcid="@Block">    <link rel="stylesheet" type="text/css" href="../css/style.css"/></head><body jwcid="@Body">    <h1>Performing an action when a node is clicked</h1>    <div class="note">        This page demonstrates how to use a TreeStateListener to        respond when a node is clicked.     </div>    <table border="1">        <tr>            <td valign="top">                <span class="tree" jwcid="treeView">                    <span jwcid="treeDataView">                        <span jwcid="treeNodeView"/>                    </span>                </span>            </td>        </tr>        <tr>            <td colspan="4">               <code class="highlight"><span jwcid="@Insert" value="ognl:lastNodeSelectedMsg"/></code>            <td>        </tr>        </table>    <p>        Here is a snippet from FirstTree3.hmtl that adds a dynamic string        to the page to indicate the last node that was selected:<div class="code"><pre>    &lt;table border="1"&gt;        &lt;tr&gt;            &lt;td valign="top"&gt;                &lt;span class="tree" jwcid="treeView"&gt;                    &lt;span jwcid="treeDataView"&gt;                        &lt;span jwcid="treeNodeView"/&gt;                    &lt;/span&gt;                &lt;/span&gt;            &lt;/td&gt;        &lt;/tr&gt;        &lt;tr&gt;            &lt;td colspan="4"&gt;<code class="highlight">               &lt;code class="highlight"&gt;                &lt;span jwcid="@Insert" value="ognl:lastNodeSelectedMsg"/&gt;               &lt;/code&gt;</code>            &lt;td&gt;        &lt;/tr&gt;        &lt;/table&gt;</pre></div>    <p>        The TreeView's TreeStateListener is notified any time a node        of the tree is selected.  In our case the page is the TreeStateListener.        This was set up on <code>FirstTree3.page</code> in the following snippet:<div class="code"><pre>    &lt;component id="treeView" type="contrib:TreeView"&gt;        &lt;binding name="treeModel" expression='treeModel'/&gt;        <code class="highlight">&lt;binding name="treeStateListener" expression='treeStateListener'/&gt;</code>    &lt;/component&gt;</pre></div>        Here are some code        snippets from <code>FirstTreePage.java</code> that demonstrate how        to respond to events from the tree:<div class="code"><pre>    public class FirstTreePage extends BasePage         implements <code class="highlight">ITreeStateListener</code> {    	public ITreeStateListener getTreeStateListener() {		return this;	}    	/*	 * @see org.apache.tapestry.contrib.tree.model.ITreeStateListener#treeStateChanged(org.apache.tapestry.contrib.tree.model.TreeStateEvent)	 */	public void treeStateChanged(TreeStateEvent objEvent) {        // Get the StringTreeNode object that was selected         TreeView treeView = (TreeView)getComponent("treeView");        if(treeView != null){            ITreeDataModel thisTreeDataModel = treeView.getTreeModel().getTreeDataModel();            Object selectedNode = thisTreeDataModel.getObject(objEvent.getNodeUID());            if(selectedNode instanceof StringTreeNode){               lastNodeSelectedValue = ((StringTreeNode)selectedNode).getValue();            }        } else { // This shouldn't happen            lastNodeSelectedValue = objEvent.getNodeUID().toString();        }	}    String lastNodeSelectedValue;    public String getLastNodeSelectedMsg()    {        if(lastNodeSelectedValue==null){            return null;        }        return lastNodeSelectedValue + " was the last node selected.";    }</pre></div><p>    As you can see, in the <code>TreeStateChanged</code> event handler     it is fairly easy to get the ITreeNode that was    selected. With that information you can do whatever is appropriate for    your application.<p><a href="#" jwcid="@PageLink" page="FirstTree4">Changing the open and close icons...</a><p><a href="#" jwcid="@PageLink" page="Home">Return to Home Page...</a></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -