Im trying call an hql and fill my datatable with the records in this list.
executeSQL4List Error::::::::::::::::::::::: org.hibernate.QueryException: Unable to resolve path [data.REC_NO], unexpected token [data] [select data from org.wi.core.model.VW_VISIT_ASSN_HIST where data.REC_NO = 201]
This is the error i get.
my code for html datatable:
<p:dataTable var="Detailrec" style="width:100%" paginator="true" scrollable="false" id="_dataTable2"
value="#{visitBean.listDetReport}" rowIndexVar="rowNum" rows="8" draggableColumns="true"
paginatorPosition="top" editable="false">
<p:column style="width:10%" sortBy="#{Detailrec.START_TIME}">
<f:facet name="header">
<h:outputText value="OLD START TIME" />
</f:facet>
<h:outputText value="#{Detailrec.START_TIME}"/>
</p:column>
<p:column style="width:10%" sortBy="#{Detailrec.END_TIME}" exportable="false">
<f:facet name="header">
<h:outputText value="OLD END TIME" />
</f:facet>
<h:outputText value="#{Detailrec.END_TIME}" />
</p:column>
<p:column style="width:20%" sortBy="#{Detailrec.TT_NO}">
<f:facet name="header">
<h:outputText value="TT NO" />
</f:facet>
<h:outputText value="#{Detailrec.TT_NO}"/>
</p:column>
<p:column style="width:20%" sortBy="#{Detailrec.COMMENTS}">
<f:facet name="header">
<h:outputText value="OLD COMMENTS" />
</f:facet>
<h:outputText value="#{Detailrec.COMMENTS}"/>
</p:column>
<p:column style="width:20%">
<f:facet name="header">
<h:outputText value="NEW COMMENTS" />
</f:facet>
<h:outputText value="#{Detailrec.NEW_COMMENTS}"/>
</p:column>
<p:column style="width:20%">
<f:facet name="header">
<h:outputText value="EDIT TIME" />
</f:facet>
<h:outputText value="#{Detailrec.EDIT_TIME}"/>
</p:column>
<p:column style="width:20%">
<f:facet name="header">
<h:outputText value="SYSTEM COMMENTS" />
</f:facet>
<h:outputText value="#{Detailrec.SYSTEM_COMMENTS}"/>
</p:column>
<p:column style="width:20%">
<f:facet name="header">
<h:outputText value="EDITED BY" />
</f:facet>
<h:outputText value="#{Detailrec.EDITTED_BY_NAME}"/>
</p:column>
<p:column style="width:20%">
<f:facet name="header">
<h:outputText value="ALIAS" />
</f:facet>
<h:outputText value="#{Detailrec.ALIAS}"/>
</p:column>
</p:dataTable>
And my function in bean that fills this datatable through a commandbutton is :
public void ViewHistory(Integer REC_NUM)
{
try
{
REC_NO=REC_NUM;
SQL = "select data from VW_VISIT_ASSN_HIST where data.REC_NO ="+REC_NO;
listDetReport = glb.getEntityMgr().executeSQL4List(SQL, whereValues, VW_VISIT_ASSN_HIST.class, false);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Can anyone help me solve the issue here? Im really confused.
You are using column name as alias in your SQL. It's like:
SQL = "select data from VW_VISIT_ASSN_HIST where data.REC_NO ="+REC_NO;
Change it to remove alias as:
SQL = "select data from VW_VISIT_ASSN_HIST where REC_NO ="+REC_NO;
Related
I have datatable, code is below.
<h:form id="listaPoi">
<p:dataTable id="lokacije" var="poi" value="#{poiBacking.listaPoiLokacija}"
rowIndexVar="rowIndex" styleClass="nonsortable" paginator="true" rows="20"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="20,50,100" filteredValue="#{poiBacking.filteredPoi}"
emptyMessage="Nisu pronađeni POI za traženi upit">
<p:column filterBy="grad" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Mjesto" />
</f:facet>
<h:outputText value="#{poi.grad}" />
</p:column>
<p:column filterBy="adresa" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Adresa" />
</f:facet>
<h:outputText value="#{poi.adresa}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Geolat" />
</f:facet>
<h:outputText value="#{poi.geolat}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Geolon" />
</f:facet>
<h:outputText value="#{poi.geolon}" />
</p:column>
<p:column>
<f:facet name="header">
</f:facet>
<p:commandButton icon="ui-icon-pencil" value="Uredi lokaciju"
actionListener="#{poiBacking.getPois(poi.geolat,poi.geolon)}"
action="#{poiBacking.setLinkUpdate()}"
oncomplete="PF('poiDialog').show()" update=":unos,:poiDialogId,:toolbar" />
</p:column>
</p:dataTable>
</h:form>
Problem is when i click on second or any other page, datatable shows only first record. If i filter, results are the same. In backing bean list for filtered values contains all values but also shows only first.
Lists in PoiBacking:
private List<PoiLokacija> listaPoiLokacija;
private List<PoiLokacija> filteredPoi;
listaPoiLokacija is fill in #PostConstruct method init().
You didn't give us your code in PoiBacking, so I have no idea if there are something wrong in PoiBacking.
However, I tried your code and find every thing work just fine.
Check this:
Page(Deleted oncomplete="PF('poiDialog').show()" update=":unos,:poiDialogId,:toolbar" since I can't find them in your code) :
<h:form id="listaPoi">
<p:dataTable id="lokacije" var="poi" value="#{poiBacking.listaPoiLokacija}"
rowIndexVar="rowIndex" styleClass="nonsortable" paginator="true" rows="3"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="20,50,100" filteredValue="#{poiBacking.filteredPoi}"
emptyMessage="Nisu pronađeni POI za traženi upit">
<p:column filterBy="grad" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Mjesto" />
</f:facet>
<h:outputText value="#{poi.grad}" />
</p:column>
<p:column filterBy="adresa" filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Adresa" />
</f:facet>
<h:outputText value="#{poi.adresa}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Geolat" />
</f:facet>
<h:outputText value="#{poi.geolat}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Geolon" />
</f:facet>
<h:outputText value="#{poi.geolon}" />
</p:column>
<p:column>
<f:facet name="header">
</f:facet>
<p:commandButton icon="ui-icon-pencil" value="Uredi lokaciju"
actionListener="#{poiBacking.getPois(poi.geolat,poi.geolon)}"
action="#{poiBacking.setLinkUpdate()}"
/>
</p:column>
</p:dataTable>
</h:form>
Backing Bean(Set every attributes in PoiLokacija as String since you didn't mention it):
private List<PoiLokacija> listaPoiLokacija=new ArrayList<>();
private List<PoiLokacija> filteredPoi=new ArrayList<>();
#PostConstruct
public void init(){
listaPoiLokacija.add(new PoiLokacija("grad1", "adresa1", "geolat1", "geolon1"));
listaPoiLokacija.add(new PoiLokacija("grad2", "adresa2", "geolat2", "geolon2"));
listaPoiLokacija.add(new PoiLokacija("grad3", "adresa3", "geolat3", "geolon3"));
listaPoiLokacija.add(new PoiLokacija("grad4", "adresa4", "geolat4", "geolon4"));
listaPoiLokacija.add(new PoiLokacija("grad5", "adresa5", "geolat5", "geolon5"));
listaPoiLokacija.add(new PoiLokacija("grad6", "adresa6", "geolat6", "geolon6"));
filteredPoi.addAll(listaPoiLokacija);
}
public void getPois(String geolat,String geolon){
System.out.println(geolat+","+geolon);
}
public void setLinkUpdate(){
System.out.println("setLinkUpdate");
}
When i drag my panel into my 'dataTable', all works fine(my listener is called, my object is added to my DataBase) but my 'dataTable' is not updated and i need to refresh my page to see it. My xhtml:
<h:form id="formDashboard">
<p:layoutUnit id="gridLeft" position="west" size="250" style="position:absolute;">
<p:fieldset style="padding:0;padding-top:5px;">
<f:facet name="legend" id="legendId">
<p:commandButton icon="ui-icon-plus" actionListener="#{myMemosController.prepareCreate}" value="Add Memo" onclick="addMemo.show()" update=":formAdd:commentAddInput, :formAdd:chooseAddPriority" style="width:30px;height:30px;"/>
</f:facet>
<p:dataGrid id="leftData" var="item" columns="1" value="#{myMemosController.items}" style="border:none;">
<p:panel id="pnl" style="background-color:#{item.priority}}" closable="true">
<p:ajax event="close" listener="#{myMemosController.destroy}"/>
<f:facet name="header">
<h:panelGroup>
<h:outputText value="#{item.name}" styleClass=""/>
<p:commandButton icon="ui-icon-pencil" actionListener="#{myMemosController.prepareEdit}" update=":formEdit:commentEditInput, :formEdit:chooseEditPriority" onclick="editMemo.show();" style="width:19px;height:19px;"/>
</h:panelGroup>
</f:facet>
<h:panelGrid columns="1" style="width:100%">
<h:outputText value="#{item.comments}" styleClass=""/>
</h:panelGrid>
<f:facet name="footer">
<h:outputText value="#{item.date} at #{item.time}" styleClass="footerStyle"/>
</f:facet>
</p:panel>
<p:draggable for="pnl" helper="clone" handle=".ui-panel-titlebar" stack=".ui-panel" zindex="100"/>
</p:dataGrid>
</p:fieldset>
</p:layoutUnit>
<p:layoutUnit position="center" style="position:absolute;">
<p:fieldset id="selectedMemos" legend="Selected Memos" style="margin-top:20px">
<p:outputPanel id="dropArea">
<p:dataTable id="centerData" value="#{dashboardController.items}" var="item">
<p:column style="text-align:center;">
<f:facet name="header">
<h:outputText value="Priority"/>
</f:facet>
<h:outputText value="#{item.priorityname}"/>
</p:column>
<p:column style="text-align:center;">
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{item.name}"/>
</p:column>
<p:column style="text-align:center;">
<f:facet name="header">
<h:outputText value="Comment"/>
</f:facet>
<h:outputText value="#{item.comments}"/>
</p:column>
<p:column style="text-align:center;">
<f:facet name="header">
<h:outputText value="Time"/>
</f:facet>
<h:outputText value="#{item.time}"/>
</p:column>
<p:column style="text-align:center;">
<f:facet name="header">
<h:outputText value="Date"/>
</f:facet>
<h:outputText value="#{item.date}"/>
</p:column>
</p:dataTable>
</p:outputPanel>
</p:fieldset>
<p:droppable for="selectedMemos" tolerance="touch" activeStyleClass="ui-state-highlight" >
<p:ajax listener="#{myMemosController.onMemoDrop}" process="#this" update="dropArea, leftData"/>
</p:droppable>
</p:layoutUnit>
</h:form>
My method onMemoDrop:
public void onMemoDrop(DragDropEvent ddEvent)
{
String[] idTokens = ddEvent.getDragId().split(String.valueOf(UINamingContainer.getSeparatorChar(FacesContext.getCurrentInstance())));
int rowIndex = Integer.parseInt(idTokens[idTokens.length - 2]);
String name = idTokens[idTokens.length - 3];
MyMemos memo = null;
if (name.equals("leftData"))
{
items.setRowIndex(rowIndex);
memo = (MyMemos) items.getRowData();
dashboardController.create(1, memo.getName(), memo.getComments(), memo.getDate(), memo.getTime(), memo.getPriority(), memo.getPriorityname());
}
}
and the create method:
public String create(int id, String name, String comment, String date, String time, String priority, String priorityName)
{
try
{
System.out.println("I am in Create() method from DashboardController");
current = new Dashboard(id, name, comment, date, time, priority, priorityName);
getFacade().create(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/resources/Bundle").getString("DashboardCreated"));
return prepareCreate();
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/resources/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
May be a suggestion?
I think that this code is not working :
<p:ajax listener="#{myMemosController.onMemoDrop}" process="#this" update="dropArea, leftData"/>
, because this p:ajax cannot resolve the 'dropArea'. Ultimately, the component cannot be found and is not getting updated.
One solution to point to you datatable is set update as :
update=":#{p:component('centerData')}, :#{p:component('leftData')}"
Or maybe use widget vars
The problem was from my managed bean "DashboardController", when i removed #stateless and added an injection like: #ManagedBean(name = "dashboardController") and in MyMemosController i added: #ManagedProperty("value="#{dashboardController}""). Now my dataTable is correctly update.
After I save the components of a form I show it in a datatable. Interestingly if I don't refresh the page my datatable partially renders the values.
Here is the service class:
public EBSResponse uyeTeminatKaydet(UyeTeminat uyeTeminat, Kullanici sessionUser, String ipAdresi ){
Session session = null;
Transaction tx = null;
EBSException EE = new EBSException();
EBSResponse ER = new EBSResponse();
RequestContext context = RequestContext.getCurrentInstance();
context.addCallbackParam("saved", false);
Date tarih = new Date();
if (uyeTeminat.getTarih()!= null)
tarih = uyeTeminat.getTarih();
else
uyeTeminat.setTarih(tarih);
uyeTeminat.setDurum(Boolean.TRUE);
BigDecimal teminatDegeri=null;
try {
session = HibernateUtil.getSessionFactory().openSession();
tx = session.beginTransaction();
teminatDegeri=calculateTeminatDegeri(uyeTeminat,tarih, session);
uyeTeminat.setTeminatDegeri(teminatDegeri);
session.save(uyeTeminat);
session.flush();
tx.commit();
List<UyeTeminat> uyeTeminatList = getTumUyeTeminatlari(session);
ER.setStringValue("teminatIslemleriBean.uyeTeminatKaydet.info1");
ER.setObjectValue(uyeTeminatList);
context.addCallbackParam("saved", true);
} catch (Exception ex) {
ex.printStackTrace();
if (tx != null) {
tx.rollback();
}
EE.setHataTipi(EBSConstants.HATA_TIPI_ERROR);
EE.setHataMesaji("teminatIslemleriBean.uyeTeminatKaydet.err1");
ER.setExceptionValue(EE);
} finally {
if (session != null && session.isOpen()) {
session.close();
}
}
return ER;
}
Here is the backing bean:
public void uyeTeminatKaydet() {
EBSResponse er = uyeServisi.uyeTeminatKaydet(uyeTeminat, sessionUser, ipAdresi);
if (er.getExceptionValue() == null) {
this.uyeTeminatList = (List<UyeTeminat>) er.getObjectValue();
FacesUtil.addMessage(FacesMessage.SEVERITY_INFO, LocaleBean.lang.getString(er.getStringValue()));
uyeTeminat = new UyeTeminat();
} else {
FacesUtil.addMessage(EBSUtils.getHataTipi(er.getExceptionValue().getHataTipi()), LocaleBean.lang.getString(er.getExceptionValue().getHataMesaji()));
}
}
Does anyone have any idea about this?
EDIT:
xhtml:
<h:outputText value="#{lang.teminatTuruAdi}: *" />
<h:selectOneMenu id="TeminatTuru" required="true" converter="teminatTurConverter" value="#{teminatTanimlamaIslemleriBean.teminat.teminatTur}">
<f:selectItem itemLabel="#{lang.seciniz}" />
<f:selectItems value="#{teminatTanimlamaIslemleriBean.teminatTurleriMenu}" />
</h:selectOneMenu>
<h:outputText value="#{lang.teminatKodu}: *" />
<p:inputText size="50" maxlength="50" required="true" value="#{teminatTanimlamaIslemleriBean.teminat.teminatKodu}"/>
<h:outputText value="#{lang.teminatAdi}: *" />
<p:inputText size="50" maxlength="50" required="true" value="#{teminatTanimlamaIslemleriBean.teminat.teminatAdi}"/>
<h:outputText value="#{lang.birimFiyat}: *" />
<p:inputText id="BirimFiyat" size="30" maxlength="50" value="#{teminatTanimlamaIslemleriBean.teminat.birimFiyati}"
style="text-align:right" onkeypress="return isNumberAndComma(event); isMaxLength(this, 14, event);" onkeyup="this.value=numberFormat(this.value,6);">
<f:converter converterId="ondalikAltiHaneConverter" />
</p:inputText>
<h:outputText value="#{lang.fiyatTipi}: *" />
<h:selectOneMenu id="FiyatTipi" required="true" value="#{teminatTanimlamaIslemleriBean.teminat.fiyatTuru}">
<f:selectItem itemLabel="#{lang.seciniz}" />
<f:selectItems value="#{genelBilgiBean.fiyatTipiListesi}" />
</h:selectOneMenu>
</h:panelGrid>
<br/>
<p:commandButton value="#{lang.kaydetButton}" onclick="confirmationKaydet.show()"/>
<br/><br/>
<p:dialog showEffect="explode" hideEffect="explode" resizable="false"
header="#{lang.uyari}" widgetVar="confirmationKaydet" appendToBody="true" modal="true">
<h:outputText value="#{lang.kayitOnayMesaji}"/>
<br/><br/>
<p:commandButton value="#{lang.evetButton}" actionListener="#{teminatTanimlamaIslemleriBean.teminatKaydet}"
update="sysMsg, dTable"
process="mf:formPanel"
onstart="waitDialog.show(),confirmationKaydet.hide()"
oncomplete="waitDialog.hide();handleComplete(xhr, status, args);" />
<p:commandButton value="#{lang.hayirButton}" onclick="confirmationKaydet.hide()" type="button" />
</p:dialog>
</p:panel>
<p:panel id="dtPanel" style="width: 80%">
<p:dataTable style="width: 100%;" id="dTable" var="tt" value="#{teminatTanimlamaIslemleriBean.teminatList}" paginator="true" rows="20"
selection="#{teminatTanimlamaIslemleriBean.selectedTeminat}" selectionMode="single" emptyMessage="#{lang.kayitBulunamadi}"
onRowSelectUpdate="mf:tabcontent" onRowSelectComplete="tvl();">
<f:facet name="header">
#{lang.menu_teminat}
</f:facet>
<p:column filterBy="#{tt.teminatId}" sortBy="#{tt.teminatId}">
<f:facet name="header">
<h:outputText value="#{lang.teminatId}" />
</f:facet>
<h:outputText value="#{tt.teminatId}" />
</p:column>
<p:column filterBy="#{tt.teminatTur.teminatTuruAdi}" sortBy="#{tt.teminatTur.teminatTuruAdi}">
<f:facet name="header">
<h:outputText value="#{lang.teminatTuruAdi}" />
</f:facet>
<h:outputText value="#{tt.teminatTur.teminatTuruAdi}" />
</p:column>
<p:column filterBy="#{tt.teminatKodu}" sortBy="#{tt.teminatKodu}">
<f:facet name="header">
<h:outputText value="#{lang.teminatKodu}" />
</f:facet>
<h:outputText value="#{tt.teminatKodu}" />
</p:column>
<p:column filterBy="#{tt.teminatAdi}" sortBy="#{tt.teminatAdi}">
<f:facet name="header">
<h:outputText value="#{lang.teminatAdi}" />
</f:facet>
<h:outputText value="#{tt.teminatAdi}" />
</p:column>
<p:column filterBy="#{tt.birimFiyati}" sortBy="#{tt.birimFiyati}" style="text-align:right">
<f:facet name="header">
<h:outputText value="#{lang.birimFiyat}" />
</f:facet>
<h:outputText value="#{tt.birimFiyati}" style="text-align:right">
<f:converter converterId="ondalikAltiHaneConverter" />
</h:outputText>
</p:column>
<p:column filterBy="#{tt.fiyatTuru}" sortBy="#{tt.fiyatTuru}">
<f:facet name="header">
<h:outputText value="#{lang.fiyatTipi}" />
</f:facet>
<h:outputText value="#{tt.fiyatTuru}" />
</p:column>
<p:column filterBy="#{tt.durum == true ? lang.kullanimda : lang.kullanimDisi}" sortBy="#{tt.durum == true ? lang.kullanimda : lang.kullanimDisi}">
<f:facet name="header">
<h:outputText value="#{lang.durum}" />
</f:facet>
<h:outputText value="#{tt.durum == true ? lang.kullanimda : lang.kullanimDisi}" />
</p:column>
<f:facet name="footer">
#{lang.toplamKayit}: #{fn:length(teminatTanimlamaIslemleriBean.teminatList)}
</f:facet>
</p:dataTable>
</p:panel>
there were two problems:
corresponding converters in Uye and Teminat did not include the necessary fields.
the correct xhtml for the same fields should have been:
d
<h:selectOneMenu id="uyeAdi" required="true" converter="uyeConverter" value="#{teminatTanimlamaIslemleriBean.uyeTeminat.uye}">
<h:selectOneMenu id="teminatTuruAdi" required="true" converter="teminatTurConverter" value="#{teminatTanimlamaIslemleriBean.uyeTeminat.teminat.teminatTur}">
I have an entity with the following named query:
#NamedQuery(name = "findAllGarbage", query = "SELECT g.filename, g.description, g.uploadDate FROM Garbage g;")
The problem is that i want to pass that result to a dataTable to render, and i recieve NumberFormatException. I dont understand why because there are no numbers anywhere.
This is how the rest of the program looks like:
-The EJB that executes the query
#Stateless(name = "ejbs/SearchEJB")
public class SearchEJB implements ISearchEJB {
#PersistenceContext
private EntityManager em;
public List<Garbage> findAllGarbage() {
Query query = em.createNamedQuery("findAllGarbage");
List<Garbage> tmpGarbage = query.getResultList();
return tmpGarbage;
}
-The part of the JSF that displays the tableData:
<p:dataTable var="garbage" value="#{resultsController.allGarbage}" paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column>
<f:facet name="header">
<h:outputText value="Filename" />
</f:facet>
<h:outputText value="#{garbage.filename}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Description" />
</f:facet>
<h:outputText value="#{garbage.description}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Upload date" />
</f:facet>
<h:outputText value="#{garbage.uploadDate}" />
</p:column>
</p:dataTable>
-The managed bean that interacts with the JSF page:
#ManagedBean
#RequestScoped
public class ResultsController {
#EJB
private ISearchEJB searchEJB;
private Garbage garbage;
public List<Garbage> getAllGarbage() {
return searchEJB.findAllGarbage();
}
public Garbage getGarbage() {
return garbage;
}
public void setGarbage(Garbage garbage) {
this.garbage = garbage;
}
The error says:
WARNING: StandardWrapperValve[Faces Servlet]: PWC1406: Servlet.service() for servlet Faces Servlet threw exception
java.lang.NumberFormatException: For input string: "filename"
I dont understand what is wrong with the file name.
------------------------------------UPDATE------------------------------------
I changed the JSF to this, and now i dont see the error. I see tha table data but empty:
<p:dataTable var="garbage" value="#{resultsController.allGarbage}" paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column>
<f:facet name="header">
<h:outputText value="Filename" />
</f:facet>
<h:outputText value="#{garbage[4]}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Description" />
</f:facet>
<h:outputText value="#{garbage[3]}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Upload date" />
</f:facet>
<h:outputText value="#{garbage[6]}" />
</p:column>
</p:dataTable>
The problem is caused by the fact that a query such as
SELECT g.filename, g.description, g.uploadDate FROM Garbage
returns an Object[] with filename, description and uploadDate as its elements.
If you want to access them as object properties (as you do in JSF), you need to query for the full object instead:
SELECT g FROM Garbage g
I've never had such a problem getting the simplest stuff to work in Java EE 6. I have an extremely basic project. I've tried debugging. Etc. I don't know what to do.
Here is my bean.
#Named(value = "contactsBean")
#SessionScoped
public class ContactsBean implements Serializable {
#EJB
ContactsFacade contactsEJB;
private List<Contacts> contacts = new ArrayList<Contacts>();
public ContactsBean() {
}
public String next() {
contacts = contactsEJB.findAll();
return "index";
}
/**
* #return the contacts
*/
public List<Contacts> getContacts() {
return contacts;
}
/**
* #param contacts the contacts to set
*/
public void setContacts(List<Contacts> contacts) {
this.contacts = contacts;
}
}
Ok. Pretty basic.
Here is my xhtml page.
<ui:define name="content">
<h:form>
<h:dataTable value="#{contactsBean.contacts}" var="contacts">
<h:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
<h:outputText value="#{contacts.name}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Street"/>
</f:facet>
<h:outputText value="#{contacts.street}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="City"/>
</f:facet>
<h:outputText value="#{contacts.city}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="State"/>
</f:facet>
<h:outputText value="#{contacts.state}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Zip"/>
</f:facet>
<h:outputText value="#{contacts.zip}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Country"/>
</f:facet>
<h:outputText value="#{contacts.country}"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Sent?"/>
</f:facet>
<h:selectBooleanCheckbox value="#{contacts.sent}" />
</h:column>
</h:dataTable>
<h:commandButton value="next >" action="#{contactsBean.next}"/>
</h:form>
</ui:define>
Ok when I hit the next button my list should populate. At least it always did in Java EE 5 stuff. I'm not sure what I'm doing wrong. I was trying to do a simple paginator but even that wouldn't work. The model never gets updated.
What in the world is going on. I tried it without an EJB and it didn't work either.
I found out the reason.
There are to different packages with SessionScoped annotations.
javax.enterprise.context.SessionScoped and javax.faces.context.SessionScoped.
Since I'm using #Named(value = "contactsBean") injection I need to use javax.enterprise. #ManagedBean(name = "contactsBean") goes with javax.faces.context.