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


Java Converter.getAsObject方法代碼示例

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


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

示例1: getConvertedValue

import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
 * Converts a string value into the component's value
 * @param context the FacesContext
 * @param component the component
 * @param newValue the unconverted string value
 */
@Override
public Object getConvertedValue(
  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);

  if (converter != null)
  {
    return converter.getAsObject(context,
                                 component,
                                 // due to the new "JSF2 empty value" parameters it can be the
                                 // case the we actually have a NULL value here.
                                 (submittedValue != null) ? submittedValue.toString() : null);
  }

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

示例2: isSelected

import javax.faces.convert.Converter; //導入方法依賴的package包/類
private boolean isSelected(FacesContext context, SelectOneMenu menu, Object value, Object itemValue,
		Converter converter) {
	if (itemValue == null && value == null) {
		return true;
	}

	if (value != null) {
		Object compareValue;
		if (converter == null) {
			compareValue = coerceToModelType(context, itemValue, value.getClass());
		} else {
			compareValue = itemValue;

			if (compareValue instanceof String && !(value instanceof String)) {
				compareValue = converter.getAsObject(context, menu, (String) compareValue);
			}
		}

		if (value.equals(compareValue)) {
			return true;
		}

	}
	return false;
}
 
開發者ID:TheCoder4eu,項目名稱:BootsFaces-OSP,代碼行數:26,代碼來源:SelectOneMenuRenderer.java

示例3: _convertIndexedSubmittedValue

import javax.faces.convert.Converter; //導入方法依賴的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

示例4: 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();
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:22,代碼來源:ConverterTestCase.java

示例5: doTestBlankValue

