Seam won't set POJO values for abstract base classes
bcowdery.bcowdery.gmail.com Dec 10, 2008 7:06 PMWe're currently writing a java frontend for our reporting system using Seam, and to accommodate the differentiating parameter types that each report expects, we built an abstract super class and left it up to the implementation classes to specify the type of the expected values. This works great as it allows us to specify custom validation etc, but Seam is having issues setting values on anything OTHER than a String type value.
Below is a simplified example of our source code, I've removed all the cruft for you lazy readers
Report contains many report parameters, using a polymorphic association
@Entity @Table(name = "ENTERPRISE_REPORTS") public class EnterpriseReport implements Serializable { @OneToMany(cascade = CascadeType.ALL, mappedBy = "report", fetch = FetchType.EAGER) private List<EnterpriseReportParam> parameters; // getters & setters ... }
Base report param class, contains common data such as name, description etc.
@Entity @Table(name = "ENTERPRISE_REPORT_PARAMS") @Inheritance(strategy = InheritanceType.SINGLE_TABLE) @DiscriminatorColumn(name = "REPORT_PARAM_TYPE", discriminatorType = DiscriminatorType.STRING) public abstract class EnterpriseReportParam<T> implements Serializable { @Transient public abstract T getValue(); public abstract void setValue(T value); @ManyToOne @JoinColumns({ @JoinColumn(name = "REPORT_ID", referencedColumnName = "REPORT_ID", nullable = false, updatable = false) }) private EnterpriseReport report; }
And the concrete implementation
@Entity @DiscriminatorValue("Period") public class PeriodEnterpriseReportParam extends EnterpriseReportParam<Integer> { @Column(name = "PERIOD_VALUE", length = 6) private Integer value; public Integer getValue() { return value; } public void setValue(Integer value) { this.value = value; } }
Our input.xhtml page iterates through each EnterpriseReportParam, printing out an input field for each one. We bind the h:inputText value to the parameters.getValue() method (which will be typed for the Concrete implementation).
<ui:repeat value="#{report.parameters}" var="param" > <h:inputText value="#{param.value}"/> </ui:repeat>
But when we type in the value and submit the form, an ambiguous error is displayed - yet nothing shows in the logs.
/reporting/parametersInput.xhtml @20,106 value="#{param.value}": Error writing 'value' on type com.companyname.reporting.entities.parameters.PeriodEnterpriseReportParam
We've tried defining converters by name, and using @Converter(forClass = Integer.class), but nothing seems to help. Anyone have any ideas?