mojarra icon indicating copy to clipboard operation
mojarra copied to clipboard

ElSupport.coerceToType(...) add support for target type java.lang.Class

Open djmj opened this issue 7 years ago • 0 comments

ELSupport.coerceToType lacks support for class runtime type conversion.

I tried to pass a class instance to a converter attribute but failed due to:

java.lang.IllegalArgumentException: Cannot convert java.util.Date of type class java.lang.String to class java.lang.Class at com.sun.el.lang.ELSupport.coerceToType(ELSupport.java:428)

Markup:

<o:converter converterId="RangeConverter" type="java.util.Date"/>

Converter:

public class Range<T>
{
	private T start;
	private T end;
}

public class RangeConverter<T> implements Converter<T>
{
	// required in getAsObject method
	private Class<T> type;

	public Range<T> getAsObject(FacesContext context, UIComponent component, final String value)
	{
		// create default converter  for start ane end
		Converter<T> startEndConverter = context.getApplication().createConverter(this.type)
	}
	
	public void setType(Class<T> type)
	{
		this.type = type;
	}
}

Class Converter

Registration of a @FacesConverter for Class.class did not worked.

@FacesConverter(forClass = Class.class)
public class ClassConverter implements Converter<Class<?>>

Example

http://showcase.omnifaces.org/converters/ToCollectionConverter Passes the type as a String and converts it internally. But this is unnecessary if coerceToType supports Class.class

djmj avatar Nov 28 '18 02:11 djmj