Java Code Examples for javax.faces.convert.Converter

The following are top voted examples for showing how to use javax.faces.convert.Converter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: myfaces-trinidad   File: SimpleInputColorRenderer.java   Source Code and License 7 votes vote down vote up
@Override
protected Integer getDefaultColumns(
  RenderingContext rc,
  UIComponent      component,
  FacesBean        bean)
{
  Integer columnsInteger = null;

  Converter converter = getConverter(component, bean);

  // Ignoring the "default" converter code is intentional;  we'll just
  // fall through to _DEFAULT_COLUMNS here to save time
  if (converter instanceof ColorConverter)
  {
    int columns = ((ColorConverter) converter).getColumns(FacesContext.getCurrentInstance());
    columnsInteger = columns;
  }
  else
  {
    columnsInteger = _DEFAULT_COLUMNS;
  }

  return columnsInteger;
}
 
Example 2
Project: XPagesExtensionLibrary   File: ValueColumn.java   Source Code and License 7 votes vote down vote up
@Override
public void restoreState(FacesContext context, Object state) {
	Object values[] = (Object[]) state;
	super.restoreState(context, values[0]);
       columnTitle = (String)values[1];
       columnName = (String)values[2];
	value = StateHolderUtil.restoreObjectState(context,getComponent(),values[3]);
       converter = (Converter)StateHolderUtil.restoreObjectState(context, getComponent(), values[4]);
       style = (String)values[5];
       styleClass = (String)values[6];
       href = (String)values[7];
       contentType = (String)values[8];
       headerStyle = (String)values[9];
       headerStyleClass = (String)values[10];
       linkTitle = (String)values[11];
       headerLinkTitle = (String)values[12];
}
 
Example 3
Project: cats   File: RackControllerTest.java   Source Code and License 7 votes vote down vote up
@Deployment
public static WebArchive createDeployment()
{
    MavenDependencyResolver resolver = DependencyResolvers.use( MavenDependencyResolver.class )
            .loadMetadataFromPom( "pom.xml" );

    return ShrinkWrap.create(WebArchive.class)
            .addClasses( HtmlSelectOneMenu.class, YAMLUtils.class, Converter.class, SettopInfo.class, DevRack.class)
            .addAsLibraries(resolver.artifact("org.yaml:snakeyaml:1.10").resolveAsFiles())
            .addAsLibraries(resolver.artifact("commons-lang:commons-lang:2.3").resolveAsFiles())
            .addAsLibraries(resolver.artifact("log4j:log4j:1.2.14").resolveAsFiles())
            .addAsLibraries(resolver.artifact("org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:1.0.0.Final").resolveAsFiles())
            .addAsLibraries(resolver.artifact("org.primefaces:primefaces:3.4.1").resolveAsFiles())
            .addAsLibraries(resolver.artifact("com.comcast.cats:ir-common:3.2.0.5").resolveAsFiles())
     /*     .addAsLibraries(resolver.artifact("org.jboss.spec.javax.faces:jboss-jsf-api_2.0_spec:1.0.0.Final").resolveAsFiles())*/
            .addPackage( SlotConnectionRepresenter.class.getPackage() )
            .addPackage( SettopSlotConfigServiceImpl.class.getPackage() )
            .addPackage( Slot.class.getPackage() )
            .addAsResource(new File("src/test/resources", "rackconfig.catsrack"))
            .addAsResource(new File("src/test/resources", "settops.catsrack"))
            .addAsResource(new File("src/test/resources", "settopTypes.catsrack"))
            .addPackage( SettopDesc.class.getPackage() )
            .addAsWebInfResource( new File("src/main/webapp/WEB-INF/beans.xml"))
            .addAsWebInfResource( new File("src/main/webapp/WEB-INF/faces-config.xml"))
            .setWebXML(new File("src/main/webapp/WEB-INF/web.xml"));
}
 
