Parameter values concatenated into dynamic columns in Primefaces? - java

I'm generating is so dynamic columns in a datatable in JSF with Primefaces 4. It turns out that the only way to generate it through two lists where one has data grid and other attributes of the bean.
So far it has happened only handle this.
<p:dataTable id="listCust" var="cust" value="#{mantClienteMB.customers}" rows="5"
rowIndexVar="rowIndex" paginatorPosition="top" resizableColumns="true" emptyMessage="">
<p:column headerText="N°" width="auto">
<h:outputText value="#{rowIndex+1}" />
</p:column>
<c:forEach items="#{mantClienteMB.columnCustomer}" var="colum">
<p:column headerText="#{colum.descripcion}" width="auto">
<ui:fragment rendered="#{colum.entidadBean == 'code'}">
<h:outputText value="#{cust.code}" />
</ui:fragment>
<ui:fragment rendered="#{colum.entidadBean == 'name'}">
<h:outputText value="#{cust.name}" />
</ui:fragment>
<ui:fragment rendered="#{colum.entidadBean == 'comercialName'}">
<h:outputText value="#{cust.comercialName}" />
</ui:fragment>
<ui:fragment rendered="#{colum.entidadBean == 'isActive'}">
<h:outputText value="#{cust.isActive}" />
</ui:fragment>
</p:column>
</c:forEach>
</p:dataTable>
In code java:
private List<BaCustomer> customers;
private List<ValidColumnKey> columnCustomer;
this.setCustomers(new ArrayList<BaCustomer>());
this.getCustomers().add(new BaCustomer("P0001", "PASSARELA S.A.C.", "PASSARELA", true));
this.getCustomers().add(new BaCustomer("P0002", "DARNOX S.A.C.", "DONOFRIO", true));
this.setColumnCustomer(new ArrayList<ValidColumnKey>());
this.getColumnCustomer().add(new ValidColumnKey(1, "Codigo", "code"));
this.getColumnCustomer().add(new ValidColumnKey(2, "Nombre", "name"));
this.getColumnCustomer().add(new ValidColumnKey(3, "Nombre Comercial", "comercialName"));
this.getColumnCustomer().add(new ValidColumnKey(4, "Estado", "isActive"));
But it occurred to me that if I could concatenate the value of the alias in the main list with the names of the attributes bean I get from the second list should work, but the problem of contenacion is that only prints the string, but not the result chain.
<p:dataTable id="listCust" var="cust" value="#{mantClienteMB.customers}" rows="5"
rowIndexVar="rowIndex" paginatorPosition="top" resizableColumns="true" emptyMessage="">
<p:column headerText="N°" width="auto">
<h:outputText value="#{rowIndex+1}" />
</p:column>
<c:forEach items="#{mantClienteMB.columnCustomer}" var="colum">
<p:column headerText="#{colum.descripcion}" width="auto">
<ui:param name="myVar" value="cust.#{colum.entidadBean}" />
<h:outputText value="#{myVar}" />
</p:column>
</c:forEach>
</p:dataTable>
Anyone have an idea how to print the string value and not just the string as description.
Image:
http://s2.subirimagenes.com/otros/previo/thump_8745153listcustomers.jpg

Just use bracket-writing
#{cust[colum.entidadBean]}
Hope it helps...

Related

Primefaces In cell editing data table event.getNewValue() sends the old value to the bean

