1 23 24 package com.sun.enterprise.tools.guiframework.view.descriptors; 25 26 import com.iplanet.jato.RequestContext; 27 import com.iplanet.jato.view.ContainerView; 28 import com.iplanet.jato.view.html.SelectableGroup; 29 import com.iplanet.jato.view.html.SelectableGroupImpl; 30 import com.iplanet.jato.view.html.OptionList; 31 import com.iplanet.jato.view.html.Option; 32 import com.iplanet.jato.view.View; 33 import com.iplanet.jato.view.ViewBean; 34 import com.iplanet.jato.view.event.DisplayEvent; 35 36 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 37 38 import java.util.ArrayList ; 39 import java.util.List ; 40 41 47 public class SelectFieldDescriptor extends DisplayFieldDescriptor { 48 49 55 public SelectFieldDescriptor(String name) { 56 super(name); 57 } 58 59 60 63 public View getInstance(RequestContext ctx, ContainerView container, String name) { 64 SelectableGroupImpl choice = new SelectableGroupImpl( 65 container, name, getModelFieldName(), getInitialValue()); 66 setOptions(choice); 67 setExtraHtml(choice); 68 return choice; 69 } 70 71 protected void setOptions(SelectableGroup choice) { 72 Object options = getParameter(LABELS); 73 if (options != null) { 74 if (options instanceof String ) { 75 List tmp = new ArrayList (); 76 tmp.add(options); 77 options = tmp; 78 } 79 List optionList = (List)options; 80 int numOptions = optionList.size(); 81 82 Object values = getParameter(VALUES); 83 List valueList = optionList; 84 if (values != null) { 85 if (values instanceof String ) { 86 List tmp = new ArrayList (); 87 tmp.add(values); 88 values = tmp; 89 } 90 valueList = (List)values; 91 if (valueList.size() != numOptions) { 92 throw new FrameworkException( 93 "Unequal number of option names / values!", 94 this, choice.getParent()); 95 } 96 } 97 98 OptionList choices = 99 new OptionList( 100 (String [])optionList.toArray(new String [numOptions]), 101 (String [])valueList.toArray(new String [numOptions])); 102 choice.setOptions(choices); 103 } 104 } 105 106 107 110 public static final String LABELS = "labels"; 111 public static final String VALUES = "values"; 112 } 113 | Popular Tags |