View Javadoc

    1   /*
    2    * $Id: TreeNode.java 497654 2007-01-19 00:21:57Z rgielen $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
    10   * with the License.  You may obtain a copy of the License at
    11   *
    12   *  http://www.apache.org/licenses/LICENSE-2.0
    13   *
    14   * Unless required by applicable law or agreed to in writing,
    15   * software distributed under the License is distributed on an
    16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    17   * KIND, either express or implied.  See the License for the
    18   * specific language governing permissions and limitations
    19   * under the License.
    20   */
    21  package org.apache.struts2.components;
    22
    23  import javax.servlet.http.HttpServletRequest;
    24  import javax.servlet.http.HttpServletResponse;
    25
    26  import org.apache.struts2.views.annotations.StrutsTag;
    27  import org.apache.struts2.views.annotations.StrutsTagAttribute;
    28
    29  import com.opensymphony.xwork2.util.ValueStack;
    30
    31  /***
    32   * <!-- START SNIPPET: javadoc -->
    33   *
    34   * Renders a tree node within a tree widget with AJAX support.<p/>
    35   *
    36   * Either of the following combinations should be used depending on if the tree
    37   * is to be constrcted dynamically or statically. <p/>
    38   *
    39   * <b>Dynamically</b>
    40   * <ul>
    41   *      <li>id - id of this tree node</li>
    42   *      <li>title - label to be displayed for this tree node</li>
    43   * </ul>
    44   *
    45   * <b>Statically</b>
    46   * <ul>
    47   *      <li>rootNode - the parent node of which this tree is derived from</li>
    48   *      <li>nodeIdProperty - property to obtained this current tree node's id</li>
    49   *      <li>nodeTitleProperty - property to obtained this current tree node's title</li>
    50   *      <li>childCollectionProperty - property that returnds this current tree node's children</li>
    51   * </ul>
    52   *
    53   * <!-- END SNIPPET: javadoc -->
    54   *
    55   * <p/> <b>Examples</b>
    56   *
    57   * <pre>
    58   * <!-- START SNIPPET: example -->
    59   *
    60   * &lt-- statically --&gt;
    61   * &lt;s:tree id="..." label="..."&gt;
    62   *    &lt;s:treenode id="..." label="..." /&gt;
    63   *    &lt;s:treenode id="..." label="..."&gt;
    64   *        &lt;s:treenode id="..." label="..." /&gt;
    65   *        &lt;s:treenode id="..." label="..." /&gt;
    66   *    &;lt;/s:treenode&gt;
    67   *    &lt;s:treenode id="..." label="..." /&gt;
    68   * &lt;/s:tree&gt;
    69   *
    70   * &lt;-- dynamically --&gt;
    71   * &lt;s:tree
    72   *          id="..."
    73   *          rootNode="..."
    74   *          nodeIdProperty="..."
    75   *          nodeTitleProperty="..."
    76   *          childCollectionProperty="..." /&gt;
    77   *
    78   * <!-- END SNIPPET: example -->
    79   * </pre>
    80   *
    81   */
    82  @StrutsTag(name="treenode", tldTagClass="org.apache.struts2.views.jsp.ui.TreeNodeTag", description="Render a tree node within a tree widget.")
    83  public class TreeNode extends ClosingUIBean {
    84      private static final String TEMPLATE = "treenode-close";
    85      private static final String OPEN_TEMPLATE = "treenode";
    86
    87      public TreeNode(ValueStack stack, HttpServletRequest request, HttpServletResponse response) {
    88          super(stack, request, response);
    89      }
    90
    91      public String getDefaultOpenTemplate() {
    92          return OPEN_TEMPLATE;
    93      }
    94
    95      protected String getDefaultTemplate() {
    96          return TEMPLATE;
    97      }
    98
    99      @StrutsTagAttribute(description="Label expression used for rendering tree node label.", required=true)
    100     public void setLabel(String label) {
    101         super.setLabel(label);
    102     }
    103 }