I am trying to use the feature of prime faces which allows user to edit the cell data in the table itself.I have followed this link to achieve it:
Primefaces showcase
When I say edit a cell in the table, new values which are entered are not sent to the bean.It still shows the old values only.
My code JSF:
<h:form id="testform">
<p:growl id="messages" showDetail="true" />
<p:outputPanel id="testContainer" deferred="true">
<p:remoteCommand name="oncompleteCellEdit" update="cars messages" />
<p:dataTable id="cars" var="car" value="#{articlesbean.LMatpilotaccess1}" editable="true" editMode="cell" widgetVar="carsTable" update=":cars">
<f:facet name="header">
Matériel du pilotage et accessoires
</f:facet>
<p:ajax event="cellEdit" listener="#{articlesbean.onCellEdit}" oncomplete="oncompleteCellEdit()" update=":testform:messages" />
<p:column headerText="Serie" style="width:25%">
<p:cellEditor >
<f:facet name="output"><h:outputText value="#{car.serie}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput16" value="#{car.serie}" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Cap" style="width:25%">
<p:cellEditor >
<f:facet name="output"><h:outputText value="#{car.cap}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput15" value="#{car.cap}" style="width:96%"/></f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</p:outputPanel>
</h:form>
My code bean
#ManagedBean(name="articlesbean")
#ViewScoped
public class ArticlesBean implements Serializable{
#Inject
private ArticlesDAO articleDAO;
private Matpilotaccess1 matpilotaccess1;
public void onCellEdit(CellEditEvent event) {
Object oldValue = event.getOldValue();
Object newValue = event.getNewValue();
System.out.println("/////"+(event.getNewValue());
System.out.println("/////"+(event.getOldValue());
FacesContext context = FacesContext.getCurrentInstance();
Matpilotaccess1 mpltiacc = context.getApplication().evaluateExpressionGet(context, "#{mpltiacc}", Matpilotaccess1.class);
articleDAO.Updatetable(mpltiacc);
}
/////////Getters and Setters
}
and as result of
System.out.println("/////"+(event.getNewValue());
System.out.println("/////"+(event.getOldValue());
i got in both case the old value!!!
Could anyone let me know how I can get the new values???I am using Jboss 7 and primefaces4 Thanks
You need to annotate your bean with #SessionScoped annotation.

Why i can't refresh my dataTable, after adding data?

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.

Forward variable on the next page

I have a Users table. Added, view and delete work. But I have problem to edit.
My list page:
<h:form id="form">
<p:dataTable styleClass="table" value="#{userMB.allAdmins}" var="admin" paginator="true" rows="15" rowKey="#{admin.id}" selection="#{userMB.user}" selectionMode="single">
<f:facet name="header">
Lista administratorów
</f:facet>
<p:column headerText="#{msg.firstName}">
<h:outputText value="#{admin.firstName}" />
</p:column>
<p:column headerText="#{msg.lastName}">
<h:outputText value="#{admin.lastName}" />
</p:column>
<p:column headerText="#{msg.personalId}">
<h:outputText value="#{admin.personalId}" />
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="#{msg.info}" icon="ui-icon-search"
update=":form:display" oncomplete="userDialog.show()"/>
<p:commandButton action="#{userMB.createStart()}" value="#{msg.add}" icon="ui-icon-plus" />
<p:commandButton action="#{userMB.editStart()}" value="#{msg.edit}" >
<f:setPropertyActionListener target="#{userMB.user}" value="#{userMB.user}" />
</p:commandButton>
<p:commandButton action="#{userMB.deleteUser()}" value="#{msg.delete}" icon="ui-icon-close"/>
</f:facet>
</p:dataTable>
<p:dialog id="dialog" header="Administrator" widgetVar="userDialog" resizable="false"
width="300" showEffect="clip" hideEffect="explode">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<p:graphicImage value="./../../images/person4.png" width="150" height="150"/>
</f:facet>
<h:outputText value="#{msg.firstName}" />
<h:outputText value="#{userMB.user.firstName}" />
<h:outputText value="#{msg.lastName}" />
<h:outputText value="#{userMB.user.lastName}" />
<h:outputText value="#{msg.personalId}" />
<h:outputText value="#{userMB.user.personalId}" />
</h:panelGrid>
</p:dialog>
</h:form>
I want to send the selected user on the next page:
I use aciontListener:
<p:commandButton action="#{userMB.editStart()}" value="#{msg.edit}" >
<f:setPropertyActionListener target="#{userMB.user}" value="#{userMB.user}" />
</p:commandButton>
My edit page where I want to send user:
<h:form>
<div id="userPanel">
<h:inputHidden value="#{userMB.user}" />
<p:panel id="panelUser" header="Edytuj administratora" >
<div id="panelImage">
<img src="./../../images/person4.png" alt="person" width="150px" height="130px"/>
</div>
<h:panelGrid columns="3">
<p:outputLabel for="firstName" value="#{msg.firstName}"></p:outputLabel>
<p:inputText id="firstName" value="#{userMB.user.firstName}" label="#{msg.firstName}" required="true">
<f:validator validatorId="nameValidator" />
<p:ajax update="msgFristName" event="keyup" />
</p:inputText>
<p:message for="firstName" id="msgFristName"/>
<p:outputLabel for="lastName" value="#{msg.lastName}"></p:outputLabel>
<p:inputText id="lastName" value="#{userMB.user.lastName}" label="#{msg.lastName}" required="true">
<f:validator validatorId="nameValidator" />
<p:ajax update="msgLastName" event="keyup" />
</p:inputText>
<p:message for="lastName" id="msgLastName"/>
<p:outputLabel for="personalId" value="#{msg.personalId}"></p:outputLabel>
<p:inputText id="personalId" value="#{userMB.user.personalId}" label="#{msg.personalId}" required="true">
<f:validator validatorId="personalIdValidator" />
<p:ajax update="msgPersonalId" event="keyup" />
</p:inputText>
<p:message for="personalId" id="msgPersonalId"/>
<p:outputLabel for="password" value="#{msg.password}"></p:outputLabel>
</p:panel>
</div>
</h:form>
I added: <h:inputHidden value="#{userMB.user}" /> but I do not see data user, only empty field. How do I send this person? I used once this method in other project, a little different without primefaces and it worked. Why now does not work?
Method editStart:
public String editStart() {
return "editStart";
}
faces-config:
<navigation-case>
<from-outcome>editStart</from-outcome>
<to-view-id>/protected/admin/adminEdit.xhtml</to-view-id>
<redirect/>
</navigation-case>
When I'm on the side adminEdit I edited the pool and do editUser method:
public String editUser() {
FacesContext context = FacesContext.getCurrentInstance();
Map requestParameterMap = (Map) context.getExternalContext().getRequestParameterMap();
try {
String userRole = requestParameterMap.get("userRole").toString();
String active = requestParameterMap.get("active").toString();
Boolean act = Boolean.parseBoolean(active);
user.setRole(userRole);
user.setActive(act);
userDao.update(user);
} catch (EJBException e) {
sendErrorMessageToUser("Edit error");
return null;
}
sendInfoMessageToUser("Account edited");
return user.getRole() + "List";
}
My method editStart use only for navigation.
You can either consider Przemek's answer or use one of the 4 ways of passing a parameter to a backing bean.
1. Method expression
2. f:param
3. f:atribute
4. f:setPropertyActionListener
For very well explained full explanation refer to this
It has easy to understand examples. Take a look and pick what fits your needs.
Or simply:
In the actual managed bean...
public String navigationButtonListener(User parameter) {
FacesContext.getCurrentInstance().getExternalContext().getRequestMap()
.put("parameterAttribute", parameter);
return "my-destination-page";
}
In the destination managed bean...
#PostConstruct
public void init(){
myAttribute= (User) FacesContext.getCurrentInstance()
.getExternalContext().getRequestMap().get("parameterAttribute");
}
Good Luck!
You can pass your userid through the session.
Add a parameter to your commandLink
<p:commandButton action="#{userMB.editStart()}" value="#{msg.edit}>
<f:param name="userId" value="#{userMB.user.id}" />
</p:commandButton>
In your backing bean do this
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest myRequest = (HttpServletRequest)context.getExternalContext().getRequest();
HttpSession mySession = myRequest.getSession();
Integer userId = Integer.parseInt(myRequest.getParameter("userId"));
After that you can reload the user you want to edit with the Id you got

Partially rendering datatable

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}">

Issue rendering JPQL custom query results into a JSF page

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

Categories

Resources