Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

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

Open
djmj opened this issue Nov 28, 2018 · 0 comments
Open

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

djmj opened this issue Nov 28, 2018 · 0 comments

Comments

@djmj
Copy link

djmj commented Nov 28, 2018

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 djmj changed the title ElSupport - Coerce to class ElSupport.coerceToType(...) add support for target type java.lang.Class Nov 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant