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.BasicChoiceDisplayField; 29 import com.iplanet.jato.view.Choice; 30 import com.iplanet.jato.view.SimpleChoice; 31 import com.iplanet.jato.view.View; 32 import com.iplanet.jato.view.ViewBean; 33 import com.iplanet.jato.view.event.DisplayEvent; 34 35 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 36 37 import java.util.ArrayList ; 38 import java.util.List ; 39 40 43 public class ChoiceFieldDescriptor extends DisplayFieldDescriptor { 44 45 51 public ChoiceFieldDescriptor(String name) { 52 super(name); 53 } 54 55 56 59 public View getInstance(RequestContext ctx, ContainerView container, String name) { 60 BasicChoiceDisplayField choice = 61 new BasicChoiceDisplayField(container, name); 62 setModelFieldBinding(choice, getModelFieldName()); 63 Object options = getParameter(LABELS); 64 if (options != null) { 65 if (options instanceof String ) { 66 List tmp = new ArrayList (); 67 tmp.add(options); 68 options = tmp; 69 } 70 List optionList = (List )options; 71 72 Object values = getParameter(VALUES); 73 List valueList = optionList; 74 if (values != null) { 75 if (values instanceof String ) { 76 List tmp = new ArrayList (); 77 tmp.add(values); 78 values = tmp; 79 } 80 valueList = (List )values; 81 if (valueList.size() != optionList.size()) { 82 throw new FrameworkException( 83 "Unequal number of option names / values!", 84 this, container); 85 } 86 } 87 88 Choice choices[] = new Choice[valueList.size()]; 89 for (int count=0; count<valueList.size(); count++) { 90 choices[count] = new SimpleChoice( 92 optionList.get(count), valueList.get(count)); 93 } 94 choice.setChoices(choices); 95 } 96 return choice; 97 } 98 99 100 103 public static final String LABELS = "labels"; 104 public static final String VALUES = "values"; 105 } 106 | Popular Tags |