1 16 package org.apache.cocoon.faces.taglib; 17 18 import org.apache.cocoon.faces.FacesUtils; 19 import org.apache.commons.lang.BooleanUtils; 20 21 import javax.faces.FacesException; 22 import javax.faces.component.UIComponent; 23 import javax.faces.component.UISelectItem; 24 25 28 public class SelectItemTag extends UIComponentTag { 29 30 protected String value; 31 protected String itemValue; 32 protected String itemLabel; 33 protected String itemDescription; 34 protected String itemDisabled; 35 36 public void setValue(String value) { 37 this.value = value; 38 } 39 40 public void setItemValue(String itemValue) { 41 this.itemValue = itemValue; 42 } 43 44 public void setItemLabel(String itemLabel) { 45 this.itemLabel = itemLabel; 46 } 47 48 public void setItemDescription(String itemDescription) { 49 this.itemDescription = itemDescription; 50 } 51 52 public void setItemDisabled(String itemDisabled) { 53 this.itemDisabled = itemDisabled; 54 } 55 56 protected String getComponentType() { 57 return "javax.faces.SelectItem"; 58 } 59 60 protected String getRendererType() { 61 return null; 62 } 63 64 protected void setProperties(UIComponent component) { 65 super.setProperties(component); 66 67 UISelectItem selectItem; 68 try { 69 selectItem = (UISelectItem) component; 70 } catch (ClassCastException cce) { 71 throw new FacesException("Tag <" + getClass().getName() + "> expected UISelectItem. " + 72 "Got <" + component.getClass().getName() + ">"); 73 } 74 75 if (value != null) { 76 if (FacesUtils.isExpression(value)) { 77 selectItem.setValueBinding("value", createValueBinding(value)); 78 } else { 79 selectItem.setValue(value); 80 } 81 } 82 83 if (itemValue != null) { 84 if (FacesUtils.isExpression(itemValue)) { 85 selectItem.setValueBinding("itemValue", createValueBinding(itemValue)); 86 } else { 87 selectItem.setItemValue(itemValue); 88 } 89 } 90 91 if (itemLabel != null) { 92 if (FacesUtils.isExpression(itemLabel)) { 93 selectItem.setValueBinding("itemLabel", createValueBinding(itemLabel)); 94 } else { 95 selectItem.setItemLabel(itemLabel); 96 } 97 } 98 99 if (itemDescription != null) { 100 if (FacesUtils.isExpression(itemDescription)) { 101 selectItem.setValueBinding("itemDescription", createValueBinding(itemDescription)); 102 } else { 103 selectItem.setItemDescription(itemDescription); 104 } 105 } 106 107 if (itemDisabled != null) { 108 if (FacesUtils.isExpression(itemDisabled)) { 109 selectItem.setValueBinding("itemDisabled", createValueBinding(itemDisabled)); 110 } else { 111 selectItem.setItemDisabled(BooleanUtils.toBoolean(itemDisabled)); 112 } 113 } 114 } 115 116 public void recycle() { 117 super.recycle(); 118 this.value = null; 119 this.itemValue = null; 120 this.itemLabel = null; 121 this.itemDescription = null; 122 this.itemDisabled = null; 123 } 124 } 125 | Popular Tags |