Example 4
Project: myfaces-trinidad   File: SimpleInputDateRenderer.java   Source Code and License 6 votes vote down vote up
@Override
protected Integer getDefaultColumns(
  RenderingContext rc,
  UIComponent      component,
  FacesBean        bean)
{
  Integer columnsInteger = null;

  Converter converter = getConverter(component, bean);

  // Ignoring the "default" converter code is intentional;  we'll just
  // fall through to _DEFAULT_COLUMNS here to save time
  if (converter instanceof
      org.apache.myfaces.trinidadinternal.convert.DateTimeConverter)
  {
    int columns = ((org.apache.myfaces.trinidadinternal.convert.DateTimeConverter)
            converter).getColumns();
    columnsInteger = (columns);
  }
  else
  {
    columnsInteger = _DEFAULT_COLUMNS;
  }

  return columnsInteger;
}
 
Example 5
Project: myfaces-trinidad   File: FormRenderer.java   Source Code and License 6 votes vote down vote up
public static void addOnSubmitConverterValidators(
  UIComponent         component,
  Converter           converter,
  Iterator<Validator> validators,
  String              clientId,
  boolean             immediate,
  boolean             required,
  String              requiredMessageKey
  ) throws IOException
{
  CoreFormData fData = (CoreFormData)
    RenderingContext.getCurrentInstance().getFormData();

  fData.addOnSubmitConverterValidators(component,
                                       converter,
                                       validators,
                                       clientId,
                                       immediate,
                                       required,
                                       requiredMessageKey);
}
 
Example 6
Project: myfaces-trinidad   File: SimpleSelectOneChoiceRenderer.java   Source Code and License 6 votes vote down vote up
@Override
protected void encodeElementContent(
  FacesContext     context,
  RenderingContext rc,
  UIComponent      component,
  FacesBean        bean,
  List<SelectItem> selectItems,
  int              selectedIndex,
  Converter        converter,
  boolean          valuePassThru
  ) throws IOException
{
  ResponseWriter writer = context.getResponseWriter();
  writer.startElement("select", component);
  renderId(context, component);
  renderAllAttributes(context, rc, component, bean, false);

  encodeSelectItems(context, rc, component, bean,
                    selectItems, selectedIndex, converter,
                    valuePassThru);

  writer.endElement("select");
}
 
Example 7
Project: myfaces-trinidad   File: ValueRenderer.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 8
Project: myfaces-trinidad   File: SimpleSelectOneRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
  }
}
 
Example 9
Project: myfaces-trinidad   File: EditableValueRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 10
Project: myfaces-trinidad   File: SimpleSelectManyRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * Override to return a Converter for the items in the value,
 * not the value itself.
 */
@Override
protected Converter getDefaultConverter(
  FacesContext context,
  UIComponent  copmonent,
  FacesBean    bean)
{
  ValueExpression expression = getValueExpression(copmonent, bean);
  if (expression == null)
    return null;

  Class<?> type = expression.getType(context.getELContext());
  if ((type == null) || type.isAssignableFrom(List.class))
    return null;

  if (type.isArray())
  {
    Class<?> itemClass = type.getComponentType();
    return ConverterUtils.createConverter(context, itemClass);
  }

  _throwUnsupportedModelType(context, type, null);
  return null;
}
 
Example 11
Project: myfaces-trinidad   File: ConverterBoundValue.java   Source Code and License 6 votes vote down vote up
public Object getValue(UIXRenderingContext context)
{
  FacesBean bean = _component.getFacesBean();
  // Try to get an explicit Converter
  Converter converter = (Converter)
    bean.getProperty(UIXValue.CONVERTER_KEY);

  // OK, no explicit converter, look at the ValueExpression
  if (converter == null)
  {
    ValueExpression expression = bean.getValueExpression(UIXValue.VALUE_KEY);
    if (expression != null)
    {
      FacesContext fContext = (context == null) ? 
        FacesContext.getCurrentInstance() : context.getFacesContext();
      Class<?> type = expression.getType(fContext.getELContext());
      converter = ConverterUtils.createConverter(fContext, type);
    }
  }
  
  return converter;
}
 
