当前位置: 首页>>代码示例>>Java>>正文


Java ConverterException类代码示例

本文整理汇总了Java中javax.faces.convert.ConverterException的典型用法代码示例。如果您正苦于以下问题:Java ConverterException类的具体用法?Java ConverterException怎么用?Java ConverterException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ConverterException类属于javax.faces.convert包,在下文中一共展示了ConverterException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getAsObject

import javax.faces.convert.ConverterException; //导入依赖的package包/类
/**
 * Conversion to server representation, so converting days to milliseconds.
 * Prior to the conversion the input value is validated.
 */
@Override
public Object getAsObject(FacesContext context, UIComponent component,
        String value) {
    try {
        // Checks if mandatory and not empty
        new ParameterValueValidator().validate(context, component, value);
    } catch (ValidatorException e) {
        throw new ConverterException(e.getFacesMessage());
    }

    // Validation passed; so if the value is empty it's not mandatory
    if (value == null || value.trim().length() == 0) {
        return null;
    } else {
        Long durationInMs = DurationValidation.convertDurationToMs(context,
                value);
        if (durationInMs != null) {
            return durationInMs.toString();
        } else {
            throw new ConverterException(
                    ParameterValueValidator.getFacesMessage(component,
                            context));
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:30,代码来源:DurationConverter.java

示例2: getAsString

import javax.faces.convert.ConverterException; //导入依赖的package包/类
/**
 * Conversion to portal representation as String.
 */
@Override
public String getAsString(FacesContext context, UIComponent component,
        Object object) {
    if (object == null) {
        return null;
    }
    String value = object.toString();
    if (value.trim().length() == 0) {
        return null;
    }
    long durationInMs;
    try {
        durationInMs = Long.parseLong(value);
    } catch (NumberFormatException e) {
        throw new ConverterException(
                ParameterValueValidator.getFacesMessage(component, context));
    }
    long days = durationInMs / DurationValidation.MILLISECONDS_PER_DAY;
    return String.valueOf(days);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:DurationConverter.java

示例3: getAsObject

import javax.faces.convert.ConverterException; //导入依赖的package包/类
/**
 * Conversion to server representation, so converting currency to internal
 * integer with cents format. Prior to the conversion the input value is
 * validated.
 * 
 * @param context
 *            JSF context.
 * @param component
 *            Component which value will be processed.
 * @param value
 *            Value.
 */
public Object getAsObject(FacesContext context, UIComponent component,
        String value) {
    final PriceConverter converter = getConverter(context);

    try {
        return converter.parse(value);
    } catch (ParseException e) {
        String msg = e.getMessage();
        if (msg != null
                && msg.equals("ERROR_PRICEMODEL_INVALID_FRACTIONAL_PART")) {
            throw new ConverterException(JSFUtils.getFacesMessage(
                    component, context,
                    BaseBean.ERROR_PRICEMODEL_INVALID_FRACTIONAL_PART));
        }
        throw new ConverterException(JSFUtils.getFacesMessage(component,
                context, BaseBean.ERROR_PRICEMODEL_INPUT));
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:31,代码来源:CurrencyConverter.java

示例4: getAsObject

import javax.faces.convert.ConverterException; //导入依赖的package包/类
@Override
public Object getAsObject(
  FacesContext context, 
  UIComponent component,
  String value) 
{
  try
  {
    return super.getAsObject(context, component, value);
  }
  catch(ConverterException ce)
  {
   
    throw ConverterUtils.getIntegerConverterException(context, 
                                                      component, 
                                                      ce,
                                                      value,
                                                      CONVERT_MESSAGE_ID,
                                                      MAXIMUM_MESSAGE_ID,
                                                      _SHORT_MAX,
                                                      MINIMUM_MESSAGE_ID,
                                                      _SHORT_MIN);
  }     
  
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:26,代码来源:ShortConverter.java

示例5: _addConversionErrorMessage

import javax.faces.convert.ConverterException; //导入依赖的package包/类
private void _addConversionErrorMessage(
   FacesContext       context,
   ConverterException ce,
   Object             value)
{
  FacesMessage message = ce.getFacesMessage();

  if (message == null)
  {
    Object label = _getLabel();
    message = MessageFactory.getMessage(context,
                                        CONVERSION_MESSAGE_ID,
                                        new Object[]{label, value,
                                                     ce.getMessage()},
                                        label);
  }
  else
  {
    message = _wrapMessage(message);
  }

  context.addMessage(getClientId(context), message);
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:24,代码来源:UIXEditableValueTemplate.java

示例6: getAsObject

import javax.faces.convert.ConverterException; //导入依赖的package包/类
@Override
public Object getAsObject(
  FacesContext context,
  UIComponent component,
  String value)
  throws ConverterException
{
  Object number = super.getAsObject(context, component, value);
  if (number == null) // bug 4137626
    return null;

  // this is causing issue TRINIDAD-690    
  number = 
    DateTimeConverter.__typeConvert(context, this, component, value, number);
  return number;
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:17,代码来源:NumberConverter.java

示例7: getAsObject

import javax.faces.convert.ConverterException; //导入依赖的package包/类
@Override
public Object getAsObject(
  FacesContext context, 
  UIComponent component,
  String value) 
{
  try
  {
    return super.getAsObject(context, component, value);
  }
  catch(ConverterException ce)
  {

    throw ConverterUtils.getIntegerConverterException(context, 
                                                      component, 
                                                      ce,
                                                      value,
                                                      CONVERT_MESSAGE_ID,
                                                      MAXIMUM_MESSAGE_ID,
                                                      _BYTE_MAX,
                                                      MINIMUM_MESSAGE_ID,
                                                      _BYTE_MIN);
  }     
  
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:26,代码来源:ByteConverter.java

示例8: testGetAsObjectWithComma

import javax.faces.convert.ConverterException; //导入依赖的package包/类
/**
 * Test for getting value with unescaped comma.
 * 
 * @throws ParseException
 */
@Test
public void testGetAsObjectWithComma() throws ConverterException, ParseException {
    UIComponent component = getComponent();
    POService actual = (POService) converter.getAsObject(context,
            component, poServiceAsStringWithComma);
    
    Assert.assertEquals(actual.getKey(), 10001);
    Assert.assertEquals(actual.getPictureUrl(),
            "/image?type=SERVICE_IMAGE&serviceKey=10001");
    Assert.assertEquals(actual.getProviderName(), "Fujitsu, INC.");
    Assert.assertEquals(actual.getServiceName(),
            "Hello Kitty November 6.66 1234:");
    Assert.assertEquals(actual.getStatusSymbol(), "status_NOT_ACTIVE");
    Assert.assertEquals(actual.getVersion(), 5);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:21,代码来源:POServiceConverterTest.java

示例9: doTestStrictNess

import javax.faces.convert.ConverterException; //导入依赖的package包/类
@Override
protected void doTestStrictNess(
  MockFacesContext context,
  MockUIComponentWrapper wrapper,
  Locale locale,
  String inputValue)
{
   NumberConverter converter = getNumberConverter();
   converter.setLocale(locale);
   context.getViewRoot().setLocale(locale);
   try
   {
     // ADF Converter is not lenient.
     converter.getAsObject(context, wrapper.getUIComponent(), inputValue);
     fail("Expected converter exception");
   }
   catch (ConverterException ce)
   {
     ; // We expected a exception to occur
   }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:22,代码来源:TrinidadNumberConverterTest.java

示例10: testCreatePricedParameterRowListCreateMissing

import javax.faces.convert.ConverterException; //导入依赖的package包/类
@Test
public void testCreatePricedParameterRowListCreateMissing()
        throws ConverterException {
    product.getPriceModel().setSelectedParameters(null);

    int size = parameterList.size()
            + parameterWithOption.getParameterDefinition()
                    .getParameterOptions().size();
    size--; // one parameter is of type string, must not be listed

    List<PricedParameterRow> selectedParameters;

    selectedParameters = PricedParameterRow.createPricedParameterRowList(
            product, false, true, false, true, true);
    Assert.assertEquals(size, selectedParameters.size());
    for (PricedParameterRow row : selectedParameters) {
        Assert.assertNotNull(row.getPricedParameter());
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:PricedParameterRowTest.java

示例11: testCreatePricedParameterRowList_NotIncludeConfigurableOneTimeParams

import javax.faces.convert.ConverterException; //导入依赖的package包/类
@Test
public void testCreatePricedParameterRowList_NotIncludeConfigurableOneTimeParams()
        throws ConverterException {

    // Given product with two one time parameter, 1 configurable, 1 not
    // configurable
    VOService product = givenProductWithParams();
    List<PricedParameterRow> selectedParameters;

    // when
    selectedParameters = PricedParameterRow.createPricedParameterRowList(
            product, true, true, true, true, false);

    // then
    Assert.assertEquals(1, selectedParameters.size());
    assertTrue(selectedParameters.get(0).isOneTimeParameter());

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:19,代码来源:PricedParameterRowTest.java

示例12: createPricedParameterRowListForSubscription

import javax.faces.convert.ConverterException; //导入依赖的package包/类
@Test
public void createPricedParameterRowListForSubscription()
        throws ConverterException {

    // Given product with two one time parameter, 1 configurable, 1 not
    // configurable
    VOService product = givenProductWithParams();
    List<PricedParameterRow> selectedParameters;

    // when
    selectedParameters = PricedParameterRow
            .createPricedParameterRowListForSubscription(product);

    // then
    Assert.assertEquals(1, selectedParameters.size());
    assertTrue(selectedParameters.get(0).isOneTimeParameter());
    Assert.assertNull(selectedParameters.get(0).getParameter().getValue());

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:20,代码来源:PricedParameterRowTest.java

示例13: createPricedParameterRowListForService

import javax.faces.convert.ConverterException; //导入依赖的package包/类
@Test
public void createPricedParameterRowListForService()
        throws ConverterException {

    // Given product with two one time parameter, 1 configurable, 1 not
    // configurable
    VOService product = givenProductWithParams();
    List<PricedParameterRow> selectedParameters;

    // when
    selectedParameters = PricedParameterRow
            .createPricedParameterRowListForService(product);

    // then
    Assert.assertEquals(1, selectedParameters.size());
    assertTrue(selectedParameters.get(0).isOneTimeParameter());
    Assert.assertEquals("d1", selectedParameters.get(0).getParameter()
            .getValue());

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:21,代码来源:PricedParameterRowTest.java

示例14: getConvertedValue

import javax.faces.convert.ConverterException; //导入依赖的package包/类
@Override
public Object getConvertedValue(
  FacesContext context,
  UIComponent  component,
  Object       submittedValue
  ) throws ConverterException
{
  boolean valuePassThru = getValuePassThru(component, getFacesBean(component));

  if (!valuePassThru)
  {
    return _convertIndexedSubmittedValue(context, component, submittedValue);
  }
  else
  {
    return super.getConvertedValue(context, component, submittedValue);
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:19,代码来源:SimpleSelectOneRenderer.java

示例15: getConvertedValue

import javax.faces.convert.ConverterException; //导入依赖的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


注:本文中的javax.faces.convert.ConverterException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。