1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javax.faces.webapp;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23
24 import javax.faces.FacesException;
25 import javax.faces.FactoryFinder;
26 import javax.faces.application.Application;
27 import javax.faces.component.UIComponent;
28 import javax.faces.component.UIViewRoot;
29 import javax.faces.component.UIOutput;
30 import javax.faces.context.FacesContext;
31 import javax.faces.context.ResponseWriter;
32 import javax.faces.context.ExternalContext;
33 import javax.faces.el.ValueBinding;
34 import javax.faces.render.RenderKit;
35 import javax.faces.render.RenderKitFactory;
36
37 import javax.servlet.jsp.JspException;
38 import javax.servlet.jsp.PageContext;
39 import javax.servlet.jsp.JspWriter;
40 import javax.servlet.jsp.tagext.Tag;
41 import javax.servlet.jsp.tagext.BodyContent;
42 import java.io.IOException;
43 import java.io.Reader;
44 import java.util.*;
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 public abstract class UIComponentTag
62 implements Tag
63 {
64 private static final String FORMER_CHILD_IDS_SET_ATTR = UIComponentTag.class.getName() + ".FORMER_CHILD_IDS";
65 private static final String FORMER_FACET_NAMES_SET_ATTR = UIComponentTag.class.getName() + ".FORMER_FACET_NAMES";
66 private static final String COMPONENT_STACK_ATTR = UIComponentTag.class.getName() + ".COMPONENT_STACK";
67
68 private static final String UNIQUE_ID_COUNTER_ATTR = UIComponentTag.class.getName() + ".UNIQUE_ID_COUNTER";
69
70 private static final String PARTIAL_STATE_SAVING_METHOD_PARAM_NAME = "javax.faces.PARTIAL_STATE_SAVING_METHOD";
71 private static final String PARTIAL_STATE_SAVING_METHOD_ON = "true";
72 private static final String PARTIAL_STATE_SAVING_METHOD_OFF = "false";
73
74 private static final String BEFORE_VIEW_CONTEXT = "org.apache.myfaces.BEFORE_VIEW_CONTEXT";
75
76 protected PageContext pageContext = null;
77 private Tag _parent = null;
78
79
80 private String _binding = null;
81 private String _id = null;
82 private String _rendered = null;
83
84 private FacesContext _facesContext = null;
85 private UIComponent _componentInstance = null;
86 private boolean _created = false;
87 private Boolean _suppressed = null;
88 private ResponseWriter _writer = null;
89 private Set _childrenAdded = null;
90 private Set _facetsAdded = null;
91 private Boolean _partialStateSaving = null;
92
93 private static Log log = LogFactory.getLog(UIComponentTag.class);
94 private static final int READ_LENGTH = 8000;
95
96 private boolean isPartialStateSavingOn(javax.faces.context.FacesContext context)
97 {
98 if(context == null) throw new NullPointerException("context");
99 if (_partialStateSaving != null) return _partialStateSaving.booleanValue();
100 String stateSavingMethod = context.getExternalContext().getInitParameter(PARTIAL_STATE_SAVING_METHOD_PARAM_NAME);
101 if (stateSavingMethod == null)
102 {
103 _partialStateSaving = Boolean.FALSE;
104 context.getExternalContext().log("No context init parameter '"+PARTIAL_STATE_SAVING_METHOD_PARAM_NAME+"' found; no partial state saving method defined, assuming default partial state saving method off.");
105 }
106 else if (stateSavingMethod.equals(PARTIAL_STATE_SAVING_METHOD_ON))
107 {
108 _partialStateSaving = Boolean.TRUE;
109 }
110 else if (stateSavingMethod.equals(PARTIAL_STATE_SAVING_METHOD_OFF))
111 {
112 _partialStateSaving = Boolean.FALSE;
113 }
114 else
115 {
116 _partialStateSaving = Boolean.FALSE;
117 context.getExternalContext().log("Illegal context init parameter '"+PARTIAL_STATE_SAVING_METHOD_PARAM_NAME+"' found; illegal partial state saving method '" + stateSavingMethod + "', default partial state saving will be used (partial state saving off).");
118 }
119 return _partialStateSaving.booleanValue();
120 }
121
122
123 public UIComponentTag()
124 {
125
126 }
127
128 public void release()
129 {
130 internalRelease();
131
132
133
134 pageContext = null;
135 _parent = null;
136
137
138
139
140 _binding = null;
141 _id = null;
142 _rendered = null;
143 }
144
145
146
147
148
149
150
151
152 private void internalRelease()
153 {
154 _facesContext = null;
155 _componentInstance = null;
156 _created = false;
157 _suppressed = null;
158 _writer = null;
159 _childrenAdded = null;
160 _facetsAdded = null;
161 }
162
163
164 public void setBinding(String binding)
165 throws JspException
166 {
167 if (!isValueReference(binding))
168 {
169 throw new IllegalArgumentException("not a valid binding: " + binding);
170 }
171 _binding = binding;
172 }
173
174
175 public void setId(String id)
176 {
177 _id = id;
178 }
179
180
181
182
183 protected String getId()
184 {
185 return _id;
186 }
187
188
189 public void setRendered(String rendered)
190 {
191 _rendered = rendered;
192 }
193
194
195
196
197
198
199
200
201
202
203 public abstract String getComponentType();
204
205
206
207
208
209 public UIComponent getComponentInstance()
210 {
211 return _componentInstance;
212 }
213
214
215
216
217
218 public boolean getCreated()
219 {
220 return _created;
221 }
222
223
224
225
226 public static UIComponentTag getParentUIComponentTag(PageContext pageContext)
227 {
228
229
230
231 List list = (List)pageContext.getAttribute(COMPONENT_STACK_ATTR,
232 PageContext.REQUEST_SCOPE);
233 if (list != null)
234 {
235 return (UIComponentTag)list.get(list.size() - 1);
236 }
237 return null;
238 }
239
240
241 private void popTag()
242 {
243 List list = (List)pageContext.getAttribute(COMPONENT_STACK_ATTR,
244 PageContext.REQUEST_SCOPE);
245 if (list != null)
246 {
247 int size = list.size();
248 list.remove(size -1);
249 if (size <= 1)
250 {
251 pageContext.removeAttribute(COMPONENT_STACK_ATTR,
252 PageContext.REQUEST_SCOPE);
253 }
254 }
255 }
256
257
258
259
260
261
262
263
264
265
266 private void pushTag()
267 {
268 List list = (List)pageContext.getAttribute(COMPONENT_STACK_ATTR,
269 PageContext.REQUEST_SCOPE);
270 if (list == null)
271 {
272 list = new ArrayList();
273 pageContext.setAttribute(COMPONENT_STACK_ATTR,
274 list,
275 PageContext.REQUEST_SCOPE);
276 }
277 list.add(this);
278 }
279
280
281
282
283
284
285
286
287
288
289 public abstract String getRendererType();
290
291
292
293
294
295
296
297
298 public static boolean isValueReference(String value)
299 {
300 if (value == null) throw new NullPointerException("value");
301
302 int start = value.indexOf("#{");
303 if (start < 0) return false;
304
305 int end = value.lastIndexOf('}');
306 return (end >=0 && start < end);
307 }
308
309
310
311
312
313
314 public void setPageContext(PageContext pageContext)
315 {
316 this.pageContext = pageContext;
317 }
318
319
320
321
322
323 public Tag getParent()
324 {
325 return _parent;
326 }
327
328
329
330
331
332 public void setParent(Tag parent)
333 {
334 _parent = parent;
335 }
336
337
338
339
340
341
342
343
344
345
346 private void flushWriter( JspWriter writerToFlush ) throws JspException,IOException {
347
348 if (getFacesContext() == null)
349 return;
350 BodyContent tempwriter;
351 _componentInstance = findComponent(_facesContext);
352 if (writerToFlush instanceof BodyContent)
353 {
354 int count = 0;
355 char [] readChars = new char[READ_LENGTH];
356 tempwriter = (BodyContent) writerToFlush;
357 Reader read =tempwriter.getReader();
358 count = read.read(readChars,0,READ_LENGTH);
359 String readString = new String(readChars,0,count);
360 if(!readString.trim().equals(""))
361 {
362
363 UIComponentTag parentTag = getParentUIComponentTag(pageContext);
364 addOutputComponentAfterComponent(parentTag,createUIOutputComponentFromString(readString),_componentInstance);
365 tempwriter.clearBody();
366 }
367
368 }
369 else
370 {
371 if (_componentInstance.getParent() == null) {
372 writerToFlush.flush();
373 String beforeViewContent = _facesContext.getExternalContext().getResponse().toString();
374 if((beforeViewContent != null)&&(!beforeViewContent.trim().equals("")))
375 {
376 _facesContext.getExternalContext().getRequestMap().put(BEFORE_VIEW_CONTEXT,beforeViewContent);
377 }
378 }
379 }
380
381 }
382
383
384
385
386
387
388
389 private void addOutputComponentAfterComponent(UIComponentTag parentTag,
390 UIComponent outputComponent,
391 UIComponent component) {
392 int indexOfComponentInParent = 0;
393 UIComponent parent = component.getParent();
394
395 if (null == parent) {
396 return;
397 }
398 List children = parent.getChildren();
399 indexOfComponentInParent = children.indexOf(component);
400 if (children.size() - 1 == indexOfComponentInParent) {
401 children.add(outputComponent);
402 }
403 else {
404 children.add(indexOfComponentInParent + 1, outputComponent);
405 }
406 parentTag.addChildIdToParentTag(parentTag,outputComponent.getId());
407
408 }
409
410
411
412
413
414
415
416
417
418 private UIComponent createUIOutputComponentFromString( String content) {
419 UIOutput outputComponent = null;
420
421 outputComponent = createUIOutputComponent(getFacesContext());
422 outputComponent.setValue(content);
423
424 return outputComponent;
425 }
426
427
428
429
430
431
432
433
434
435
436 private UIOutput createUIOutputComponent(FacesContext context) {
437 if (context == null) return null;
438 UIOutput outputComponent = null;
439 Application application = context.getApplication();
440 outputComponent = (UIOutput) application.createComponent("javax.faces.HtmlOutputText");
441 outputComponent.setTransient(true);
442 outputComponent.getAttributes().put("escape", Boolean.FALSE);
443 outputComponent.setId(context.getViewRoot().createUniqueId());
444 return outputComponent;
445 }
446
447
448
449
450
451
452
453
454
455
456
457
458 public int doStartTag()
459 throws JspException
460 {
461 setupResponseWriter();
462 FacesContext facesContext = getFacesContext();
463 if ( isPartialStateSavingOn(facesContext) )
464 {
465 JspWriter writer = pageContext.getOut();
466 try {
467 flushWriter(writer);
468 } catch (IOException e) {
469 log.error(e.toString());
470 }
471 }
472 UIComponent component = findComponent(facesContext);
473 if (!component.getRendersChildren() && !isSuppressed())
474 {
475 try
476 {
477 encodeBegin();
478 _writer.flush();
479 }
480 catch (IOException e)
481 {
482 throw new JspException(e.getMessage(), e);
483 }
484 }
485 pushTag();
486 return getDoStartValue();
487 }
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506 public int doEndTag()
507 throws JspException
508 {
509 if (isPartialStateSavingOn(getFacesContext()))
510 {
511 JspWriter writerToFlush = pageContext.getOut();
512 if (_componentInstance == null) {
513 findComponent(getFacesContext());
514 }
515 if ((!(writerToFlush instanceof BodyContent)) && _componentInstance.getParent() == null) {
516
517 _componentInstance.getChildren().add(0,
518 createUIOutputComponentFromString((String)
519 _facesContext.getExternalContext().getRequestMap().get(BEFORE_VIEW_CONTEXT)));
520 _facesContext.getExternalContext().getRequestMap().remove(BEFORE_VIEW_CONTEXT);
521 }
522 }
523
524 popTag();
525 UIComponent component = getComponentInstance();
526 removeFormerChildren(component);
527 removeFormerFacets(component);
528
529 try
530 {
531 if (!isSuppressed())
532 {
533
534
535
536
537
538
539
540
541 if (component.getRendersChildren())
542 {
543 encodeBegin();
544 encodeChildren();
545 }
546 encodeEnd();
547 }
548 }
549 catch (IOException e)
550 {
551 throw new JspException(e.getMessage(), e);
552 }
553
554 int retValue = getDoEndValue();
555 internalRelease();
556 return retValue;
557 }
558
559
560
561
562
563
564
565
566
567
568
569
570 private void removeFormerChildren(UIComponent component)
571 {
572 Set formerChildIdsSet = (Set)component.getAttributes().get(FORMER_CHILD_IDS_SET_ATTR);
573 if (formerChildIdsSet != null)
574 {
575 for (Iterator iterator = formerChildIdsSet.iterator(); iterator.hasNext();)
576 {
577 String childId = (String)iterator.next();
578 if (_childrenAdded == null || !_childrenAdded.contains(childId))
579 {
580 UIComponent childToRemove = component.findComponent(childId);
581 if (childToRemove != null)
582 {
583 component.getChildren().remove(childToRemove);
584 }
585 }
586 }
587 if (_childrenAdded == null)
588 {
589 component.getAttributes().remove(FORMER_CHILD_IDS_SET_ATTR);
590 }
591 else
592 {
593 component.getAttributes().put(FORMER_CHILD_IDS_SET_ATTR, _childrenAdded);
594 }
595 }
596 else
597 {
598 if (_childrenAdded != null)
599 {
600 component.getAttributes().put(FORMER_CHILD_IDS_SET_ATTR, _childrenAdded);
601 }
602 }
603 }
604
605
606 private void removeFormerFacets(UIComponent component)
607 {
608 Set formerFacetNamesSet = (Set)component.getAttributes().get(FORMER_FACET_NAMES_SET_ATTR);
609 if (formerFacetNamesSet != null)
610 {
611 for (Iterator iterator = formerFacetNamesSet.iterator(); iterator.hasNext();)
612 {
613 String facetName = (String)iterator.next();
614 if (_facetsAdded == null || !_facetsAdded.contains(facetName))
615 {
616 component.getFacets().remove(facetName);
617 }
618 }
619 if (_facetsAdded == null)
620 {
621 component.getAttributes().remove(FORMER_FACET_NAMES_SET_ATTR);
622 }
623 else
624 {
625 component.getAttributes().put(FORMER_FACET_NAMES_SET_ATTR, _facetsAdded);
626 }
627 }
628 else
629 {
630 if (_facetsAdded != null)
631 {
632 component.getAttributes().put(FORMER_FACET_NAMES_SET_ATTR, _facetsAdded);
633 }
634 }
635 }
636
637
638
639
640
641
642 protected void encodeBegin()
643 throws IOException
644 {
645 if(log.isDebugEnabled())
646 log.debug("Entered encodeBegin for client-Id: "+_componentInstance.getClientId(getFacesContext()));
647 _componentInstance.encodeBegin(getFacesContext());
648 if(log.isDebugEnabled())
649 log.debug("Exited encodeBegin");
650 }
651
652
653
654
655
656
657
658 protected void encodeChildren()
659 throws IOException
660 {
661 if(log.isDebugEnabled())
662 log.debug("Entered encodeChildren for client-Id: "+_componentInstance.getClientId(getFacesContext()));
663 _componentInstance.encodeChildren(getFacesContext());
664 if(log.isDebugEnabled())
665 log.debug("Exited encodeChildren for client-Id: "+_componentInstance.getClientId(getFacesContext()));
666 }
667
668
669
670
671
672
673 protected void encodeEnd()
674 throws IOException
675 {
676 if(log.isDebugEnabled())
677 log.debug("Entered encodeEnd for client-Id: "+_componentInstance.getClientId(getFacesContext()));
678 _componentInstance.encodeEnd(getFacesContext());
679 if(log.isDebugEnabled())
680 log.debug("Exited encodeEnd for client-Id: "+_componentInstance.getClientId(getFacesContext()));
681
682 }
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710 protected UIComponent findComponent(FacesContext context)
711 throws JspException
712 {
713 if (_componentInstance != null) return _componentInstance;
714 UIComponentTag parentTag = getParentUIComponentTag(pageContext);
715 if (parentTag == null)
716 {
717
718 _componentInstance = context.getViewRoot();
719 setProperties(_componentInstance);
720 return _componentInstance;
721 }
722
723 UIComponent parent = parentTag.getComponentInstance();
724
725 if (parent == null) throw new IllegalStateException("parent is null?");
726
727 String facetName = getFacetName();
728 if (facetName != null)
729 {
730
731 String id = getOrCreateUniqueId(context);
732 _componentInstance = parent.getFacet(facetName);
733 if (_componentInstance == null)
734 {
735 _componentInstance = createComponentInstance(context, id);
736 setProperties(_componentInstance);
737 parent.getFacets().put(facetName, _componentInstance);
738 }
739 else
740 {
741 if (checkFacetNameOnParentExists(parentTag, facetName))
742 {
743 throw new IllegalStateException("facet '" + facetName + "' already has a child associated. current associated component id: "
744 + _componentInstance.getClientId(context) + " class: " + _componentInstance.getClass().getName());
745 }
746 }
747
748 addFacetNameToParentTag(parentTag, facetName);
749 return _componentInstance;
750 }
751 else
752 {
753
754
755
756
757
758
759
760 String id = getOrCreateUniqueId(context);
761
762
763
764
765
766
767
768 if(parentTag._childrenAdded != null && parentTag._childrenAdded.contains(id))
769 {
770 throw new FacesException("There is more than one JSF tag with id : " + id+" for parent component with id : '"+parent.getId()+"'");
771 }
772
773 _componentInstance = findComponent(parent,id);
774 if (_componentInstance == null)
775 {
776 _componentInstance = createComponentInstance(context, id);
777 if (id.equals(_componentInstance.getId()) )
778 {
779 setProperties(_componentInstance);
780 int index = getAddedChildrenCount(parentTag);
781 List children = parent.getChildren();
782 if (index <= children.size())
783 {
784 children.add(index, _componentInstance);
785 }
786 else
787 {
788 throw new FacesException("cannot add component with id '" +
789 _componentInstance.getId() + " to its parent component with id : '"+parent.getId()+"' and path '"+
790 getPathToComponent(parent)+"'at position :"+index+" in list of children. "+
791 "This might be a problem due to a duplicate id in a previously added component,"+
792 "if this is the case, the problematic id might be one of : "+printSet(parentTag._childrenAdded));
793 }
794 }
795
796
797
798
799
800 else if (null == findComponent(parent,_componentInstance.getId()))
801 {
802 setProperties(_componentInstance);
803 int index = getAddedChildrenCount(parentTag);
804 List children = parent.getChildren();
805 if (index <= children.size())
806 {
807 children.add(index, _componentInstance);
808 }
809 else
810 {
811 throw new FacesException("cannot add component with id '" +
812 _componentInstance.getId() + " to its parent component with id : '"+parent.getId()+"' and path '"+
813 getPathToComponent(parent)+"'at position :"+index+" in list of children. "+
814 "This might be a problem due to a duplicate id in a previously added component,"+
815 "if this is the case, the problematic id might be one of : "+printSet(parentTag._childrenAdded));
816 }
817 }
818 }
819 addChildIdToParentTag(parentTag, id);
820 return _componentInstance;
821 }
822 }
823
824 private UIComponent findComponent(UIComponent parent, String id)
825 {
826 List li = parent.getChildren();
827
828 for (int i = 0; i < li.size(); i++)
829 {
830 UIComponent uiComponent = (UIComponent) li.get(i);
831 if(uiComponent.getId()!=null && uiComponent.getId().equals(id))
832 {
833 return uiComponent;
834 }
835 }
836
837 return null;
838 }
839
840
841
842
843 private String printSet(Set childrenAdded)
844 {
845 StringBuffer buf = new StringBuffer();
846
847 if(childrenAdded!=null)
848 {
849 Iterator it = childrenAdded.iterator();
850
851 while (it.hasNext())
852 {
853 Object obj = it.next();
854 buf.append(obj);
855
856 if(it.hasNext())
857 buf.append(",");
858 }
859 }
860 return buf.toString();
861 }
862
863
864 private String getOrCreateUniqueId(FacesContext context)
865 {
866 String id = getId();
867 if (id != null)
868 {
869 return id;
870 }
871 else
872 {
873
874
875 Long currentCounter = (Long) context.getExternalContext().getRequestMap().get(UNIQUE_ID_COUNTER_ATTR);
876 long lCurrentCounter = 0;
877
878 if(currentCounter!=null)
879 {
880 lCurrentCounter = currentCounter.longValue();
881 }
882
883 StringBuffer retValue = new StringBuffer(UIViewRoot.UNIQUE_ID_PREFIX);
884 retValue.append("Jsp");
885 retValue.append(lCurrentCounter);
886
887 lCurrentCounter++;
888
889 context.getExternalContext().getRequestMap().put(UNIQUE_ID_COUNTER_ATTR,new Long(lCurrentCounter));
890
891 ExternalContext extCtx = FacesContext.getCurrentInstance().getExternalContext();
892 return extCtx.encodeNamespace(retValue.toString());
893 }
894 }
895
896
897
898
899
900
901
902
903 private UIComponent createComponentInstance(FacesContext context, String id)
904 {
905 String componentType = getComponentType();
906 if (componentType == null)
907 {
908 throw new NullPointerException("componentType");
909 }
910
911 if (_binding != null)
912 {
913 Application application = context.getApplication();
914 ValueBinding componentBinding = application.createValueBinding(_binding);
915 UIComponent component = application.createComponent(componentBinding,
916 context,
917 componentType);
918 component.setId(id);
919 component.setValueBinding("binding", componentBinding);
920 recurseFacetsAndChildrenForId(component.getFacetsAndChildren(), id + "_", 0);
921 _created = true;
922 return component;
923 }
924 else
925 {
926 UIComponent component = context.getApplication().createComponent(componentType);
927 component.setId(id);
928 _created = true;
929 return component;
930 }
931 }
932
933
934
935
936
937
938
939 private int recurseFacetsAndChildrenForId(
940 Iterator facetsAndChildren,
941 String idPrefix,
942 int cnt)
943 {
944 while (facetsAndChildren.hasNext())
945 {
946 UIComponent comp = (UIComponent)facetsAndChildren.next();
947 if (comp.getId() == null)
948 {
949 ++cnt;
950 comp.setId(idPrefix + cnt);
951 }
952 cnt = recurseFacetsAndChildrenForId(comp.getFacetsAndChildren(), idPrefix, cnt);
953 }
954 return cnt;
955 }
956
957
958
959
960
961
962 private void addChildIdToParentTag(UIComponentTag parentTag, String id)
963 {
964 if (parentTag._childrenAdded == null)
965 {
966 parentTag._childrenAdded = new HashSet();
967 }
968 parentTag._childrenAdded.add(id);
969 }
970
971
972
973
974 private boolean checkFacetNameOnParentExists(UIComponentTag parentTag, String facetName)
975 {
976 return parentTag._facetsAdded != null && parentTag._facetsAdded.contains(facetName);
977 }
978
979
980
981
982
983
984 private void addFacetNameToParentTag(UIComponentTag parentTag, String facetName)
985 {
986 if (parentTag._facetsAdded == null)
987 {
988 parentTag._facetsAdded = new HashSet();
989 }
990 parentTag._facetsAdded.add(facetName);
991 }
992
993 private int getAddedChildrenCount(UIComponentTag parentTag)
994 {
995 return parentTag._childrenAdded != null ?
996 parentTag._childrenAdded.size() :
997 0;
998 }
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009 protected int getDoStartValue()
1010 throws JspException
1011 {
1012 return Tag.EVAL_BODY_INCLUDE;
1013 }
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024 protected int getDoEndValue()
1025 throws JspException
1026 {
1027 return Tag.EVAL_PAGE;
1028 }
1029
1030 protected FacesContext getFacesContext()
1031 {
1032 if (_facesContext == null)
1033 {
1034 _facesContext = FacesContext.getCurrentInstance();
1035 }
1036 return _facesContext;
1037 }
1038
1039
1040 private boolean isFacet()
1041 {
1042 return _parent != null && _parent instanceof FacetTag;
1043 }
1044
1045 protected String getFacetName()
1046 {
1047 return isFacet() ? ((FacetTag)_parent).getName() : null;
1048 }
1049
1050
1051
1052
1053
1054
1055 protected boolean isSuppressed()
1056 {
1057 if (_suppressed == null)
1058 {
1059
1060
1061
1062 if (isFacet())
1063 {
1064
1065 _suppressed = Boolean.TRUE;
1066 return true;
1067 }
1068
1069 UIComponent component = getComponentInstance();
1070
1071
1072
1073
1074
1075 UIComponent parent = component.getParent();
1076 while (parent != null)
1077 {
1078 if (parent.getRendersChildren())
1079 {
1080
1081 _suppressed = Boolean.TRUE;
1082 return true;
1083 }
1084 parent = parent.getParent();
1085 }
1086
1087
1088 while (component != null)
1089 {
1090 if (!component.isRendered())
1091 {
1092
1093 _suppressed = Boolean.TRUE;
1094 return true;
1095 }
1096 component = component.getParent();
1097 }
1098
1099
1100 _suppressed = Boolean.FALSE;
1101 }
1102 return _suppressed.booleanValue();
1103 }
1104
1105 protected void setProperties(UIComponent component)
1106 {
1107 if (getRendererType() != null)
1108 {
1109 _componentInstance.setRendererType(getRendererType());
1110 }
1111
1112 if (_rendered != null)
1113 {
1114 if (isValueReference(_rendered))
1115 {
1116 ValueBinding vb = getFacesContext().getApplication().createValueBinding(_rendered);
1117 component.setValueBinding("rendered", vb);
1118 } else
1119 {
1120 boolean b = Boolean.valueOf(_rendered).booleanValue();
1121 component.setRendered(b);
1122 }
1123 }
1124 }
1125
1126 protected void setupResponseWriter()
1127 {
1128 FacesContext facesContext = getFacesContext();
1129
1130 if(facesContext == null)
1131 {
1132 throw new FacesException("Faces context not found. getResponseWriter will fail. "+
1133 "Check if the FacesServlet has been initialized at all in your web.xml configuration file"+
1134 "and if you are accessing your jsf-pages through the correct mapping. E.g.: if your FacesServlet is mapped to "+
1135 " *.jsf (with the <servlet-mapping>-element), you need to access your pages as 'sample.jsf'. If you tried to access 'sample.jsp', you'd get this error-message."
1136 );
1137 }
1138
1139 _writer = facesContext.getResponseWriter();
1140 if (_writer == null)
1141 {
1142 RenderKitFactory renderFactory = (RenderKitFactory)FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
1143 RenderKit renderKit = renderFactory.getRenderKit(facesContext,
1144 facesContext.getViewRoot().getRenderKitId());
1145
1146 if (isPartialStateSavingOn(facesContext)) {
1147 _writer = renderKit.createResponseWriter(new _DummyPageContextOutWriter(pageContext),
1148 null
1149 pageContext.getRequest().getCharacterEncoding());
1150 } else {
1151 _writer = renderKit.createResponseWriter(new _PageContextOutWriter(pageContext),
1152 null
1153 pageContext.getRequest().getCharacterEncoding());
1154
1155 }
1156 facesContext.setResponseWriter(_writer);
1157 }
1158 }
1159
1160
1161 private String getPathToComponent(UIComponent component)
1162 {
1163 StringBuffer buf = new StringBuffer();
1164
1165 if(component == null)
1166 {
1167 buf.append("{Component-Path : ");
1168 buf.append("[null]}");
1169 return buf.toString();
1170 }
1171
1172 getPathToComponent(component,buf);
1173
1174 buf.insert(0,"{Component-Path : ");
1175 buf.append("}");
1176
1177 return buf.toString();
1178 }
1179
1180
1181 private static void getPathToComponent(UIComponent component, StringBuffer buf)
1182 {
1183 if(component == null)
1184 return;
1185
1186 StringBuffer intBuf = new StringBuffer();
1187
1188 intBuf.append("[Class: ");
1189 intBuf.append(component.getClass().getName());
1190 if(component instanceof UIViewRoot)
1191 {
1192 intBuf.append(",ViewId: ");
1193 intBuf.append(((UIViewRoot) component).getViewId());
1194 }
1195 else
1196 {
1197 intBuf.append(",Id: ");
1198 intBuf.append(component.getId());
1199 }
1200 intBuf.append("]");
1201
1202 buf.insert(0,(Object)intBuf);
1203
1204 getPathToComponent(component.getParent(),buf);
1205 }
1206
1207 }