Example 12
Project: myfaces-trinidad   File: FastRenderer.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 13
Project: myfaces-trinidad   File: FastRenderer2.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 14
Project: myfaces-trinidad   File: DateTimeRangeValidator.java   Source Code and License 6 votes vote down vote up
private FacesMessage _getNotInRangeMessage(
  FacesContext context,
  UIComponent component,
  Object value,
  Object min,
  Object max)
{ 
  Converter converter = _getConverter(context, component);

  Object cValue = _getConvertedValue(context, component, converter, value);
  Object cMin   = _getConvertedValue(context, component, converter, min);
  Object cMax   = _getConvertedValue(context, component, converter, max);

  Object msg   = _getRawNotInRangeMessageDetail();
  Object label = ValidatorUtils.getComponentLabel(component);

  Object[] params = {label, cValue, cMin, cMax};

  return MessageFactory.getMessage(context, NOT_IN_RANGE_MESSAGE_ID,
                                    msg, params, component);
}
 
Example 15
Project: myfaces-trinidad   File: DateTimeRangeValidator.java   Source Code and License 6 votes vote down vote up
private FacesMessage _getMaximumMessage(
  FacesContext context,
  UIComponent component,
  Object value,
  Object max)
{
  Converter converter = _getConverter(context, component);

  Object cValue = _getConvertedValue(context, component, converter, value);
  Object cMax   = _getConvertedValue(context, component, converter, max);

  Object msg   = _getRawMaximumMessageDetail();
  Object label = ValidatorUtils.getComponentLabel(component);

  Object[] params = {label, cValue, cMax};

  return MessageFactory.getMessage(context,
                                   MAXIMUM_MESSAGE_ID,
                                   msg,
                                   params,
                                   component);
}
 
Example 16
Project: myfaces-trinidad   File: DateTimeRangeValidator.java   Source Code and License 6 votes vote down vote up
private FacesMessage _getMinimumMessage(
  FacesContext context,
  UIComponent component,
  Object value,
  Object min)
{
  Converter converter = _getConverter(context, component);

  Object cValue = _getConvertedValue(context, component, converter, value);
  Object cMin   = _getConvertedValue(context, component, converter, min);


  Object msg      = _getRawMinimumMessageDetail();
  Object label    = ValidatorUtils.getComponentLabel(component);

  Object[] params = {label, cValue, cMin};

  return MessageFactory.getMessage(context, MINIMUM_MESSAGE_ID,
                                   msg, params, component);
}
 
Example 17
Project: myfaces-trinidad   File: DateTimeRangeValidator.java   Source Code and License 6 votes vote down vote up
private Converter _getConverter(
  FacesContext context,
  UIComponent component)
{
  Converter converter = null;
  if (component instanceof ValueHolder)
  {
    converter = ((ValueHolder) component).getConverter();
  }

  if (converter == null)
  {
    // Use the DateTimeConverter's CONVERTER_ID, not Date.class,
    // because there is in fact not usually a converter registered
    // at Date.class
    converter = context.getApplication().createConverter(
                    DateTimeConverter.CONVERTER_ID);
  }

  assert(converter != null);

  return converter;
}
 
Example 18
Project: myfaces-trinidad   File: DateRestrictionValidator.java   Source Code and License 6 votes vote down vote up
private Converter _getConverter(
  FacesContext context,
  UIComponent component)
{
  Converter converter = null;
  if (component instanceof ValueHolder)
  {
    converter = ((ValueHolder) component).getConverter();
  }

  if (converter == null)
  {
    // Use the DateTimeConverter's CONVERTER_ID, not Date.class,
    // because there is in fact not usually a converter registered
    // at Date.class
    converter = context.getApplication().createConverter(DateTimeConverter.CONVERTER_ID);
  }

  assert(converter != null);

  return converter;
}
 
Example 19
Project: myfaces-trinidad   File: DateRestrictionValidator.java   Source Code and License 6 votes vote down vote up
/**
 * Builds an error message indicating invalid week-day selection
 * @param context FacesContext
 * @param component inputDate instance
 * @param converter date converter instance
 * @param value user submitted value
 * @param dayOfTheWeekIndex Week day index as returned by Calendar.DAY_OF_WEEK on the value
 * @return FacesMessage
 */
