# TreeController.jpf Sample

This topic inludes the source code for the TreeController.jpf Sample.

## Sample Location

This sample is located in the following directory in your WebLogic Workshop installation:

BEA_HOME/weblogic81/samples/workshop/SamplesApp/WebApp/tagSamples/netui/tree/

## Sample Source Code

`001 package tagSamples.netui.tree; 002 003 import com.bea.wlw.netui.pageflow.PageFlowController; 004 import com.bea.wlw.netui.pageflow.Forward; 005 import com.bea.wlw.netui.pageflow.FormData; 006 import com.bea.wlw.netui.tags.html.Node; 007 008 import javax.servlet.http.HttpSession; 009 010 import com.bea.wlw.netui.tags.html.TreeNode; 011 import java.util.HashMap; 012 013 /** 014 * @jpf:controller 015 * @jpf:view-properties view-properties:: 016 * <!-- This data is auto-generated. Hand-editing this section is not recommended. --> 017 * <view-properties> 018 * <pageflow-object id="pageflow:/tagSamples/netui/tree/treeController.jpf"/> 019 * <pageflow-object id="action:treeState.do"> 020 * <property value="80" name="x"/> 021 * <property value="260" name="y"/> 022 * </pageflow-object> 023 * <pageflow-object id="action:begin.do"> 024 * <property value="80" name="x"/> 025 * <property value="60" name="y"/> 026 * </pageflow-object> 027 * <pageflow-object id="page:content/RootFolder.jsp"> 028 * <property value="300" name="x"/> 029 * <property value="60" name="y"/> 030 * </pageflow-object> 031 * <pageflow-object id="page:content/I.jsp"> 032 * <property value="320" name="x"/> 033 * <property value="120" name="y"/> 034 * </pageflow-object> 035 * <pageflow-object id="page:content/IA.jsp"> 036 * <property value="320" name="x"/> 037 * <property value="180" name="y"/> 038 * </pageflow-object> 039 * <pageflow-object id="page:content/IA1.jsp"> 040 * <property value="460" name="x"/> 041 * <property value="180" name="y"/> 042 * </pageflow-object> 043 * <pageflow-object id="page:content/IA2.jsp"> 044 * <property value="560" name="x"/> 045 * <property value="180" name="y"/> 046 * </pageflow-object> 047 * <pageflow-object id="page:content/IB.jsp"> 048 * <property value="460" name="x"/> 049 * <property value="240" name="y"/> 050 * </pageflow-object> 051 * <pageflow-object id="page:content/IB1.jsp"> 052 * <property value="320" name="x"/> 053 * <property value="240" name="y"/> 054 * </pageflow-object> 055 * <pageflow-object id="page:content/IB2.jsp"> 056 * <property value="560" name="x"/> 057 * <property value="240" name="y"/> 058 * </pageflow-object> 059 * <pageflow-object id="page:content/IC.jsp"> 060 * <property value="320" name="x"/> 061 * <property value="300" name="y"/> 062 * </pageflow-object> 063 * <pageflow-object id="page:content/IC1.jsp"> 064 * <property value="460" name="x"/> 065 * <property value="300" name="y"/> 066 * </pageflow-object> 067 * <pageflow-object id="page:content/IC2.jsp"> 068 * <property value="560" name="x"/> 069 * <property value="300" name="y"/> 070 * </pageflow-object> 071 * <pageflow-object id="page:content/II.jsp"> 072 * <property value="320" name="x"/> 073 * <property value="360" name="y"/> 074 * </pageflow-object> 075 * <pageflow-object id="page:content/IIA.jsp"> 076 * <property value="320" name="x"/> 077 * <property value="420" name="y"/> 078 * </pageflow-object> 079 * <pageflow-object id="page:content/IIA1.jsp"> 080 * <property value="460" name="x"/> 081 * <property value="420" name="y"/> 082 * </pageflow-object> 083 * <pageflow-object id="page:content/IIA2.jsp"> 084 * <property value="560" name="x"/> 085 * <property value="420" name="y"/> 086 * </pageflow-object> 087 * <pageflow-object id="page:content/IIB.jsp"> 088 * <property value="320" name="x"/> 089 * <property value="500" name="y"/> 090 * </pageflow-object> 091 * <pageflow-object id="page:content/IIB1.jsp"> 092 * <property value="460" name="x"/> 093 * <property value="500" name="y"/> 094 * </pageflow-object> 095 * <pageflow-object id="page:content/IIB2.jsp"> 096 * <property value="560" name="x"/> 097 * <property value="500" name="y"/> 098 * </pageflow-object> 099 * <pageflow-object id="page:content/IIC.jsp"> 100 * <property value="320" name="x"/> 101 * <property value="580" name="y"/> 102 * </pageflow-object> 103 * <pageflow-object id="page:content/IIC1.jsp"> 104 * <property value="460" name="x"/> 105 * <property value="580" name="y"/> 106 * </pageflow-object> 107 * <pageflow-object id="page:content/IIC2.jsp"> 108 * <property value="560" name="x"/> 109 * <property value="580" name="y"/> 110 * </pageflow-object> 111 * <pageflow-object id="action-call:@page:tree.jsp@#@action:treeState.do@"> 112 * <property value="100,100,80,80" name="elbowsX"/> 113 * <property value="616,460,460,304" name="elbowsY"/> 114 * <property value="North_1" name="fromPort"/> 115 * <property value="South_1" name="toPort"/> 116 * </pageflow-object> 117 * <pageflow-object id="page:tree.jsp"> 118 * <property value="100" name="x"/> 119 * <property value="660" name="y"/> 120 * </pageflow-object> 121 * <pageflow-object id="page:frameSet.jsp"> 122 * <property value="80" name="x"/> 123 * <property value="180" name="y"/> 124 * </pageflow-object> 125 * <pageflow-object id="forward:path#0#content/RootFolder.jsp#@action:treeState.do@"> 126 * <property value="116,190,190,264" name="elbowsX"/> 127 * <property value="252,252,52,52" name="elbowsY"/> 128 * <property value="East_1" name="fromPort"/> 129 * <property value="West_1" name="toPort"/> 130 * <property value="0" name="label"/> 131 * </pageflow-object> 132 * <pageflow-object id="forward:path#0.0#content/I.jsp#@action:treeState.do@"> 133 * <property value="116,200,200,284" name="elbowsX"/> 134 * <property value="252,252,112,112" name="elbowsY"/> 135 * <property value="East_1" name="fromPort"/> 136 * <property value="West_1" name="toPort"/> 137 * <property value="0.0" name="label"/> 138 * </pageflow-object> 139 * <pageflow-object id="forward:path#0.0.0#content/IA.jsp#@action:treeState.do@"> 140 * <property value="116,200,200,284" name="elbowsX"/> 141 * <property value="252,252,172,172" name="elbowsY"/> 142 * <property value="East_1" name="fromPort"/> 143 * <property value="West_1" name="toPort"/> 144 * <property value="0.0.0" name="label"/> 145 * </pageflow-object> 146 * <pageflow-object id="forward:path#0.0.0.0#content/IA1.jsp#@action:treeState.do@"> 147 * <property value="116,270,270,424" name="elbowsX"/> 148 * <property value="252,252,172,172" name="elbowsY"/> 149 * <property value="East_1" name="fromPort"/> 150 * <property value="West_1" name="toPort"/> 151 * <property value="0.0.0.0" name="label"/> 152 * </pageflow-object> 153 * <pageflow-object id="forward:path#0.0.0.1#content/IA2.jsp#@action:treeState.do@"> 154 * <property value="116,320,320,524" name="elbowsX"/> 155 * <property value="252,252,172,172" name="elbowsY"/> 156 * <property value="East_1" name="fromPort"/> 157 * <property value="West_1" name="toPort"/> 158 * <property value="0.0.0.1" name="label"/> 159 * </pageflow-object> 160 * <pageflow-object id="forward:path#0.0.1#content/IB.jsp#@action:treeState.do@"> 161 * <property value="116,270,270,424" name="elbowsX"/> 162 * <property value="252,252,232,232" name="elbowsY"/> 163 * <property value="East_1" name="fromPort"/> 164 * <property value="West_1" name="toPort"/> 165 * <property value="0.0.1" name="label"/> 166 * </pageflow-object> 167 * <pageflow-object id="forward:path#0.0.1.0#content/IB1.jsp#@action:treeState.do@"> 168 * <property value="116,200,200,284" name="elbowsX"/> 169 * <property value="252,252,232,232" name="elbowsY"/> 170 * <property value="East_1" name="fromPort"/> 171 * <property value="West_1" name="toPort"/> 172 * <property value="0.0.1.0" name="label"/> 173 * </pageflow-object> 174 * <pageflow-object id="forward:path#0.0.1.1#content/IB2.jsp#@action:treeState.do@"> 175 * <property value="116,320,320,524" name="elbowsX"/> 176 * <property value="252,252,232,232" name="elbowsY"/> 177 * <property value="East_1" name="fromPort"/> 178 * <property value="West_1" name="toPort"/> 179 * <property value="0.0.1.1" name="label"/> 180 * </pageflow-object> 181 * <pageflow-object id="forward:path#0.0.2#content/IC.jsp#@action:treeState.do@"> 182 * <property value="116,200,200,284" name="elbowsX"/> 183 * <property value="252,252,292,292" name="elbowsY"/> 184 * <property value="East_1" name="fromPort"/> 185 * <property value="West_1" name="toPort"/> 186 * <property value="0.0.2" name="label"/> 187 * </pageflow-object> 188 * <pageflow-object id="forward:path#0.0.2.0#content/IC1.jsp#@action:treeState.do@"> 189 * <property value="116,270,270,424" name="elbowsX"/> 190 * <property value="252,252,292,292" name="elbowsY"/> 191 * <property value="East_1" name="fromPort"/> 192 * <property value="West_1" name="toPort"/> 193 * <property value="0.0.2.0" name="label"/> 194 * </pageflow-object> 195 * <pageflow-object id="forward:path#0.0.2.1#content/IC2.jsp#@action:treeState.do@"> 196 * <property value="116,320,320,524" name="elbowsX"/> 197 * <property value="252,252,292,292" name="elbowsY"/> 198 * <property value="East_1" name="fromPort"/> 199 * <property value="West_1" name="toPort"/> 200 * <property value="0.0.2.1" name="label"/> 201 * </pageflow-object> 202 * <pageflow-object id="forward:path#0.1#content/II.jsp#@action:treeState.do@"> 203 * <property value="116,200,200,284" name="elbowsX"/> 204 * <property value="252,252,352,352" name="elbowsY"/> 205 * <property value="East_1" name="fromPort"/> 206 * <property value="West_1" name="toPort"/> 207 * <property value="0.1" name="label"/> 208 * </pageflow-object> 209 * <pageflow-object id="forward:path#0.1.0#content/IIA.jsp#@action:treeState.do@"> 210 * <property value="116,200,200,284" name="elbowsX"/> 211 * <property value="252,252,412,412" name="elbowsY"/> 212 * <property value="East_1" name="fromPort"/> 213 * <property value="West_1" name="toPort"/> 214 * <property value="0.1.0" name="label"/> 215 * </pageflow-object> 216 * <pageflow-object id="forward:path#0.1.0.0#content/IIA1.jsp#@action:treeState.do@"> 217 * <property value="116,270,270,424" name="elbowsX"/> 218 * <property value="252,252,412,412" name="elbowsY"/> 219 * <property value="East_1" name="fromPort"/> 220 * <property value="West_1" name="toPort"/> 221 * <property value="0.1.0.0" name="label"/> 222 * </pageflow-object> 223 * <pageflow-object id="forward:path#0.1.0.1#content/IIA2.jsp#@action:treeState.do@"> 224 * <property value="116,320,320,524" name="elbowsX"/> 225 * <property value="252,252,412,412" name="elbowsY"/> 226 * <property value="East_1" name="fromPort"/> 227 * <property value="West_1" name="toPort"/> 228 * <property value="0.1.0.1" name="label"/> 229 * </pageflow-object> 230 * <pageflow-object id="forward:path#0.1.1#content/IIB.jsp#@action:treeState.do@"> 231 * <property value="116,200,200,284" name="elbowsX"/> 232 * <property value="263,263,492,492" name="elbowsY"/> 233 * <property value="East_2" name="fromPort"/> 234 * <property value="West_1" name="toPort"/> 235 * <property value="0.1.1" name="label"/> 236 * </pageflow-object> 237 * <pageflow-object id="forward:path#0.1.1.0#content/IIB1.jsp#@action:treeState.do@"> 238 * <property value="116,270,270,424" name="elbowsX"/> 239 * <property value="263,263,492,492" name="elbowsY"/> 240 * <property value="East_2" name="fromPort"/> 241 * <property value="West_1" name="toPort"/> 242 * <property value="0.1.1.0" name="label"/> 243 * </pageflow-object> 244 * <pageflow-object id="forward:path#0.1.1.1#content/IIB2.jsp#@action:treeState.do@"> 245 * <property value="116,320,320,524" name="elbowsX"/> 246 * <property value="263,263,492,492" name="elbowsY"/> 247 * <property value="East_2" name="fromPort"/> 248 * <property value="West_1" name="toPort"/> 249 * <property value="0.1.1.1" name="label"/> 250 * </pageflow-object> 251 * <pageflow-object id="forward:path#0.1.2#content/IIC.jsp#@action:treeState.do@"> 252 * <property value="116,200,200,284" name="elbowsX"/> 253 * <property value="263,263,572,572" name="elbowsY"/> 254 * <property value="East_2" name="fromPort"/> 255 * <property value="West_1" name="toPort"/> 256 * <property value="0.1.2" name="label"/> 257 * </pageflow-object> 258 * <pageflow-object id="forward:path#0.1.2.0#content/IIC1.jsp#@action:treeState.do@"> 259 * <property value="116,270,270,424" name="elbowsX"/> 260 * <property value="263,263,572,572" name="elbowsY"/> 261 * <property value="East_2" name="fromPort"/> 262 * <property value="West_1" name="toPort"/> 263 * <property value="0.1.2.0" name="label"/> 264 * </pageflow-object> 265 * <pageflow-object id="forward:path#0.1.2.1#content/IIC2.jsp#@action:treeState.do@"> 266 * <property value="116,320,320,524" name="elbowsX"/> 267 * <property value="263,263,572,572" name="elbowsY"/> 268 * <property value="East_2" name="fromPort"/> 269 * <property value="West_1" name="toPort"/> 270 * <property value="0.1.2.1" name="label"/> 271 * </pageflow-object> 272 * <pageflow-object id="forward:path#tree#tree.jsp#@action:treeState.do@"> 273 * <property value="69,69,64,64" name="elbowsX"/> 274 * <property value="304,464,464,641" name="elbowsY"/> 275 * <property value="South_0" name="fromPort"/> 276 * <property value="West_0" name="toPort"/> 277 * <property value="tree" name="label"/> 278 * </pageflow-object> 279 * <pageflow-object id="forward:path#begin#frameSet.jsp#@action:begin.do@"> 280 * <property value="80,80,80,80" name="elbowsX"/> 281 * <property value="104,120,120,136" name="elbowsY"/> 282 * <property value="South_1" name="fromPort"/> 283 * <property value="North_1" name="toPort"/> 284 * <property value="begin" name="label"/> 285 * </pageflow-object> 286 * </view-properties> 287 * :: 288 */ 289 public class treeController extends PageFlowController 290 { 291 /** 292 * @jpf:action 293 * @jpf:forward name="0" path="content/RootFolder.jsp" 294 * @jpf:forward name="0.0" path="content/I.jsp" 295 * @jpf:forward name="0.0.0" path="content/IA.jsp" 296 * @jpf:forward name="0.0.0.0" path="content/IA1.jsp" 297 * @jpf:forward name="0.0.0.1" path="content/IA2.jsp" 298 * @jpf:forward name="0.0.1" path="content/IB.jsp" 299 * @jpf:forward name="0.0.1.0" path="content/IB1.jsp" 300 * @jpf:forward name="0.0.1.1" path="content/IB2.jsp" 301 * @jpf:forward name="0.0.2" path="content/IC.jsp" 302 * @jpf:forward name="0.0.2.0" path="content/IC1.jsp" 303 * @jpf:forward name="0.0.2.1" path="content/IC2.jsp" 304 * @jpf:forward name="0.1" path="content/II.jsp" 305 * @jpf:forward name="0.1.0" path="content/IIA.jsp" 306 * @jpf:forward name="0.1.0.0" path="content/IIA1.jsp" 307 * @jpf:forward name="0.1.0.1" path="content/IIA2.jsp" 308 * @jpf:forward name="0.1.1" path="content/IIB.jsp" 309 * @jpf:forward name="0.1.1.0" path="content/IIB1.jsp" 310 * @jpf:forward name="0.1.1.1" path="content/IIB2.jsp" 311 * @jpf:forward name="0.1.2" path="content/IIC.jsp" 312 * @jpf:forward name="0.1.2.0" path="content/IIC1.jsp" 313 * @jpf:forward name="0.1.2.1" path="content/IIC2.jsp" 314 * @jpf:forward name="tree" path="tree.jsp" 315 */ 316 public Forward treeState() 317 { 318 /* 319 * The tree info is stored as an attribute of the session object. 320 * The <netui:tree> tag on tree.jsp databinds to this attribute. 321 * the tree info is stored as the tree's root node (which contains 322 * infomation about each of the child nodes). 323 */ 324 HttpSession session = getRequest().getSession(); 325 TreeNode rootNode = (TreeNode) session.getAttribute("tree"); 326 327 String nodeSel = null; 328 String nodeExpanded = null; 329 330 /* 331 * Handles expansion / collapse of a tree node. 332 * 333 * Get the String name of the content node or the expandable/collapsable node 334 * selected by the user. 335 */ 336 nodeSel = getRequest().getParameter(TreeNode.SELECTED_NODE); 337 nodeExpanded = getRequest().getParameter(TreeNode.EXPAND_NODE); 338 339 /* 340 * If the user selected an expandable/collapsable node... 341 */ 342 if (nodeExpanded != null) 343 { 344 /* 345 * ...then get the TreeNode object based on the node's String name... 346 */ 347 TreeNode node = rootNode.findNode(nodeExpanded); 348 if (node != null) 349 { 350 /* 351 * ...and reverse the expand/collapse state of the node. 352 * (I.e. if the node was previously collapsed, then expand it; 353 * if it was previously expanded, then collapse it.) 354 */ 355 node.setExpanded(!node.isExpanded()); 356 357 } 358 /* 359 * When a node is selected for expansion/collapse, display changes only in the 360 * navigation frame. 361 */ 362 return new Forward("tree"); 363 } 364 365 return new Forward(nodeSel); 366 } 367 368 /** 369 * @jpf:action 370 * @jpf:forward name="begin" path="frameSet.jsp" 371 */ 372 public Forward begin() 373 { 374 return new Forward("begin"); 375 } 376 377 }`