This content has been marked as final.
Show 2 replies
-
1. Re: rich:combobox key value pair issue?
kidrock_hj Sep 24, 2009 12:06 AM (in response to kidrock_hj)Sorry my code is not complete.
SelectItem item = new SelectItem(); item.setValue(itemKey); item.setDescription(itemValue) <rich:comboBox width="100px" value="# {retrieveQuotesBusinessContract.quoteType}"> <f:selectItems value="#{dropdownListDelegator.quoteType}"/> </rich:comboBox>
-
2. Re: rich:combobox key value pair issue?
kidrock_hj Sep 24, 2009 1:59 AM (in response to kidrock_hj)I soloved this issue by using converter.
Build the SelectItemSelectItem item = new SelectItem(); item.setLabel(itemValue); item.setValue(itemKey);
Converterpackage com.avnet.quest.ui.converter; import java.util.List; import javax.faces.context.FacesContext; import javax.faces.component.UIComponent; import javax.faces.component.UISelectItems; import javax.faces.model.SelectItem; import org.jboss.seam.annotations.Name; import org.jboss.seam.annotations.intercept.BypassInterceptors; import org.jboss.seam.annotations.faces.Converter; import org.jboss.seam.contexts.Contexts; import com.avnet.quest.ui.dropdown.DropdownListDelegator; @Name("comboxLabelConverter") @Converter @BypassInterceptors public class ComboxLabelConverter implements javax.faces.convert.Converter{ public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String s) { List<SelectItem> items = retrieveSelectItems(uiComponent); if(items!=null){ for(SelectItem item:items){ if(item.getLabel().equals(s)) return item.getValue(); } } return s; } public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object value) { List<SelectItem> items = retrieveSelectItems(uiComponent); if(items!=null){ for(SelectItem item:items){ if(item.getValue().equals(value)) return item.getLabel(); } } return value == null? null:"canot convert label for :"+value; } private List<SelectItem> retrieveSelectItems(UIComponent uiComponent) { List<SelectItem> items = null; if(uiComponent.getChildren()!=null&&!uiComponent.getChildren().isEmpty() &&uiComponent.getChildren().get(0) instanceof UISelectItems){ items = (List<SelectItem>)((UISelectItems)uiComponent.getChildren().get(0)).getValue(); } return items; } }