private FacesMessage _getWrongWeekDayMessage(
  FacesContext  context,
  UIComponent   component,
  Converter     converter,
  Object        value,
  int           dayOfTheWeekIndex)
{ 
  RequestContext reqContext = RequestContext.getCurrentInstance();      
  Locale locale = reqContext.getFormattingLocale();

  if (locale == null)
  {
    locale = context.getViewRoot().getLocale();
  }
    
  Object cValue = _getConvertedValue(context, component, converter, value);
  Object msg   = _getRawInvalidDaysOfWeekMessageDetail();
  Object label = ValidatorUtils.getComponentLabel(component);
  String[] weekdays = new DateFormatSymbols(locale).getWeekdays();

  // Fetch the localized week name 
  Object[] params = {label, cValue, weekdays[dayOfTheWeekIndex]};

  return MessageFactory.getMessage(context, WEEKDAY_MESSAGE_ID, msg, params, component);
}
 
Example 20
Project: myfaces-trinidad   File: DateRestrictionValidator.java   Source Code and License 6 votes vote down vote up
private FacesMessage _getWrongDayMessage(
  FacesContext context,
  UIComponent component,
  Object value,
  Object day)
{ 
  Converter converter = _getConverter(context, component);

  Object cValue = _getConvertedValue(context, component, converter, value);
  Object cDay   = _getConvertedValue(context, component, converter, day);

  Object msg   = _getRawInvalidDaysMessageDetail();
  Object label = ValidatorUtils.getComponentLabel(component);

  Object[] params = {label, cValue, cDay};

  return MessageFactory.getMessage(context, DAY_MESSAGE_ID, msg, params, component);
}
 
Example 21
Project: myfaces-trinidad   File: JsfNumberConverterTest.java   Source Code and License 6 votes vote down vote up
@Override
protected void doTestStateHolderSaveRestore(
  Converter conv1,
  Converter conv2,
  MockFacesContext context,
  MockUIComponentWrapper wrapper
  )
{
  Object state = ((StateHolder)conv1).saveState(context);

  ((StateHolder)conv2).restoreState(context, state);

  boolean isEqual =  _isConvertersEqual((NumberConverter)conv1,
                                         (NumberConverter)conv2);

  assertEquals(true, isEqual);
  wrapper.getMock().verify();
}
 
Example 22
Project: ButterFaces   File: ReadonlyPartRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * 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);
}
 
Example 23
Project: community-edition-old   File: BaseComponentGenerator.java   Source Code and License 6 votes vote down vote up
/**
 * Creates the converter with the given id and adds it to the component.
 * 
 * @param context FacesContext
 * @param converterId The name of the converter to create
 * @param component The component to add the converter to
 */
protected void createAndSetConverter(FacesContext context, String converterId, 
      UIComponent component)
{
   if (converterId != null && component instanceof UIOutput)
   {
      try
      {
         Converter conv = context.getApplication().createConverter(converterId);
         ((UIOutput)component).setConverter(conv);
      }
      catch (NullPointerException npe)
      {
         // workaround a NPE bug in MyFaces
         logger.warn("Converter " + converterId + " could not be applied");
      }
      catch (FacesException fe)
      {
         logger.warn("Converter " + converterId + " could not be applied");
      }
   }
}
 
Example 24
Project: karaku   File: SelectHelper.java   Source Code and License 6 votes vote down vote up
private static Object findValueByStringConversion(FacesContext context,
		UIComponent component, Iterator<SelectItem> items, String value,
		Converter converter) {

	while (items.hasNext()) {
		SelectItem item = items.next();
		if (item instanceof SelectItemGroup) {
			SelectItem[] subitems = ((SelectItemGroup) item)
					.getSelectItems();
			if (!isEmpty(subitems)) {
				Iterator<SelectItem> iSubItems = Arrays.asList(subitems)
						.iterator();
				Object object = findValueByStringConversion(context,
						component, iSubItems, value, converter);
				if (object != null) {
					return object;
				}
			}
		} else if (!item.isNoSelectionOption()
				&& value.equals(converter.getAsString(context, component,
						item.getValue()))) {
			return item.getValue();
		}
	}
	return null;
}
 
