jakartaee / faces

Jakarta Faces
Other
106 stars 55 forks source link

JSF 2.3 with Java 10&11 not recognizing generic types with f:viewParam #1468

Open eclipse-faces-bot opened 6 years ago

eclipse-faces-bot commented 6 years ago

If you have an abstract class with generic types and try to set that attribute with f:viewParam, always get String type if running with Java 11. If you run the same code with Java 8, it works as expected. Ex:

/** CrudBean.java */
...
public abstract class CrudBean<K, E extends DomainEntity<K>> {
  private K id;
  private E e; 
...
  public K getId() {
    return id;
  }

  public void setId(K id) {
    this.id = id;
  }
...
/** ZoneBean.java */
...
@Named
@ViewScoped
public class ZoneBean extends CrudBean<Integer, Zone> implements Serializable {
...

zone.xhtml

...
<f:metadata>
  <f:viewParam name="id" value="#{zoneBean.id}"/>
</f:metadata>
...

When you run this code in Java 8, the id attribute set the value as Integer. In Java 10&11, the id attribute set the value as String and JSF throws the following error: javax.servlet.ServletException: Provided id of the wrong type for class Zone. Expected: class java.lang.Integer, got class java.lang.String

Technologies used:

eclipse-faces-bot commented 5 years ago
eclipse-faces-bot commented 6 years ago

@maxcav7 Commented The workaround for this problem is to set the converter in the f:viewParam. Ex: <f:viewParam name="id" value="#{zoneBean.id}" converter="javax.faces.Integer"/>