當前位置: 首頁>>代碼示例>>Java>>正文


Java SelectItem.getValue方法代碼示例

本文整理匯總了Java中javax.faces.model.SelectItem.getValue方法的典型用法代碼示例。如果您正苦於以下問題:Java SelectItem.getValue方法的具體用法?Java SelectItem.getValue怎麽用?Java SelectItem.getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.faces.model.SelectItem的用法示例。


在下文中一共展示了SelectItem.getValue方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getItemValue

import javax.faces.model.SelectItem; //導入方法依賴的package包/類
/**
 * Return the value to output for an item.
 */
static public Object getItemValue(
  FacesContext context,
  UIComponent  component,
  SelectItem   item,
  Converter    converter,
  boolean      valuePassThru,
  int          index)
{
  if (!valuePassThru)
  {
    return IntegerUtils.getString(index);
  }
  else
  {
    Object itemValue = item.getValue();
    if ((itemValue != null) && (converter != null))
    {
      itemValue = converter.getAsString(context,
                                        component,
                                        itemValue);
    }

    return itemValue;
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:29,代碼來源:SimpleSelectOneRenderer.java

示例2: _convertIndexedSubmittedValue

import javax.faces.model.SelectItem; //導入方法依賴的package包/類
/**
 * Call this method only when the valuePassThru attribute on the selectOne
 * component is not set to true.
 * This indicates that the client-side value
 * is an index. We need to convert that index into its real value.
 * @param component
 * @param submittedValue the submittedValue. Since this method is only
 *  called when the valuePassThru attribute on the selectOne component is
 *  not true, then the submittedValue in this case is an index into a List.
 * @return the Object value at that index specified in submittedValue,
 *    or null.
 */
private Object _convertIndexedSubmittedValue(
  FacesContext context,
  UIComponent  component,
  Object       submittedValue
  ) throws ConverterException
{
  FacesBean bean = getFacesBean(component);
  Converter converter = getConverter(component, bean);
  if ( converter == null)
    converter = getDefaultConverter(context, component, bean);

  List<SelectItem> selectItems = getSelectItems(component, converter, true);

  int index = __getIndex(context, submittedValue, selectItems);
  if (index < 0)
    return null;

  SelectItem item = selectItems.get(index);
  if (item != null)
  {
    Object converted = item.getValue();
    if (converter != null && converted != null)
    {
      converted = converter.getAsObject(context, component, converted.toString());
    }
    return converted;
  }
  else
  {
    return null;
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:45,代碼來源:SimpleSelectOneRenderer.java

示例3: resolveIndex

import javax.faces.model.SelectItem; //導入方法依賴的package包/類
private int resolveIndex(
  SelectItem item,
  Object     value,
  int        index)
{
  if(item instanceof SelectItemGroup)
  {
    int result;
    for(SelectItem subItem : ((SelectItemGroup)item).getSelectItems())
    {
      result = resolveIndex( subItem, value, index++ );

      if(result >= 0)
      {
        return result;
      }
    }
  }
  else
  {
    if (value == null)
    {
      Object itemValue = item.getValue();
      // =-=AEW Treat the empty string as if it were null
      if ((itemValue == null) || "".equals(itemValue))
        return index;
    }
    else
    {
      if (value.equals(item.getValue()) || (value.getClass().isEnum() && item.getValue() != null && value.toString().equals( item.getValue().toString() )))
        return index;
    }
  }

  return -1;
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:37,代碼來源:SimpleSelectOneRenderer.java

示例4: toSubscriptionList

import javax.faces.model.SelectItem; //導入方法依賴的package包/類
List<Subscription> toSubscriptionList(List<POSubscription> poSubs) {

        ArrayList<Subscription> list = new ArrayList<>();

        for (POSubscription poSub : poSubs) {

            String subscriptionId = poSub.getId();

            Subscription sub = new Subscription();
            sub.setId(subscriptionId);
            List<POServiceRole> roles = poSub.getRoles();
            sub.setRolesRendered(!roles.isEmpty());
            List<SelectItem> items = new ArrayList<>();

            for (POServiceRole r : roles) {
                SelectItem si = new SelectItem(String.format("%s:%s",
                        Long.valueOf(r.getKey()), r.getId()), r.getName());
                if (r.getName().equalsIgnoreCase(UnitRoleType.USER.name())) {
                    items.add(0, si);
                } else {
                    items.add(si);
                }
            }

            sub.setRoles(items);

            if (model.getSelectedSubsIds().containsKey(subscriptionId)) {
                Boolean selected = model.getSelectedSubsIds().get(
                        subscriptionId);
                sub.setSelected(selected);
            } else {
                sub.setSelected(poSub.isAssigned());
            }

            String selectedRole = null;

            if (poSub.getUsageLicense() != null
                    && poSub.getUsageLicense().getPoServieRole() != null) {

                POServiceRole poServiceRole = poSub.getUsageLicense()
                        .getPoServieRole();

                long roleKey = poServiceRole.getKey();
                String roleId = poServiceRole.getId();

                selectedRole = String.format("%s:%s", Long.valueOf(roleKey),
                        roleId);

                sub.setLicKey(poSub.getUsageLicense().getKey());
                sub.setLicVersion(poSub.getUsageLicense().getVersion());
            }

            if (model.getChangedRoles().containsKey(subscriptionId)) {
                String displayedRole = model.getChangedRoles().get(
                        subscriptionId);
                for (SelectItem item : items) {
                    if (item.getLabel().equals(displayedRole)) {
                        selectedRole = (String) item.getValue();
                    }
                }
            }

            sub.setSelectedRole(selectedRole);
            list.add(sub);
        }

        return list;
    }
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:69,代碼來源:UserSubscriptionsLazyDataModel.java

示例5: selectItemsRenderContent

import javax.faces.model.SelectItem; //導入方法依賴的package包/類
protected void selectItemsRenderContent(
  UIXRenderingContext context,
  UINode           node
  ) throws IOException
{

  UIComponent component = OptionContainerRenderer.__getUIComponent(context,
                                                                   node);
  if (component != null)
  {
    List<SelectItem> selectItems =
      SelectItemSupport.getSelectItems(component,
                                       SelectItemSupport.getConverter(
                                       component));
    // if NOTHING IS SELECTED
    // we must render a blank item first, if the app developer
    // didn't already add one.
    // We use the noSelectionLabel's attribute value if it is available
    // (It might say something like "None", for example.
    // Otherwise, we just leave it blank.

    // now check if nothing is selected by default.

    boolean isNothingSelected = _isNothingSelected(component,
                                                   selectItems);

    if (selectItems != null && !selectItems.isEmpty() && isNothingSelected)
    {
      // now check if the first item is already a blank item.
      // if it isn't, render a blank item, using the
      // noSelectionLabel attribute value as the itemLabel.
      SelectItem firstItem = selectItems.get(0);
      Object firstItemValue = firstItem.getValue();
      if (!("".equals(firstItemValue)))
      {
        Object label = component.getAttributes().get(
                         CoreSelectOneChoice.UNSELECTED_LABEL_KEY);
        String noSelectionLabel = (label != null) ? label.toString() : "";

        SelectItem item = new SelectItem("", noSelectionLabel, "", false);

        renderSelectItem(context, node, component, item,
                         "", false, false, 0);
      }

    }



    renderSelectItemOptions(context,
                            node,
                            component,
                            selectItems);
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:56,代碼來源:ChoiceRenderer.java

示例6: encodeFilter

import javax.faces.model.SelectItem; //導入方法依賴的package包/類
@Override
protected void encodeFilter(FacesContext context, DataTable table, Column column) throws IOException {
	Map<String, String> params = context.getExternalContext().getRequestParameterMap();
	ResponseWriter writer = context.getResponseWriter();
	ValueExpression filterBy = column.getValueExpression("filterBy");
	String filterField = null;
	if (filterBy != null) {
		filterField = resolveStaticField(filterBy);
	}
	String filterId = column.getClientId(context) + "_filter";
	String filterValue = params.containsKey(filterId) ? params.get(filterId) : table.getFilters().get(filterField);
	String filterStyleClass = column.getFilterStyleClass();
	if (column.getValueExpression("filterOptions") == null) {
		filterStyleClass = filterStyleClass == null ? DataTable.COLUMN_INPUT_FILTER_CLASS
				: DataTable.COLUMN_INPUT_FILTER_CLASS + " " + filterStyleClass;
		writer.startElement("input", null);
		writer.writeAttribute("id", filterId, null);
		writer.writeAttribute("name", filterId, null);
		writer.writeAttribute("class", filterStyleClass, null);
		writer.writeAttribute("value", filterValue, null);
		writer.writeAttribute("autocomplete", "off", null);
		if (column.getFilterStyle() != null) {
			writer.writeAttribute("style", column.getFilterStyle(), null);
		}
		if (column.getFilterMaxLength() != Integer.MAX_VALUE) {
			writer.writeAttribute("maxlength", column.getFilterMaxLength(), null);
		}
		writer.endElement("input");
	}
	else {
		filterStyleClass = filterStyleClass == null ? DataTable.COLUMN_FILTER_CLASS : DataTable.COLUMN_FILTER_CLASS
				+ " " + filterStyleClass;
		writer.startElement("select", null);
		writer.writeAttribute("id", filterId, null);
		writer.writeAttribute("name", filterId, null);
		writer.writeAttribute("class", filterStyleClass, null);
		SelectItem[] itemsArray = getFilterOptions(column);
		for (SelectItem item : itemsArray) {
			Object itemValue = item.getValue();
			writer.startElement("option", null);
			writer.writeAttribute("value", item.getValue(), null);
			if (itemValue != null && String.valueOf(itemValue).equals(filterValue)) {
				writer.writeAttribute("selected", "selected", null);
			}
			writer.writeText(item.getLabel(), null);
			writer.endElement("option");
		}
		writer.endElement("select");
	}
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:51,代碼來源:DataTableRenderer.java


注:本文中的javax.faces.model.SelectItem.getValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。