Example 25
Project: BootsFaces-OSP   File: CoreRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * Finds the appropriate converter for a given value holder
 *
 * @param fc
 *            FacesContext instance
 * @param vh
 *            ValueHolder instance to look converter for
 * @return Converter
 */
public static Converter getConverter(FacesContext fc, ValueHolder vh) {
	// explicit converter
	Converter converter = vh.getConverter();

	// try to find implicit converter
	if (converter == null) {
		ValueExpression expr = ((UIComponent) vh).getValueExpression("value");
		if (expr != null) {
			Class<?> valueType = expr.getType(fc.getELContext());
			if (valueType != null) {
				converter = fc.getApplication().createConverter(valueType);
			}
		}
	}

	return converter;
}
 
Example 26
Project: BootsFaces-OSP   File: CoreRenderer.java   Source Code and License 6 votes vote down vote up
protected Converter resolveConverter(FacesContext context, UIComponent c) {
	if (!(c instanceof ValueHolder)) {
		return null;
	}

	Converter cnv = ((ValueHolder) c).getConverter();

	if (cnv != null) {
		return cnv;
	} else {
		ValueExpression ve = c.getValueExpression("value");

		if (ve != null) {
			Class<?> valType = ve.getType(context.getELContext());

			if (valType != null) {
				return context.getApplication().createConverter(valType);
			}
		}

		return null;
	}
}
 
Example 27
Project: BootsFaces-OSP   File: RadiobuttonRenderer.java   Source Code and License 6 votes vote down vote up
private List<String> collectLegalValues(FacesContext context, List<UIComponent> radioButtonGroup) {
	List<String> legalValues = new ArrayList<String>();
	for (UIComponent b: radioButtonGroup) {
		Radiobutton r = (Radiobutton)b;
		Converter converter = r.getConverter();
		List<SelectItemAndComponent> options = SelectItemUtils.collectOptions(context, r, converter);
		if (options.size()>0) {
			// traditional JSF approach using f:selectItem[s]
			for (SelectItemAndComponent option:options) {
				String o = null;
				if (null != option.getSelectItem().getValue()) {
					o = String.valueOf(option.getSelectItem().getValue());
				}
				legalValues.add(o);
			}

		} else {
			// BootsFaces approach using b:radioButtons for each radiobutton item
			legalValues.add(r.getItemValue());
		}
	}
	return legalValues;
}
 
Example 28
Project: BootsFaces-OSP   File: SelectMultiMenuRenderer.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
	}
}
 
Example 29
Project: BootsFaces-OSP   File: SelectOneMenuRenderer.java   Source Code and License 6 votes vote down vote up
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);
	}
}
 
Example 30
Project: BootsFaces-OSP   File: SelectOneMenuRenderer.java   Source Code and License 6 votes vote down vote up
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;
}
 
Example 31
Project: XPagesExtensionLibrary   File: DataSourceIteratorRenderer.java   Source Code and License 6 votes vote down vote up
protected Converter findConverter(FacesContext context, UIDataSourceIterator c, ViewDefinition viewDef, ValueColumn vc, Object value) {
    // Explicit converter
    Converter converter = vc.getConverter();
    if(converter!=null) {
        return converter;
    }

    Class<?> converterType = value.getClass();
    if (converterType == null || converterType == String.class || converterType == Object.class) {
        return null;
    }
    
    // Acquire an appropriate converter instance.
    try {
        Application application = context.getApplication();
        return application.createConverter(converterType);
    } catch (Exception e) {
    }
    
    return null;
}
 
