I want to fill a simple h:datatable tag with some values from a database. But i get an exception and i cant find what is the reason:
java.lang.NumberFormatException: For input string: "url"
This is how i create the datatable:
<h:form>
<h:dataTable value="#{managementBB.retrieveRecords()}" var="record">
<h:column>
<f:facet name="header">URL</f:facet>
#{record.url}
</h:column>
<h:column>
<f:facet name="header">Submition date</f:facet>
#{record.submitionDate}
</h:column>
<h:column>
<f:facet name="header">Unacceptable</f:facet>
#{record.unnaceptableContent}
</h:column>
<h:column>
<f:facet name="header">Option</f:facet>
Something
</h:column>
</h:dataTable>
</h:form>
This is the backing bean behind this page:
@Named("managementBB")
@SessionScoped
public class ManagementBB implements Serializable{
@EJB
private ILinkManagerEJB linkManagerEJB;
public List<Record> retrieveRecords() {
return linkManagerEJB.retrieveRecords();
}
}
This is the EJB that accesses the database to get the data:
@Stateless(name = "ejbs/LinkManagerEJB")
public class LinkManagerEJB implements ILinkManagerEJB {
@PersistenceContext
private EntityManager entityManager;
public List<Record> retrieveRecords() {
Query allRecords = entityManager.createNamedQuery("allrecordinfo");
return (List<Record>) allRecords.getResultList();
}
}
And finally this is the JPA entity that represents a row in the database:
@Entity
@NamedQueries({@NamedQuery(name = "allrecordinfo",
query = "SELECT r.url, r.submitionDate, r.unnaceptableContent FROM Record r")})
public class Record {
@Id
@GeneratedValue
private long id;
@Column(nullable = false)
private String url;
@Column(nullable = false)
private String submitionDate;
@Column(nullable = false)
private boolean unnaceptableContent;
//Get set methods ...
}
As you see it looks simple, and I've done this before but now I am confused, I don't know why is not working. Could you help me find my error?
Note: I am pretty confident that the query syntax is ok (I tested it in eclipse's scrapbook)