1 16 package org.apache.myfaces.wap.renderkit; 17 18 import java.util.Collection ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import javax.faces.component.UIComponent; 23 import javax.faces.context.ResponseWriter; 24 import javax.faces.model.SelectItem; 25 import javax.faces.model.SelectItemGroup; 26 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 30 38 public class WmlRenderUtils { 39 private static Log log = LogFactory.getLog(RendererUtils.class); 40 41 44 public static void writeOptions(Object items, UIComponent component, ResponseWriter writer) throws java.io.IOException { 45 log.debug("method writeOptions"); 46 47 if (items instanceof SelectItemGroup){ 48 log.debug("item is an instanceof SelectItemGroup"); 49 SelectItemGroup group = (SelectItemGroup)items; 50 51 writer.startElement(Attributes.OPTGROUP,component); 52 RendererUtils.writeAttribute(Attributes.TITLE, group.getLabel(), writer); 53 54 SelectItem[] array = group.getSelectItems(); 55 for (int i = 0; i < array.length; i++) 56 writeOption(array[i],component, writer); 57 58 writer.endElement(Attributes.OPTGROUP); 59 } 60 else { 61 if (items instanceof SelectItem){ 62 log.debug("item is an instance of SelectItem"); 63 writeOption((SelectItem)items,component, writer); 64 } 65 66 if (items instanceof SelectItem[]){ 67 log.debug("item is an instance of SelectItem[]"); 68 SelectItem[] array = (SelectItem[])items; 69 for (int i = 0; i < array.length; i++) 70 writeOption(array[i],component, writer); 71 } 72 73 if (items instanceof Collection ){ 74 log.debug("item is an instance of Collection"); 75 Iterator iter = ((Collection )items).iterator(); 76 while(iter.hasNext()) 77 writeOptions(iter.next(),component, writer); 78 } 79 80 if (items instanceof Map ){ 81 log.debug("item is an instance of Map"); 82 Iterator iter = ((Map )items).entrySet().iterator(); 83 while(iter.hasNext()) 84 writeOption((SelectItem)iter.next(),component, writer); 85 } 86 } 87 } 88 89 90 public static void writeOption(SelectItem item, UIComponent component, ResponseWriter writer) throws java.io.IOException { 91 writer.startElement(Attributes.OPTION,component); 92 RendererUtils.writeAttribute(Attributes.VALUE, item.getValue(), writer); 93 writer.write(item.getLabel()); 94 writer.endElement(Attributes.OPTION); 95 } 96 } 97 | Popular Tags |