1 33 34 package com.icesoft.faces.component.tree; 35 36 import com.icesoft.faces.component.CSS_DEFAULT; 37 import com.icesoft.faces.component.ext.taglib.Util; 38 import com.icesoft.faces.util.CoreUtils; 39 40 import javax.faces.component.EditableValueHolder; 41 import javax.faces.component.NamingContainer; 42 import javax.faces.component.UICommand; 43 import javax.faces.component.UIComponent; 44 import javax.faces.context.FacesContext; 45 import javax.faces.el.ValueBinding; 46 import javax.faces.event.AbortProcessingException; 47 import javax.faces.event.FacesEvent; 48 import javax.faces.event.FacesListener; 49 import javax.faces.event.PhaseId; 50 import javax.swing.tree.DefaultMutableTreeNode ; 51 import javax.swing.tree.TreeModel ; 52 import java.io.Serializable ; 53 import java.util.HashMap ; 54 import java.util.Iterator ; 55 import java.util.Map ; 56 57 75 public class Tree extends UICommand implements NamingContainer { 76 77 private static final String DEFAULT_CSSIMAGEDIR = 79 "/xmlhttp/css/xp/css-images/"; 80 81 private static final String DEFAULT_NAV_OPEN_TOP_GIF = 82 "tree_nav_top_open.gif"; 83 84 private static final String DEFAULT_NAV_CLOSE_TOP_GIF = 85 "tree_nav_top_close.gif"; 86 87 private static final String DEFAULT_NAV_OPEN_TOP_NO_SIBLINGS_GIF = 88 "tree_nav_top_open_no_siblings.gif"; 89 90 private static final String DEFAULT_NAV_CLOSE_TOP_NO_SIBLINGS_GIF = 91 "tree_nav_top_close_no_siblings.gif"; 92 93 private static final String DEFAULT_NAV_OPEN_MIDDLE_GIF = 94 "tree_nav_middle_open.gif"; 95 96 private static final String DEFAULT_NAV_CLOSE_MIDDLE_GIF = 97 "tree_nav_middle_close.gif"; 98 99 private static final String DEFAULT_NAV_CLOSE_BOTTOM_GIF = 100 "tree_nav_bottom_close.gif"; 101 102 private static final String DEFAULT_NAV_OPEN_BOTTOM_GIF = 103 "tree_nav_bottom_open.gif"; 104 105 private static final String DEFAULT_LINE_MIDDLE_NODE_GIF = 106 "tree_line_middle_node.gif"; 107 108 private static final String DEFAULT_LINE_VERTICAL_GIF = 109 "tree_line_vertical.gif"; 110 111 private static final String DEFAULT_LINE_BLANK_GIF = "tree_line_blank.gif"; 112 113 private static final String DEFAULT_LINE_BOTTOM_NODE_GIF = 114 "tree_line_last_node.gif"; 115 116 private static final String DEFAULT_DOCUMENT_GIF = "tree_document.gif"; 117 118 private static final String DEFAULT_FOLDER_GIF = "tree_folder_close.gif"; 119 120 private static final String DEFAULT_FOLDER_OPEN_GIF = 121 "tree_folder_open.gif"; 122 123 126 public static final String NAVIGATION_EVENT_COLLAPSE = "collapse"; 127 128 131 public static final String NAVIGATION_EVENT_EXPAND = "expand"; 132 133 136 public static final String ID_PREFIX = "n-"; 137 138 private DefaultMutableTreeNode navigatedNode; 140 private String navigationEventType; 141 private String imageDir; 143 private String navOpenTop; 144 private String navOpenTopNoSiblings; 145 private String navCloseTopNoSiblings; 146 private String navCloseTop; 147 private String navCloseMiddle; 148 private String navOpenMiddle; 149 private String lineMiddleNode; 150 private String lineBottomNode; 151 private String lineVertical; 152 private String lineBlank; 153 private String documentImage; 154 private String folderImage; 155 private String folderOpenImage; 156 private String navCloseBottom; 157 private String navOpenBottom; 158 private String var; 159 private String styleClass; 160 private String style; 161 private Boolean hideRootNode; 162 private Boolean hideNavigation; 163 164 private DefaultMutableTreeNode currentNode; 165 private String nodePath; 166 167 170 public Tree() { 171 172 } 173 174 177 public static final String COMPONENT_TYPE = "com.icesoft.faces.TreeView"; 178 179 182 public String getRendererType() { 183 return "com.icesoft.faces.View"; 184 } 185 186 189 public String getComponentType() { 190 return COMPONENT_TYPE; 191 } 192 193 198 public String getFamily() { 199 return "com.icesoft.faces.TreeView"; 200 } 201 202 204 207 public void setCurrentNode(DefaultMutableTreeNode currentNode) { 208 this.currentNode = currentNode; 209 } 210 211 214 public DefaultMutableTreeNode getCurrentNode() { 215 return this.currentNode; 216 } 217 218 221 public void setNodePath(String nodePath) { 222 FacesContext facesContext = getFacesContext(); 223 saveChildrenState(facesContext); 225 226 this.nodePath = nodePath; 227 228 restoreChildrenState(facesContext); 230 231 this.setCurrentVarToRequestMap(facesContext, getCurrentNode()); 233 234 } 235 236 239 public String getNodePath() { 240 return this.nodePath; 241 } 242 243 246 public TreeModel getModel() { 247 ValueBinding vb = getValueBinding("value"); 248 return (TreeModel ) vb.getValue(getFacesContext()); 249 } 250 251 255 public TreeNode getTreeNodeTemplate() throws MalformedTreeTagException { 256 TreeNode template = null; 257 int childCount = this.getChildCount(); 258 if (childCount != 1) { 259 throw new MalformedTreeTagException( 260 "The tree tag requires a single treeNode child tag. Found [" 261 + childCount + "] children"); 262 } 263 UIComponent treeNodeTemplate = (UIComponent) getChildren().get(0); 264 if (treeNodeTemplate == null) { 265 throw new MalformedTreeTagException( 266 "The Tree requires a TreeNode child. None found."); 267 } 268 269 if (!(treeNodeTemplate instanceof TreeNode)) { 270 throw new MalformedTreeTagException( 271 "The Tree requires a TreeNode child. Found child of type [" 272 + treeNodeTemplate.getClass() + "]"); 273 } 274 return template; 275 } 276 277 281 public DefaultMutableTreeNode getNodeAtPathsEnd(String pathToSelectedNode) { 282 if (pathToSelectedNode.equalsIgnoreCase("root")) { 283 return (DefaultMutableTreeNode ) getModel().getRoot(); 284 } 285 String [] indices = pathToSelectedNode 286 .split(TreeRenderer.PATH_DELIMITER); 287 DefaultMutableTreeNode parent = (DefaultMutableTreeNode ) getModel() 288 .getRoot(); 289 for (int i = 0; i < indices.length; i++) { 290 parent = (DefaultMutableTreeNode ) parent.getChildAt(Integer 291 .parseInt(indices[i])); 292 } 293 return parent; 294 } 295 296 298 301 public String getImageDir() { 302 if (imageDir != null) { 303 return imageDir; 304 } 305 ValueBinding vb = getValueBinding("imageDir"); 306 return CoreUtils.resolveResourceURL(getFacesContext(), 307 vb != null ? (String ) vb.getValue(getFacesContext()) : DEFAULT_CSSIMAGEDIR); 308 } 309 310 315 public String getStyleClass() { 316 return Util.getQualifiedStyleClass(this, 317 styleClass, 318 CSS_DEFAULT.TREE_DEFAULT_STYLE_CLASS, 319 "styleClass"); 320 } 321 322 327 public void setStyleClass(String styleClass) { 328 this.styleClass = styleClass; 329 } 330 331 336 public String getStyle() { 337 if (style != null) { 338 return style; 339 } 340 ValueBinding vb = getValueBinding("style"); 341 return vb != null ? (String ) vb.getValue(getFacesContext()) : ""; 342 } 343 344 349 public void setStyle(String style) { 350 this.style = style; 351 } 352 353 String getTreeRowStyleClass() { 354 return Util.getQualifiedStyleClass(this, 355 CSS_DEFAULT.STYLE_TREEROW); 356 } 357 363 public String getImage(String imageProperty, String bindingName, 364 String defaultImage) { 365 if (imageProperty != null) { 366 return imageProperty; 367 } 368 ValueBinding vb = getValueBinding(bindingName); 369 if (vb != null) { 370 return (String ) vb.getValue(getFacesContext()); 371 } 372 return getImageDir() + defaultImage; 373 374 } 375 376 379 public String getFolderImage() { 380 return getImage(folderImage, "folderImage", DEFAULT_FOLDER_GIF); 381 } 382 383 386 public String getFolderOpenImage() { 387 return getImage(folderOpenImage, "folderOpenImage", 388 DEFAULT_FOLDER_OPEN_GIF); 389 } 390 391 394 public String getDocumentImage() { 395 return getImage(documentImage, "documentImage", DEFAULT_DOCUMENT_GIF); 396 } 397 398 401 public String getLineBottomImage() { 402 return getImage(lineBottomNode, "lineBottom", 403 DEFAULT_LINE_BOTTOM_NODE_GIF); 404 } 405 406 409 public String getLineVerticalImage() { 410 return getImage(lineVertical, "lineVertical", 411 DEFAULT_LINE_VERTICAL_GIF); 412 } 413 414 417 public String getLineMiddleImage() { 418 return getImage(lineMiddleNode, "lineMiddle", 419 DEFAULT_LINE_MIDDLE_NODE_GIF); 420 } 421 422 425 public String getNavCloseMiddleImage() { 426 return getImage(navCloseMiddle, "navCloseMiddleImage", 427 DEFAULT_NAV_CLOSE_MIDDLE_GIF); 428 } 429 430 433 public String getNavOpenMiddleImage() { 434 return getImage(navOpenMiddle, "navOpenMiddle", 435 DEFAULT_NAV_OPEN_MIDDLE_GIF); 436 } 437 438 441 public String getNavCloseTopImage() { 442 return getImage(navCloseTop, "navCloseTop", DEFAULT_NAV_CLOSE_TOP_GIF); 443 } 444 445 448 public String getNavOpenTopImage() { 449 return getImage(navOpenTop, "navOpenTopImage", 450 DEFAULT_NAV_OPEN_TOP_GIF); 451 } 452 453 456 public String getNavOpenTopNoSiblingsImage() { 457 return getImage(navOpenTopNoSiblings, "navOpenTopNoSiblingsImage", 458 DEFAULT_NAV_OPEN_TOP_NO_SIBLINGS_GIF); 459 } 460 461 464 public String getNavCloseTopNoSiblingsImage() { 465 return getImage(navCloseTopNoSiblings, "navCloseTopNoSiblingsImage", 466 DEFAULT_NAV_CLOSE_TOP_NO_SIBLINGS_GIF); 467 } 468 469 472 public String getNavCloseBottomImage() { 473 return getImage(navCloseBottom, "navCloseBottomImage", 474 DEFAULT_NAV_CLOSE_BOTTOM_GIF); 475 } 476 477 480 public String getNavOpenBottomImage() { 481 return getImage(navOpenBottom, "navOpenBottomImage", 482 DEFAULT_NAV_OPEN_BOTTOM_GIF); 483 } 484 485 488 public String getLineBlankImage() { 489 return getImage(lineBlank, "lineBlank", DEFAULT_LINE_BLANK_GIF); 490 } 491 492 495 public String getLineBottomNode() { 496 return lineBottomNode; 497 } 498 499 502 public void setLineBottomNode(String lineBottomNode) { 503 this.lineBottomNode = lineBottomNode; 504 } 505 506 509 public String getLineMiddleNode() { 510 return lineMiddleNode; 511 } 512 513 516 public void setLineMiddleNode(String lineMiddleNode) { 517 this.lineMiddleNode = lineMiddleNode; 518 } 519 520 523 public String getLineVertical() { 524 return lineVertical; 525 } 526 527 530 public void setLineVertical(String lineVertical) { 531 this.lineVertical = lineVertical; 532 } 533 534 537 public String getNavExpandedMiddle() { 538 return navCloseMiddle; 539 } 540 541 544 public void setNavExpandedMiddle(String navExpandedMiddle) { 545 this.navCloseMiddle = navExpandedMiddle; 546 } 547 548 551 public String getNavExpandedTop() { 552 return navOpenTop; 553 } 554 555 558 public void setNavExpandedTop(String navExpandedTop) { 559 this.navOpenTop = navExpandedTop; 560 } 561 562 565 public void setImageDir(String imageDir) { 566 this.imageDir = imageDir; 567 } 568 569 572 public void setDocumentImage(String documentImage) { 573 this.documentImage = documentImage; 574 } 575 576 579 public void setFolderImage(String folderImage) { 580 this.folderImage = folderImage; 581 } 582 583 586 public String getNavCloseTop() { 587 return navCloseTop; 588 } 589 590 593 public void setNavCloseTop(String navCloseTop) { 594 this.navCloseTop = navCloseTop; 595 } 596 597 600 public String getNavOpenTop() { 601 return navOpenTop; 602 } 603 604 607 public void setNavOpenTop(String navOpenTop) { 608 this.navOpenTop = navOpenTop; 609 } 610 611 614 public String getNavOpenTopNoSiblings() { 615 return navOpenTopNoSiblings; 616 } 617 618 621 public void setNavOpenTopNoSiblings(String navOpenTopNoSiblings) { 622 this.navOpenTopNoSiblings = navOpenTopNoSiblings; 623 } 624 625 628 public String getNavCloseTopNoSiblings() { 629 return navCloseTopNoSiblings; 630 } 631 632 635 public void setNavCloseTopNoSiblings(String navCloseTopNoSiblings) { 636 this.navCloseTopNoSiblings = navCloseTopNoSiblings; 637 } 638 639 642 public void setFolderOpenImage(String folderOpenImage) { 643 this.folderOpenImage = folderOpenImage; 644 } 645 646 649 public String getNavCloseBottom() { 650 return navCloseBottom; 651 } 652 653 656 public void setNavCloseBottom(String navCloseBottom) { 657 this.navCloseBottom = navCloseBottom; 658 } 659 660 663 public String getNavCloseMiddle() { 664 return navCloseMiddle; 665 } 666 667 670 public void setNavCloseMiddle(String navCloseMiddle) { 671 this.navCloseMiddle = navCloseMiddle; 672 } 673 674 677 public String getNavOpenBottom() { 678 return navOpenBottom; 679 } 680 681 684 public void setNavOpenBottom(String navOpenBottom) { 685 this.navOpenBottom = navOpenBottom; 686 } 687 688 691 public String getNavOpenMiddle() { 692 return navOpenMiddle; 693 } 694 695 698 public void setNavOpenMiddle(String navOpenMiddle) { 699 this.navOpenMiddle = navOpenMiddle; 700 } 701 702 705 public String getVar() { 706 return var; 707 } 708 709 712 public void setVar(String var) { 713 this.var = var; 714 } 715 716 719 public String getLineBlank() { 720 return lineBlank; 721 } 722 723 726 public void setLineBlank(String lineBlank) { 727 this.lineBlank = lineBlank; 728 } 729 730 733 public DefaultMutableTreeNode getNavigatedNode() { 734 return navigatedNode; 735 } 736 737 740 public void setNavigatedNode(DefaultMutableTreeNode navigatedNode) { 741 this.navigatedNode = navigatedNode; 742 } 743 744 747 public void setNavigationEventType(String string) { 748 this.navigationEventType = string; 749 } 750 751 754 public String getNavigationEventType() { 755 return navigationEventType; 756 } 757 758 760 766 public Object saveState(FacesContext context) { 767 768 Object values[] = new Object [26]; 769 values[0] = super.saveState(context); 770 values[1] = navigatedNode; 771 values[2] = navigationEventType; 772 values[3] = imageDir; 773 values[4] = navOpenTop; 774 values[5] = navOpenTopNoSiblings; 775 values[6] = navCloseTopNoSiblings; 776 values[7] = navCloseTop; 777 values[8] = navCloseMiddle; 778 values[9] = navOpenMiddle; 779 values[10] = lineMiddleNode; 780 values[11] = lineBottomNode; 781 values[12] = lineVertical; 782 values[13] = lineBlank; 783 values[14] = documentImage; 784 values[15] = folderImage; 785 values[16] = folderOpenImage; 786 values[17] = navCloseBottom; 787 values[18] = navOpenBottom; 788 values[19] = var; 789 values[20] = styleClass; 790 values[21] = style; 791 values[22] = hideRootNode; 792 values[23] = hideNavigation; 793 values[24] = currentNode; 794 values[25] = nodePath; 795 796 return (values); 797 798 } 799 800 806 public void restoreState(FacesContext context, Object state) { 807 808 Object values[] = (Object []) state; 809 super.restoreState(context, values[0]); 810 navigatedNode = (DefaultMutableTreeNode ) values[1]; 811 navigationEventType = (String ) values[2]; 812 imageDir = (String ) values[3]; 813 navOpenTop = (String ) values[4]; 814 navOpenTopNoSiblings = (String ) values[5]; 815 navCloseTopNoSiblings = (String ) values[6]; 816 navCloseTop = (String ) values[7]; 817 navCloseMiddle = (String ) values[8]; 818 navOpenMiddle = (String ) values[9]; 819 lineMiddleNode = (String ) values[10]; 820 lineBottomNode = (String ) values[11]; 821 lineVertical = (String ) values[12]; 822 lineBlank = (String ) values[13]; 823 documentImage = (String ) values[14]; 824 folderImage = (String ) values[15]; 825 folderOpenImage = (String ) values[16]; 826 navCloseBottom = (String ) values[17]; 827 navOpenBottom = (String ) values[18]; 828 var = (String ) values[19]; 829 styleClass = (String ) values[20]; 830 style = (String ) values[21]; 831 hideRootNode = (Boolean ) values[22]; 832 hideNavigation = (Boolean ) values[23]; 833 currentNode = (DefaultMutableTreeNode ) values[24]; 834 nodePath = (String ) values[25]; 835 } 836 837 838 843 public void processDecodes(FacesContext context) { 844 if (context == null) { 845 throw new NullPointerException ("context"); 846 } 847 if (!isRendered()) { 848 return; 849 } 850 851 savedChildren = new HashMap (); 852 853 this.processTreeNodes((DefaultMutableTreeNode ) getModel().getRoot(), 854 PhaseId.APPLY_REQUEST_VALUES, context); 855 856 try { 857 this.setNodePath(null); 858 this.setCurrentNode(null); 859 decode(context); 860 } catch (RuntimeException e) { 861 context.renderResponse(); 862 throw e; 863 } 864 } 865 866 870 public void processValidators(FacesContext context) { 871 if (context == null) { 872 throw new NullPointerException ("context"); 873 } 874 if (!isRendered()) { 875 return; 876 } 877 878 this.processTreeNodes((DefaultMutableTreeNode ) getModel().getRoot(), 879 PhaseId.PROCESS_VALIDATIONS, context); 880 881 this.setNodePath(null); 882 this.setCurrentNode(null); 883 } 884 885 886 890 public void processUpdates(FacesContext context) { 891 if (context == null) { 892 throw new NullPointerException ("context"); 893 } 894 if (!isRendered()) { 895 return; 896 } 897 898 this.processTreeNodes((DefaultMutableTreeNode ) getModel().getRoot(), 899 PhaseId.UPDATE_MODEL_VALUES, context); 900 901 this.setNodePath(null); 902 this.setCurrentNode(null); 903 } 904 905 913 private void processTreeNodes(DefaultMutableTreeNode currentNode, 914 Object phaseId, 915 FacesContext context) { 916 this.setCurrentNode(currentNode); 918 919 TreeNode treeNodeTemplate = (TreeNode) this.getChildren().get(0); 920 String pathToCurrentNode = TreeRenderer.getPathAsString(currentNode, 921 (DefaultMutableTreeNode ) getModel() 922 .getRoot()); 923 treeNodeTemplate.setMutable(currentNode); 924 treeNodeTemplate.setId(ID_PREFIX + pathToCurrentNode); 925 treeNodeTemplate.setParent(this); 926 927 this.setNodePath(pathToCurrentNode); 928 929 UIComponent iconFacet; 931 UIComponent contentFacet; 932 933 iconFacet = treeNodeTemplate.getIcon(); 934 contentFacet = treeNodeTemplate.getContent(); 935 936 if (phaseId == PhaseId.APPLY_REQUEST_VALUES) { 938 if (iconFacet != null) { 939 iconFacet.processDecodes(context); 940 } 941 if (contentFacet != null) { 942 contentFacet.processDecodes(context); 943 } 944 } else if (phaseId == PhaseId.PROCESS_VALIDATIONS) { 945 if (iconFacet != null) { 946 iconFacet.processValidators(context); 947 } 948 if (contentFacet != null) { 949 contentFacet.processValidators(context); 950 } 951 952 } else if (phaseId == PhaseId.UPDATE_MODEL_VALUES) { 953 if (iconFacet != null) { 954 iconFacet.processUpdates(context); 955 } 956 if (contentFacet != null) { 957 contentFacet.processUpdates(context); 958 } 959 960 } 961 962 IceUserObject userObject = (IceUserObject) currentNode.getUserObject(); 964 if (userObject.isExpanded()) { 965 int childCount = currentNode.getChildCount(); 966 for (int childIndex = 0; childIndex < childCount; childIndex++) { 967 DefaultMutableTreeNode nextNode = 968 (DefaultMutableTreeNode ) currentNode 969 .getChildAt(childIndex); 970 971 processTreeNodes(nextNode, 972 phaseId, 973 context); 974 } 975 } 976 } 977 978 983 public void queueEvent(FacesEvent event) { 984 UIComponent eventComponent = event.getComponent(); 985 UIComponent parentTreeNode = eventComponent.getParent(); 986 while (parentTreeNode != null && 987 !(parentTreeNode instanceof TreeNode)) { 988 parentTreeNode = parentTreeNode.getParent(); 989 } 990 if (parentTreeNode == null) { 991 super.queueEvent(event); 993 return; 994 } 995 super.queueEvent(new NodeEvent(this, event, 996 ((TreeNode) parentTreeNode).getMutable())); 997 } 998 999 1004 public void broadcast(FacesEvent event) throws AbortProcessingException { 1005 1006 if (!(event instanceof NodeEvent)) { 1007 super.broadcast(event); 1008 return; 1009 } 1010 1011 NodeEvent wrapperEvent = (NodeEvent) event; 1013 DefaultMutableTreeNode eventNode = wrapperEvent.getNode(); 1014 this.setCurrentNode(eventNode); 1015 this.setNodePath(TreeRenderer.getPathAsString(eventNode, 1016 (DefaultMutableTreeNode ) getModel() 1017 .getRoot())); 1018 1019 FacesEvent facesEvent = wrapperEvent.getFacesEvent(); 1020 facesEvent.getComponent().broadcast(facesEvent); 1021 } 1022 1023 1027 private void setCurrentVarToRequestMap(FacesContext context, 1028 DefaultMutableTreeNode currentVar) { 1029 Map requestMap = context.getExternalContext().getRequestMap(); 1030 String varAttribute = getVar(); 1031 if (currentVar != null) { 1032 requestMap.put(varAttribute, currentVar); 1033 } 1034 } 1035 1036 1039 public String getHideNavigation() { 1040 1041 if (hideNavigation != null) { 1042 return hideNavigation.toString(); 1043 } 1044 ValueBinding vb = getValueBinding("hideNavigation"); 1045 if (vb != null) { 1046 return vb.getValue(getFacesContext()).toString(); 1047 } 1048 return String.valueOf(false); 1049 1050 } 1051 1052 1055 public void setHideNavigation(String b) { 1056 hideNavigation = new Boolean (b); 1057 } 1058 1059 1062 public String getHideRootNode() { 1063 1064 if (hideRootNode != null) { 1065 return hideRootNode.toString(); 1066 } 1067 ValueBinding vb = getValueBinding("hideRootNode"); 1068 if (vb != null) { 1069 return vb.getValue(getFacesContext()).toString(); 1070 } 1071 return String.valueOf(false); 1072 } 1073 1074 1077 public void setHideRootNode(String b) { 1078 hideRootNode = new Boolean (b); 1079 } 1080 1081 class NodeEvent extends FacesEvent { 1086 1087 1090 private static final long serialVersionUID = 1L; 1091 1092 private FacesEvent event = null; 1093 1094 private DefaultMutableTreeNode node = null; 1095 1096 1101 public NodeEvent(UIComponent component, FacesEvent event, 1102 DefaultMutableTreeNode node) { 1103 super(component); 1104 this.event = event; 1105 this.node = node; 1106 } 1107 1108 1111 public DefaultMutableTreeNode getNode() { 1112 return node; 1113 } 1114 1115 1118 public void setNode(DefaultMutableTreeNode node) { 1119 this.node = node; 1120 } 1121 1122 1125 public FacesEvent getFacesEvent() { 1126 return (this.event); 1127 } 1128 1129 1132 public PhaseId getPhaseId() { 1133 return (this.event.getPhaseId()); 1134 } 1135 1136 1139 public void setPhaseId(PhaseId phaseId) { 1140 this.event.setPhaseId(phaseId); 1141 } 1142 1143 1146 public boolean isAppropriateListener(FacesListener listener) { 1147 return (false); 1148 } 1149 1150 1153 public void processListener(FacesListener listener) { 1154 throw new IllegalStateException (); 1155 } 1156 1157 } 1158 1159 1160 1164 protected Map savedChildren = new HashMap (); 1165 1166 1167 1172 protected void restoreChildrenState(FacesContext context) { 1173 Iterator kids = getChildren().iterator(); 1174 while (kids.hasNext()) { 1175 UIComponent kid = (UIComponent) kids.next(); 1176 restoreChildState(kid, context); 1177 } 1178 } 1179 1180 1186 protected void restoreChild(UIComponent component, FacesContext context) { 1187 if (component instanceof EditableValueHolder) { 1189 EditableValueHolder input = (EditableValueHolder) component; 1190 String clientId = component.getClientId(context); 1191 ChildState state = (ChildState) savedChildren.get(clientId); 1192 if (state == null) { 1193 state = new ChildState(); 1194 } 1195 input.setValue(state.getValue()); 1196 input.setValid(state.isValid()); 1197 input.setSubmittedValue(state.getSubmittedValue()); 1198 input.setLocalValueSet(state.isLocalValueSet()); 1199 } 1200 } 1201 1202 1209 private void restoreChildState(UIComponent component, 1210 FacesContext context) { 1211 1212 String id = component.getId(); 1214 component.setId(id); restoreChild(component, context); 1217 1218 Iterator kids = component.getFacetsAndChildren(); 1220 while (kids.hasNext()) { 1221 restoreChildState((UIComponent) kids.next(), context); 1222 } 1223 } 1224 1225 1230 protected void saveChildrenState(FacesContext context) { 1231 1232 Iterator kids = getChildren().iterator(); 1233 while (kids.hasNext()) { 1234 UIComponent kid = (UIComponent) kids.next(); 1235 saveChildState(kid, context); 1236 } 1237 } 1238 1239 1245 protected void saveChild(UIComponent component, FacesContext context) { 1246 if (component instanceof EditableValueHolder) { 1248 EditableValueHolder input = (EditableValueHolder) component; 1249 String clientId = component.getClientId(context); 1250 ChildState state = (ChildState) savedChildren.get(clientId); 1251 if (state == null) { 1252 state = new ChildState(); 1253 savedChildren.put(clientId, state); 1254 } 1255 state.setValue(input.getLocalValue()); 1256 state.setValid(input.isValid()); 1257 state.setSubmittedValue(input.getSubmittedValue()); 1258 state.setLocalValueSet(input.isLocalValueSet()); 1259 } 1260 } 1261 1262 1269 protected void saveChildState(UIComponent component, FacesContext context) { 1270 saveChild(component, context); 1272 Iterator kids = component.getFacetsAndChildren(); 1274 while (kids.hasNext()) { 1275 saveChildState((UIComponent) kids.next(), context); 1276 } 1277 } 1278} 1279 1280 1282class ChildState implements Serializable { 1283 1284 1287 private static final long serialVersionUID = 1L; 1288 private Object submittedValue; 1289 private boolean valid = true; 1290 private Object value; 1291 private boolean localValueSet; 1292 1293 Object getSubmittedValue() { 1294 return (this.submittedValue); 1295 } 1296 1297 void setSubmittedValue(Object submittedValue) { 1298 this.submittedValue = submittedValue; 1299 } 1300 1301 boolean isValid() { 1302 return (this.valid); 1303 } 1304 1305 void setValid(boolean valid) { 1306 this.valid = valid; 1307 } 1308 1309 Object getValue() { 1310 return (this.value); 1311 } 1312 1313 1316 public void setValue(Object value) { 1317 this.value = value; 1318 } 1319 1320 boolean isLocalValueSet() { 1321 return (this.localValueSet); 1322 } 1323 1324 1327 public void setLocalValueSet(boolean localValueSet) { 1328 this.localValueSet = localValueSet; 1329 } 1330} 1331 1332 1333 | Popular Tags |