javax.faces.convert.Converter.getAsString()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(217)

本文整理了Java中javax.faces.convert.Converter.getAsString()方法的一些代码示例,展示了Converter.getAsString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Converter.getAsString()方法的具体详情如下:
包路径:javax.faces.convert.Converter
类名称:Converter
方法名:getAsString

Converter.getAsString介绍

[英]Convert the specified model object value, which is associated with the specified UIComponent, into a String that is suitable for being included in the response generated during the Render Response phase of the request processing lifeycle.
[中]将与指定UIComponent关联的指定模型对象值转换为适合包含在请求处理生命周期的呈现响应阶段生成的响应中的字符串。

代码示例

代码示例来源:origin: primefaces/primefaces

protected String getOptionAsString(FacesContext context, UIComponent component, Converter converter, Object value) throws ConverterException {
  if (!(component instanceof ValueHolder)) {
    return value == null ? null : value.toString();
  }
  if (converter == null) {
    if (value == null) {
      return "";
    }
    else if (value instanceof String) {
      return (String) value;
    }
    else {
      Converter implicitConverter = findImplicitConverter(context, component);
      return implicitConverter == null ? value.toString() : implicitConverter.getAsString(context, component, value);
    }
  }
  else {
    return converter.getAsString(context, component, value);
  }
}

代码示例来源:origin: primefaces/primefaces

