本文整理匯總了Java中javax.faces.convert.Converter.getAsString方法的典型用法代碼示例。如果您正苦於以下問題:Java Converter.getAsString方法的具體用法?Java Converter.getAsString怎麽用?Java Converter.getAsString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.faces.convert.Converter
的用法示例。
在下文中一共展示了Converter.getAsString方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getConvertedString
import javax.faces.convert.Converter; //導入方法依賴的package包/類
protected String getConvertedString(
FacesContext context,
UIComponent component,
FacesBean bean)
{
Object value = getValue(component, bean);
Converter converter = getConverter(component, bean);
// If there's no explicitly set converter, and the value is non-null
// and not a String, try to get a default converter
if ((converter == null) &&
(value != null) &&
!(value instanceof String))
converter = getDefaultConverter(context, component, bean);
if (converter != null)
{
return converter.getAsString(context, component, value);
}
return toString(value);
}
示例2: getItemValue
import javax.faces.convert.Converter; //導入方法依賴的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;
}
}
示例3: getConvertedValue
import javax.faces.convert.Converter; //導入方法依賴的package包/類
protected Object getConvertedValue(
FacesContext context,
CoreOutputText cot)
{
Object value = cot.getValue();
if (value == null)
return null;
Converter converter = cot.getConverter();
if ((converter == null) && !(value instanceof String))
{
converter = getConverterByType(context, cot);
}
if (converter != null)
{
return converter.getAsString(context, cot, value);
}
return value;
}
示例4: getConvertedValue
import javax.faces.convert.Converter; //導入方法依賴的package包/類
protected Object getConvertedValue(
FacesContext context,
UIComponent component,
FacesBean bean)
{
Object value = getValue(component, bean);
if (value == null)
return null;
Converter converter = getConverter(component, bean);
if ((converter == null) && !(value instanceof String))
{
converter = getConverterByType(context, bean);
}
if (converter != null)
{
return converter.getAsString(context, component, value);
}
return value;
}
示例5: getReadonlyDisplayValue
import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
* Should return value string for the readonly view mode. Can be overridden
* for custom components.
*/
private String getReadonlyDisplayValue(final Object value, final UIInput component, final Converter converter) {
if (value == null || "".equals(value)) {
return "-";
} else if (converter != null) {
final String asString = converter.getAsString(FacesContext.getCurrentInstance(), component, value);
return asString == null ? "-" : asString;
}
if (component instanceof HtmlCheckBox) {
HtmlCheckBox checkBoxComponent = (HtmlCheckBox) component;
final StringBuilder sb = new StringBuilder();
if (StringUtils.isNotEmpty(checkBoxComponent.getDescription())) {
sb.append(checkBoxComponent.getDescription()).append(": ");
}
sb.append((Boolean) value ? "ja" : "nein");
return sb.toString();
}
return String.valueOf(value);
}
示例6: getValue2Render
import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
* Algorithm works as follows; - If it's an input component, submitted value
* is checked first since it'd be the value to be used in case validation
* errors terminates jsf lifecycle - Finally the value of the component is
* retrieved from backing bean and if there's a converter, converted value
* is returned
*
* @param context
* FacesContext instance
* @return End text
*/
public Object getValue2Render(FacesContext context, SelectMultiMenu menu) {
Object sv = menu.getSubmittedValue();
if (sv != null) {
return sv;
}
Object val = menu.getValue();
if (val != null) {
Converter converter = menu.getConverter();
if (converter != null)
return converter.getAsString(context, menu, val);
else
return val;
} else {
// component is a value holder but has no value
return null;
}
}
示例7: getOptionAsString
import javax.faces.convert.Converter; //導入方法依賴的package包/類
private String getOptionAsString(FacesContext context, SelectOneMenu menu, Object value, Converter converter)
throws ConverterException {
if (converter == null) {
if (value == null) {
return "";
} else if (value instanceof String) {
return (String) value;
} else {
Converter implicitConverter = findImplicitConverter(context, menu);
return implicitConverter == null ? value.toString()
: implicitConverter.getAsString(context, menu, value);
}
} else {
return converter.getAsString(context, menu, value);
}
}
示例8: queueReturnEvent
import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
* Give subclasses a chance to override the ReturnEvent.
*/
@Override
protected void queueReturnEvent(
FacesContext context,
UIComponent component,
ReturnEvent event)
{
Object returnValue = event.getReturnValue();
// If we got passed a Color object, send it back to String
// land (where it needs to be for submitted values).
if (returnValue instanceof Color)
{
FacesBean bean = getFacesBean(component);
Converter converter = getConverter(component, bean);
if (converter == null)
converter = getDefaultConverter(context, component, bean);
if (converter != null)
{
returnValue = converter.getAsString(context,
component,
returnValue);
}
else
{
returnValue = returnValue.toString();
}
event = new ReturnEvent(component,
returnValue,
event.getReturnParameters());
}
event.queue();
}
示例9: queueReturnEvent
import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
* Give subclasses a chance to override the ReturnEvent.
*/
@Override
protected void queueReturnEvent(
FacesContext context,
UIComponent component,
ReturnEvent event)
{
Object returnValue = event.getReturnValue();
GenericConverterFactory fac = GenericConverterFactory.getCurrentInstance();
// If we got passed a Date object, send it back to String
// land (where it needs to be for submitted values).
if ((returnValue instanceof Date) || fac.isConvertible(returnValue, Date.class))
{
FacesBean bean = getFacesBean(component);
Converter converter = getConverter(component, bean);
if (converter == null)
converter = getDefaultConverter(context, component, bean);
if (converter != null)
{
returnValue = converter.getAsString(context,
component,
returnValue);
}
else
{
returnValue = returnValue.toString();
}
event = new ReturnEvent(component,
returnValue,
event.getReturnParameters());
}
event.queue();
}
示例10: _getConvertedValue
import javax.faces.convert.Converter; //導入方法依賴的package包/類
private Object _getConvertedValue(
FacesContext context,
UIComponent component,
Converter converter,
Object value)
{
return converter.getAsString(context, component, value);
}
示例11: doTestNull
import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
* This test performs action on the method
* javax.faces.convert.Converter.getAsObject(FacesContext, UIComponent, String)
* and
* javax.faces.convert.Converter.getAsString(FacesContext, UIComponent, Object)
* for method getAsObject() should return a value of null while getAsString()
* should return a empty string.
* @throws ValidatorException when test fails
*/
protected void doTestNull(
MockFacesContext context,
MockUIComponentWrapper wrapper,
Converter converter
) throws ConverterException
{
Object obj = converter.getAsObject(context, wrapper.getUIComponent(), null);
assertEquals(null, obj);
String str = converter.getAsString(context, wrapper.getUIComponent(), null);
assertEquals("",str);
wrapper.getMock().verify();
}
示例12: doTestGetAsString
import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
* Test the validity of call on the method
* javax.faces.convert.Converter.getAsString(FacesContext, UIComponent, Object)
* @param converter converter which is to be tested
* @param context MockFaces context
* @param component MockFaces component
* @throws javax.faces.convert.ConvertException
*/
protected void doTestGetAsString(
Converter converter,
MockFacesContext context,
MockUIComponentWrapper wrapper,
Object value,
String expectedValue
) throws ConverterException
{
Object conv = converter.getAsString(context, wrapper.getUIComponent(), value);
assertEquals(conv, expectedValue);
wrapper.getMock().verify();
}
示例13: getValue
import javax.faces.convert.Converter; //導入方法依賴的package包/類
private Object getValue(FacesContext context, SketchPad sketchPad) {
Object submittedValue = sketchPad.getSubmittedValue();
if (submittedValue != null) {
return submittedValue;
}
Object value = sketchPad.getValue();
Converter converter = getConverter(context, sketchPad);
if (converter != null) {
return converter.getAsString(context, sketchPad, value);
} else if (value != null) {
return value.toString();
} else {
return "";
}
}
示例14: getCurrentValue
import javax.faces.convert.Converter; //導入方法依賴的package包/類
protected String getCurrentValue(FacesContext context, final UIComponent component) {
if (component instanceof UIInput) {
Object submittedValue = ((UIInput) component).getSubmittedValue();
if (submittedValue != null) {
// value may not be a String...
return submittedValue.toString();
}
}
if (component instanceof ValueHolder) {
final ValueHolder valueHolder = (ValueHolder) component;
final Object value = valueHolder.getValue();
final Converter converter = valueHolder.getConverter();
if (converter != null && value != null) {
return converter.getAsString(context, component, value);
}
if (value != null) {
return value.toString();
}
}
return null;
}
示例15: getDateAsString
import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
* Get date in string format
* @param fc The FacesContext
* @param dtp the DateTimePicker component
* @param value The date to display
* @param javaFormatString The format string as defined by the SimpleDateFormat syntax
* @param locale The locale
* @return null if the value is null.
*/
public static String getDateAsString(FacesContext fc, DateTimePicker dtp, Object value, String javaFormatString, Locale locale) {
if (value == null) {
return null;
}
Converter converter = dtp.getConverter();
return converter == null ?
getInternalDateAsString(value, javaFormatString, locale)
:
converter.getAsString(fc, dtp, value);
}