Example 32
Project: XPagesExtensionLibrary   File: DojoComboBoxRenderer.java   Source Code and License 6 votes vote down vote up
protected void renderOption(FacesContext context, ResponseWriter writer, UIDojoComboBox component, Converter converter, SelectItem curItem, String currentValue) throws IOException {
    writer.writeText(" ", null);
    writer.startElement("option", component); // $NON-NLS-1$

    String value = convertValue(context,component, converter, curItem.getValue());
    writer.writeAttribute("value", value, "value"); // $NON-NLS-1$ $NON-NLS-2$

    // Get the value to compare to
    boolean isSelected = isSelected(curItem, currentValue);

    if (isSelected) {
        writer.writeAttribute("selected", "selected", "selected"); // $NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$
    }
    if (curItem.isDisabled()) {
        writer.writeAttribute("disabled", "disabled", "disabled"); // $NON-NLS-1$ $NON-NLS-2$ $NON-NLS-3$
    }

    writer.writeText(curItem.getLabel(), "label"); // $NON-NLS-1$
    writer.endElement("option"); // $NON-NLS-1$
    writer.writeText("\n", null); // $NON-NLS-1$

}
 
Example 33
Project: cats   File: SlotConnectionConstructorRepresenterTest.java   Source Code and License 6 votes vote down vote up
@Deployment
public static WebArchive createDeployment()
{
    MavenDependencyResolver resolver = DependencyResolvers.use( MavenDependencyResolver.class )
            .loadMetadataFromPom( "pom.xml" );

    return ShrinkWrap.create(WebArchive.class)
            .addClasses( HtmlSelectOneMenu.class, YAMLUtils.class, Converter.class, SettopInfo.class, DevRack.class)
            .addAsLibraries(resolver.artifact("org.yaml:snakeyaml:1.10").resolveAsFiles())
            .addAsLibraries(resolver.artifact("commons-lang:commons-lang:2.3").resolveAsFiles())
            .addAsLibraries(resolver.artifact("log4j:log4j:1.2.14").resolveAsFiles())
            .addAsLibraries(resolver.artifact("org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:1.0.0.Final").resolveAsFiles())
            .addAsLibraries(resolver.artifact("org.primefaces:primefaces:3.4.1").resolveAsFiles())
            .addAsLibraries(resolver.artifact("com.comcast.cats:ir-common:3.2.0.5").resolveAsFiles())
     /*     .addAsLibraries(resolver.artifact("org.jboss.spec.javax.faces:jboss-jsf-api_2.0_spec:1.0.0.Final").resolveAsFiles())*/
            .addPackage( SlotConnectionRepresenter.class.getPackage() )
            .addPackage( SettopSlotConfigServiceImpl.class.getPackage() )
            .addPackage( Slot.class.getPackage() )
            .addAsResource(new File("src/test/resources", "rackconfig.catsrack"))
            .addAsResource(new File("src/test/resources", "settops.catsrack"))
            .addAsResource(new File("src/test/resources", "settopTypes.catsrack"))
            .addPackage( SettopDesc.class.getPackage() )
            .addAsWebInfResource( new File("src/main/webapp/WEB-INF/beans.xml"))
            .addAsWebInfResource( new File("src/main/webapp/WEB-INF/faces-config.xml"))
            .setWebXML(new File("src/main/webapp/WEB-INF/web.xml"));
}
 