import javax.faces.convert.Converter; //導入方法依賴的package包/類
protected void doTestBlankValue(Converter converter)
{
  MockFacesContext context = new MockFacesContext();
  Mock mock = mock(UIComponent.class);
  UIComponent component = (UIComponent) mock.proxy();
  Object value = converter.getAsObject(context, component,"");
  assertEquals(null, value);
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:9,代碼來源:ConverterTestCase.java

示例6: doTestGetAsObject

import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
 * Test the validity of method
 * javax.faces.convert.Converter.getAsObject(FacesContext, UIComponent, String)
 *
 * @param converter converter which is to be tested
 * @param context MockFaces context
 * @param component MockFaces component
 * @throws javax.faces.convert.ConvertException
 */
protected void doTestGetAsObject(
  Converter converter,
  MockFacesContext context,
  MockUIComponentWrapper wrapper,
  String value,
  Object expectedValue
  )  throws ConverterException
{
  Object conv = converter.getAsObject(context, wrapper.getUIComponent(), value);
  assertEquals(expectedValue, conv);

  wrapper.getMock().verify();
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:23,代碼來源:ConverterTestCase.java

示例7: getConvertedValue

import javax.faces.convert.Converter; //導入方法依賴的package包/類
@Override
public Object getConvertedValue(FacesContext context, UIComponent component, Object submittedValue)
		throws ConverterException {
	Converter converter = getConverter(context, component);
	if (converter != null) {
		return converter.getAsObject(context, component, (String) submittedValue);
	} else {
		return submittedValue;
	}
}
 
開發者ID:phoenixctms,項目名稱:ctsms,代碼行數:11,代碼來源:SketchPadRenderer.java

示例8: getConvertedValue

import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
 * This method is called by the JSF framework to get the type-safe value of the
 * attribute. Do not delete this method.
 */
@Override
public Object getConvertedValue(FacesContext fc, UIComponent c, Object sval) throws ConverterException {
	Converter cnv = resolveConverter(fc, c);

	if (cnv != null) {
		if (sval == null || sval instanceof String) {
			return cnv.getAsObject(fc, c, (String) sval);
		} else {
			return cnv.getAsObject(fc, c, String.valueOf(sval));
		}
	} else {
		return sval;
	}
}
 
開發者ID:TheCoder4eu,項目名稱:BootsFaces-OSP,代碼行數:19,代碼來源:CoreRenderer.java

示例9: getConvertedValue

import javax.faces.convert.Converter; //導入方法依賴的package包/類
@Override
protected Object getConvertedValue(FacesContext fc, Object sval) throws ConverterException {
	if (sval == null) {
		return null;
	}

	String val = (String) sval;
	// If the Trimmed submitted value is empty, return null
	if (val.trim().length() == 0) {
		return null;
	}

	Converter converter = getConverter();

	// If the user supplied a converter, use it
	if (converter != null) {
		return converter.getAsObject(fc, this, val);
	}
	// Else we use our own converter
	sloc = selectLocale(fc.getViewRoot().getLocale(), A.asString(getAttributes().get(JQ.LOCALE)));
	sdf = selectDateFormat(sloc, A.asString(getAttributes().get(JQ.DTFORMAT)));

	Calendar cal = Calendar.getInstance(sloc);
	SimpleDateFormat format = new SimpleDateFormat(sdf, sloc);
	format.setTimeZone(cal.getTimeZone());

	try {
		cal.setTime(format.parse(val));
		cal.set(Calendar.HOUR_OF_DAY, 12);

		return cal.getTime();
	} catch (ParseException e) {
		this.setValid(false);
		throw new ConverterException(
				BsfUtils.getMessage("javax.faces.converter.DateTimeConverter.DATE", val, sdf, getLabel(fc)));
	}
}
 
開發者ID:TheCoder4eu,項目名稱:BootsFaces-OSP,代碼行數:38,代碼來源:Datepicker.java

示例10: getObjectFromRequestParameter

import javax.faces.convert.Converter; //導入方法依賴的package包/類
public static Object getObjectFromRequestParameter(String requestParameterName, Converter converter, UIComponent component) {
    String theId = JsfUtil.getRequestParameter(requestParameterName);
    return converter.getAsObject(FacesContext.getCurrentInstance(), component, theId);
}
 
開發者ID:javaee-samples,項目名稱:javaee8-applications,代碼行數:5,代碼來源:JsfUtil.java

示例11: _getSelectedIndex

import javax.faces.convert.Converter; //導入方法依賴的package包/類
private int _getSelectedIndex(
  FacesContext     context,
  UIComponent      component,
  FacesBean        bean,
  List<SelectItem> selectItems,
  Converter        converter,
  boolean          valuePassThru)
{
  Object submittedValue = getSubmittedValue(component, bean);
  // In passthru mode, if there's a submitted value, we just
  // have to turn it into an int and range-check it
  if ((submittedValue != null) && !valuePassThru)
  {
    return __getIndex(context, submittedValue, selectItems);
  }
  // Figure out the current value, whether it's submitted or not
  else
  {
    Object value;
    if (submittedValue == null)
    {
      value = getValue(component, bean);
    }
    else
    {
      // submittedValue: run it through the converter if there is one
      if (converter != null)
      {
        try
        {
          value = converter.getAsObject(context,
                                        component,
                                        submittedValue.toString());
        }
        // This shouldn't happen unless we got sent a bogus value;
        // log a warning and move on
        catch (ConverterException ce)
        {
          _LOG.warning(ce);
          value = null;
        }
      }
      else
        value = submittedValue;
    }

    int index = _findIndex(value, selectItems);
    if ((value != null) && (index < 0))
    {
      if (_LOG.isWarning())
        _LOG.warning("CANNOT_FIND_SELECTED_ITEM_MATCHING_VALUE", new Object[]{value, component});
    }

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

示例12: getConvertedValue

import javax.faces.convert.Converter; //導入方法依賴的package包/類
@Override
public Object getConvertedValue(
  FacesContext context,
  UIComponent  component,
  Object       submittedValue)
{
  // Convert FALSE back into null
  if (submittedValue == Boolean.FALSE)
    return null;

  UploadedFile file = (UploadedFile) submittedValue;
  if(file.getLength() == -1)
  {
    // There was a failure while one of the UploadedFileProcessor in the chain processed this file,
    // we expect the details to be in opaqueData
    String errorMessage = _getErrorMessage(context, file);
    FacesMessage fm = MessageFactory.getMessage(context, 
                                                FacesMessage.SEVERITY_WARN, 
                                                "org.apache.myfaces.trinidad.UPLOAD_FAILURE", 
                                                new Object[]{errorMessage}, component); 
    throw new ConverterException(fm);
  }

  FacesBean bean = getFacesBean(component);
  Converter converter = getConverter(component, bean);
  // support converter for the <inputFile> component
  if(converter != null)
  {
    // create a unique key (component class name + filename) and use this
    // key to add the actual uploaded file to the requestMap
    String fileNameKey = component.getClass().getName() + "." + file.getFilename();
    context.getExternalContext().getRequestMap().put(fileNameKey, file);

    // applying the above convention. The String here is just the
    // unique key which the converter has to use to look for the
    // actual uploaded file.
    return converter.getAsObject(context, component, fileNameKey);
  }
  else
  {
    return file;
  }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:44,代碼來源:SimpleInputFileRenderer.java

示例13: getConvertedValue

import javax.faces.convert.Converter; //導入方法依賴的package包/類
/**
 *
 */
protected Object getConvertedValue(
  FacesContext context,
  Object       submittedValue) throws ConverterException
{
  Renderer renderer = getRenderer(context);
  Object newValue = null;

  if (_LOG.isFine())
  {
    _LOG.fine("Converting from " + submittedValue + "(" +
              submittedValue.getClass() + ")");
  }

  if (renderer != null)
  {
    newValue = renderer.getConvertedValue(context, this,
                                          submittedValue);
    if (_LOG.isFine())
    {
      _LOG.fine("Renderer " + renderer + " returned value " + newValue + "(" +
                ((newValue != null) ? newValue.getClass().getName() : "null") + ")");
    }
  }
  else if (submittedValue instanceof String)
  {
    // If there's no Renderer, and we've got a String,
    // run it through the Converter (if any)
    Converter converter = _getConverterWithType(context);
    if (converter != null)
    {
      newValue = converter.getAsObject(context, this,
                                       (String) submittedValue);
    }
    else
    {
      newValue = submittedValue;
    }
  }
  else
  {
    newValue = submittedValue;
  }

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

示例14: getObjectFromRequestParameter

import javax.faces.convert.Converter; //導入方法依賴的package包/類
public static Object getObjectFromRequestParameter(String reqParamName, Converter converter, UIComponent component) {
    String theId = JsfUtil.getRequestParameter(reqParamName);
    return converter.getAsObject(FacesContext.getCurrentInstance(), component, theId);
}
 
開發者ID:evgeniyosipov,項目名稱:facshop,代碼行數:5,代碼來源:JsfUtil.java

示例15: getObjectFromRequestParameter

import javax.faces.convert.Converter; //導入方法依賴的package包/類
public static Object getObjectFromRequestParameter( String requestParameterName ,
                                                    Converter converter , UIComponent component ) {
    String theId = JsfUtil.getRequestParameter( requestParameterName );
    return converter.getAsObject( FacesContext.getCurrentInstance() , component , theId );
}
 
開發者ID:juliocnsouzadev,項目名稱:omg_mongodb,代碼行數:6,代碼來源:JsfUtil.java


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