for (int i = 0; i < collectionSize; i++) {
  Object object = collection.get(i);
  builder.append(converter.getAsString(context, component, object));
return converter.getAsString(context, component, value);

代码示例来源:origin: primefaces/primefaces

public static final String getValue(FacesContext context, UICalendar calendar, Object value, String pattern) {
  //first ask the converter
  if (calendar.getConverter() != null) {
    return calendar.getConverter().getAsString(context, calendar, value);
  }
  else if (value instanceof String) {
    return (String) value;
  }
  //Use built-in converter
  else if (value instanceof Date) {
    SimpleDateFormat format = new SimpleDateFormat(pattern, calendar.calculateLocale(context));
    format.setTimeZone(calculateTimeZone(calendar.getTimeZone()));
    return format.format((Date) value);
  }
  else {
    //Delegate to global defined converter (e.g. joda or java8)
    ValueExpression ve = calendar.getValueExpression("value");
    if (ve != null) {
      Class type = ve.getType(context.getELContext());
      if (type != null && type != Object.class && type != Date.class) {
        Converter converter = context.getApplication().createConverter(type);
        if (converter != null) {
          return converter.getAsString(context, calendar, value);
        }
      }
    }
    throw new FacesException("Value could be either String or java.util.Date");
  }
}

代码示例来源:origin: primefaces/primefaces

@Override
public void encodeEnd(FacesContext context, UIComponent component) throws IOException {
  ColorPicker colorPicker = (ColorPicker) component;
  Converter converter = colorPicker.getConverter();
  String value;
  if (converter != null) {
    value = converter.getAsString(context, component, colorPicker.getValue());
  }
  else {
    value = (String) colorPicker.getValue();
  }
  encodeMarkup(context, colorPicker, value);
  encodeScript(context, colorPicker, value);
}

代码示例来源:origin: primefaces/primefaces

return converter.getAsString(context, component, value);

代码示例来源:origin: primefaces/primefaces

protected void encodeListItems(FacesContext context, MultiSelectListbox listbox, SelectItem[] selectItems) throws IOException {
  if (selectItems != null && selectItems.length > 0) {
    ResponseWriter writer = context.getResponseWriter();
    Converter converter = ComponentUtils.getConverter(context, listbox);
    String itemValue = null;
    for (int i = 0; i < selectItems.length; i++) {
      SelectItem selectItem = selectItems[i];
      itemValue = converter != null ? converter.getAsString(context, listbox, selectItem.getValue()) : String.valueOf(selectItem.getValue());
      writer.startElement("li", null);
      writer.writeAttribute("class", MultiSelectListbox.ITEM_CLASS, null);
      writer.writeAttribute("data-value", itemValue, null);
      writer.startElement("span", listbox);
      writer.writeText(selectItem.getLabel(), null);
      writer.endElement("span");
      if (selectItem instanceof SelectItemGroup) {
        SelectItemGroup group = (SelectItemGroup) selectItem;
        SelectItem[] groupItems = group.getSelectItems();
        if (groupItems != null && groupItems.length > 0) {
          encodeGroupItems(context, listbox, group.getSelectItems());
        }
      }
      writer.endElement("li");
    }
  }
}

代码示例来源:origin: primefaces/primefaces

String value = converter != null ? converter.getAsString(context, old, old.getItemValue()) : old.getItemValue().toString();

代码示例来源:origin: primefaces/primefaces

String value = converter == null ? String.valueOf(ac.getItemValue()) : converter.getAsString(context, ac, ac.getItemValue());
writer.writeAttribute("data-item-value", value, null);
writer.writeAttribute("data-item-label", ac.getItemLabel(), null);

代码示例来源:origin: primefaces/primefaces

context.getExternalContext().getRequestMap().put(var, item);
String itemValue = converter != null ?
          converter.getAsString(context, pickList, pickList.getItemValue()) : pickList.getItemValue().toString();
String itemLabel = pickList.getItemLabel();
String itemClass = pickList.isItemDisabled() ? PickList.ITEM_CLASS + " " + PickList.ITEM_DISABLED_CLASS : PickList.ITEM_CLASS;

代码示例来源:origin: primefaces/primefaces

Object value = it.next();
String tokenValue = converter != null ? converter.getAsString(context, chips, value) : String.valueOf(value);

代码示例来源:origin: primefaces/primefaces

String tokenValue = converter != null ? converter.getAsString(context, ac, itemValue) : String.valueOf(itemValue);
String itemStyleClass = AutoComplete.TOKEN_DISPLAY_CLASS;
if (ac.getItemStyleClass() != null) {

代码示例来源:origin: primefaces/primefaces

String value = converter == null ? String.valueOf(ac.getItemValue()) : converter.getAsString(context, ac, ac.getItemValue());
writer.writeAttribute("data-item-value", value, null);
writer.writeAttribute("data-item-label", ac.getItemLabel(), null);

代码示例来源:origin: javax/javaee-web-api

private static String stringValue(UIComponent component,
                 Long toConvert,
                 FacesContext context) {
  Converter converter =
     context.getApplication().createConverter("javax.faces.Number");
  return converter.getAsString(context, component, toConvert);
}

代码示例来源:origin: javax.faces/javax.faces-api

private static String stringValue(UIComponent component,
                 Double toConvert,
                 FacesContext context) {
  Converter converter = context.getApplication().createConverter("javax.faces.Number");
  return converter.getAsString(context, component, toConvert);
}

代码示例来源:origin: javax.faces/javax.faces-api

private static String stringValue(UIComponent component,
                 Long toConvert,
                 FacesContext context) {
  Converter converter =
     context.getApplication().createConverter("javax.faces.Number");
  return converter.getAsString(context, component, toConvert);
}

代码示例来源:origin: javax/javaee-web-api

private static String integerToString(UIComponent component,
                   Integer toConvert,
                   FacesContext context) {
  Converter converter =
     context.getApplication().createConverter("javax.faces.Number");
  return converter.getAsString(context, component, toConvert);
}

代码示例来源:origin: com.sun.faces/jsf-api

private static String stringValue(UIComponent component,
                 Long toConvert,
                 FacesContext context) {
  Converter converter =
     context.getApplication().createConverter("javax.faces.Number");
  return converter.getAsString(context, component, toConvert);
}

代码示例来源:origin: javax/javaee-web-api

private static String stringValue(UIComponent component,
                 Double toConvert,
                 FacesContext context) {
  Converter converter = context.getApplication().createConverter("javax.faces.Number");
  return converter.getAsString(context, component, toConvert);
}

代码示例来源:origin: org.richfaces/richfaces

public String getConvertedValue(FacesContext facesContext, AbstractPlaceholder placeholder) {
    final Object value = placeholder.getValue();

    Converter converter = InputUtils.findConverter(facesContext, placeholder, "value");

    if (converter != null) {
      return converter.getAsString(facesContext, placeholder, value);
    } else {
      return value != null ? value.toString() : "";
    }
  }
}

代码示例来源:origin: com.sun.faces/jsf-impl

public String getAsString(FacesContext context, UIComponent component, Object value) {
  Converter delegate = getDelegate(context);
  if (delegate != null) {
    return delegate.getAsString(context, component, value);
  } else {
    throw new ConverterException(
       MessageUtils.getExceptionMessage(
         MessageUtils.CANNOT_CONVERT_ID,
         converterId != null ? converterId.getExpressionString() : "",
         binding != null ? binding.getExpressionString() : "")); 
  }
}

相关文章