Example 34
Project: cats   File: SettopControllerTest.java   Source Code and License 6 votes vote down vote up
@Deployment
public static WebArchive createDeployment() {
    MavenDependencyResolver resolver = DependencyResolvers
            .use(MavenDependencyResolver.class)
            .loadMetadataFromPom("pom.xml");

    return ShrinkWrap.create(WebArchive.class)
                .addClasses( HtmlSelectOneMenu.class, YAMLUtils.class, Converter.class, SettopInfo.class, DevRack.class)
                .addAsLibraries(resolver.artifact("org.yaml:snakeyaml:1.10").resolveAsFiles())
                .addAsLibraries(resolver.artifact("commons-lang:commons-lang:2.3").resolveAsFiles())
                .addAsLibraries(resolver.artifact("log4j:log4j:1.2.14").resolveAsFiles())
                .addAsLibraries(resolver.artifact("org.jboss.spec.javax.servlet:jboss-servlet-api_3.0_spec:1.0.0.Final").resolveAsFiles())
                .addAsLibraries(resolver.artifact("org.primefaces:primefaces:3.4.1").resolveAsFiles())
                .addAsLibraries(resolver.artifact("com.comcast.cats:ir-common:3.2.0.5").resolveAsFiles())
         /*     .addAsLibraries(resolver.artifact("org.jboss.spec.javax.faces:jboss-jsf-api_2.0_spec:1.0.0.Final").resolveAsFiles())*/
                .addPackage( SlotConnectionRepresenter.class.getPackage() )
                .addPackage( SettopSlotConfigServiceImpl.class.getPackage() )
                .addPackage( Slot.class.getPackage() )
                .addAsResource(new File("src/test/resources", "rackconfig.catsrack"))
                .addAsResource(new File("src/test/resources", "settops.catsrack"))
                .addAsResource(new File("src/test/resources", "settopTypes.catsrack"))
                .addPackage( SettopDesc.class.getPackage() )
                .addAsWebInfResource( new File("src/main/webapp/WEB-INF/beans.xml"))
                .addAsWebInfResource( new File("src/main/webapp/WEB-INF/faces-config.xml"))
                .setWebXML(new File("src/main/webapp/WEB-INF/web.xml"));
}
 
Example 35
Project: myfaces-trinidad   File: DateTimeRangeValidator.java   Source Code and License 5 votes vote down vote up
private SimpleDateFormat _getISOFormat (Converter conv)
{
  SimpleDateFormat isoFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  // Trinidad-1967: ISOFormat should use the same timezone as the converter's
  // Make sure this matches DateTimeConverter's#_getTimeZone
  TimeZone tZone = null;

  if (conv instanceof javax.faces.convert.DateTimeConverter)
     tZone = ((javax.faces.convert.DateTimeConverter)conv).getTimeZone();
   
  if (tZone == null)
  {
    RequestContext context = RequestContext.getCurrentInstance();
    if (context == null)
    {
      _LOG.warning("NO_REQUESTCONTEXT_TIMEZONE_DEFAULT");
    }
    else
    {
      tZone = context.getTimeZone();
    }

    // If RequestContext is null or if it returns a null,
    // then set it to the default time zone which is GMT time zone
    if (tZone == null)
    {
      tZone = _DEFAULT_TIME_ZONE;
    }
  }
  isoFormat.setTimeZone(tZone);
  return isoFormat;    
}
 
Example 36
Project: myfaces-trinidad   File: ColorPickerJSP.java   Source Code and License 5 votes vote down vote up
static private Converter _getConverter(Map<String, String> requestParams)
{
  String pattern = requestParams.get("pattern");
  boolean allowsTransparent =
    "true".equals(requestParams.get("allowsTransparent"));
  ColorConverter converter = new ColorConverter();
  converter.setPatterns(pattern.split(" "));
  if (allowsTransparent)
    converter.setTransparentAllowed(true);
  return converter;
}
 
Example 37
Project: myfaces-trinidad   File: SimpleInputColorRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * 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();
}
 
Example 38
Project: myfaces-trinidad   File: SimpleInputColorRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * Return a default converter.
 */
@Override
protected Converter getDefaultConverter(
  FacesContext context,
  UIComponent  component,
  FacesBean    bean)
{
  return _DEFAULT_CONVERTER;
}
 
Example 39
Project: myfaces-trinidad   File: SimpleInputDateRenderer.java   Source Code and License 5 votes vote down vote up
/**
 * 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();
}
 
Example 40
Project: myfaces-trinidad   File: SelectManyShuttleRenderer.java   Source Code and License 5 votes vote down vote up
@Override
protected int[] getSelectedIndices(
  FacesContext     context,
  UIComponent      component,
  FacesBean        bean,
  List<SelectItem> selectItems,
  Converter        converter,
  boolean          valuePassThru)
{
  return _EMPTY_INT_ARRAY;
}