1 16 package org.apache.myfaces.custom.tree.renderkit.html; 17 18 import java.io.IOException ; 19 import java.util.Set ; 20 21 import javax.faces.FacesException; 22 import javax.faces.component.UIComponent; 23 import javax.faces.component.UISelectMany; 24 import javax.faces.context.FacesContext; 25 import javax.faces.convert.Converter; 26 27 import org.apache.myfaces.custom.tree.HtmlTreeCheckbox; 28 import org.apache.myfaces.renderkit.RendererUtils; 29 import org.apache.myfaces.renderkit.html.HtmlCheckboxRendererBase; 30 31 34 public class HtmlTreeCheckboxRenderer extends HtmlCheckboxRendererBase 35 { 36 37 41 public void encodeEnd(FacesContext context, UIComponent component) throws IOException 42 { 43 HtmlTreeCheckbox checkbox = (HtmlTreeCheckbox) component; 44 45 String forAttr = checkbox.getFor(); 46 if (forAttr == null) 47 { 48 throw new IllegalStateException ("Mandatory attribute 'for'"); 49 } 50 51 UIComponent uiComponent = checkbox.findComponent(forAttr); 52 if (uiComponent == null) 53 { 54 throw new IllegalStateException ("Could not find component '" + forAttr 55 + "' (calling findComponent on component '" + checkbox.getClientId(context) + "')"); 56 } 57 if (!(uiComponent instanceof UISelectMany)) 58 { 59 throw new IllegalStateException ("UISelectMany expected"); 60 } 61 62 UISelectMany uiSelectMany = (UISelectMany) uiComponent; 63 64 Converter converter; 65 try 66 { 67 converter = RendererUtils.findUISelectManyConverter(context, uiSelectMany); 68 } 69 catch (FacesException e) 70 { 71 converter = null; 72 } 73 74 Set lookupSet = RendererUtils.getSelectedValuesAsSet(context, component, converter, uiSelectMany); 75 76 Object itemValue = checkbox.getItemValue(); 77 String itemStrValue = null; 78 if (converter == null) 79 { 80 if (null != itemValue) 81 { 82 itemStrValue = itemValue.toString(); 83 } 84 } 85 else 86 { 87 itemStrValue = converter.getAsString(context, uiSelectMany, itemValue); 88 } 89 90 renderCheckbox(context, uiSelectMany, itemStrValue, checkbox.getItemLabel(), lookupSet.contains(itemStrValue), 91 true); 92 } 93 94 98 protected boolean isDisabled(FacesContext facesContext, UIComponent uiComponent) 99 { 100 return super.isDisabled(facesContext, uiComponent); 101 } 102 103 107 public void decode(FacesContext facesContext, UIComponent uiComponent) 108 { 109 if (uiComponent instanceof HtmlTreeCheckbox) 110 { 111 } 113 else 114 { 115 super.decode(facesContext, uiComponent); 116 } 117 } 118 } 119 | Popular Tags |