This content has been marked as final.
Show 3 replies
-
1. Re: Specify fields in query and use in datatable?
fernando_jmt Mar 5, 2008 4:35 AM (in response to brodequin.al.green.vec.virginia.gov)What about:
@Factory("acertRequests") public void requestList(){ String requestQuery = "select t.acertNumber, t.acertTitle from Task t"; acertRequests = (List<Object[]>) em.createQuery(requestQuery).getResultList(); }
and:
<h:dataTable id="table1" value="#{acertRequests}" var="req"> <h:column><h:outputText value="#{req[0]}" /></h:column> <h:column><h:outputText value="#{req[1]}" /></h:column> </h:dataTable>
-
2. Re: Specify fields in query and use in datatable?
brodequin.al.green.vec.virginia.gov Mar 7, 2008 1:05 AM (in response to brodequin.al.green.vec.virginia.gov)Yes, that worked! Thank you very much.
-
3. Re: Specify fields in query and use in datatable?
elenctic87 Oct 17, 2008 4:38 AM (in response to brodequin.al.green.vec.virginia.gov)The EL expressions in the columns of the dataTable, "#{req[0]}" and "#{req[1]}", leave something to be desired because they aren't very readable. You have to know that req[0] corresponds to acertNumber and req[1] corresponds to acertTitle. With many fields in the query that could get very unmanageable. Is there a way to reference the fields of the query by name? Maybe cast to something besides List<Object[]>, like List<NumAndTitle>? Assuming NumAndTitle has properties named num and title, could you then do "#{req.num}" and "#{req.title}". This is much more readable and scales well to queries with many fields.