I've simply changed working JSF h:dataTable to p:dataTable, but it's empty. Without headers, one empty row. I've installed primefaces-3.0.M1.jar to my project.
UPDATE: if I remove binding, dataTable is working properly, but without advantages of HtmlDataTable...
UPDATE2: don't anybody knows how to bind rich:dataTable?
Part of code:
<p:dataTable
id="tableDetail"
value="#{myBdeCheck.dataListBde}"
binding="#{myBdeCheck.dataTable}"
var="bdeItem">
<p:column>
<f:facet name="header">
<h:outputText value="Select" />
</f:facet>
<h:selectBooleanCheckbox value="#{myBdeCheck.selectedRow}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Shift" />
</f:facet>
<h:outputText value="#{bdeItem.dayShift}"/>
</p:column>
<f:facet name="footer">
<h:commandButton id="btnAdd" action="#{myBdeCheck.add}"/>
</f:facet>
</p:dataTable>
Did I forgot something?
This can be caused by binding (as you suggested yourself). You have to bind p:dataTable to
org.primefaces.component.datatable.DataTable
instead of javax.faces.component.html.HtmlDataTable
Related
I am trying to export a view to xlsx using PrimeFaces extensions. I have a main table and an expandable row with 2 tables inside.
The exporter works fine for the first dataTable in the expandable row, but not for the other one. Any ideas?
<p:dataTable id="mainTable" var="mainObject" value="#{mainBean.mainList}">
<p:column exportable="false" width="5%">
<p:rowToggler />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="main column A"/>
</f:facet>
<h:outputText value="#{mainObject.columnA}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="main column B"/>
</f:facet>
<h:outputText value="#{mainObject.columnB}" />
</p:column>
<p:rowExpansion>
<p:datTable id="relatedTableA" var="relatedA" value="#{mainObject.relatedA}">
<f:facet name="header">
<h:outputText value="Related A"/>
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Related A column A"/>
</f:facet>
<h:outputText value="#{relatedA.columnA}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Related A column B"/>
</f:facet>
<h:outputText value="#{relatedA.columnB}" />
</p:column>
</p:dataTable>
<p:datTable id="relatedTableB" var="relatedB" value="#{mainObject.relatedB}">
<f:facet name="header">
<h:outputText value="Related B"/>
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Related B column A"/>
</f:facet>
<h:outputText value="#{relatedB.columnA}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Related B column B"/>
</f:facet>
<h:outputText value="#{relatedB.columnB}" />
</p:column>
</p:dataTable>
</p:rowExpansion>
</p:dataTable>
<h:commandLink>
<p:graphicImage url="/resources/images/Excel32.png" width="32"/>
<pe:exporter type="xlsx" target="mainTable" fileName="fileExport" facetBackground="#AAFFBB" datasetPadding="4" />
</h:commandLink>
I followed this guide: https://www.primefaces.org/showcase-ext/sections/exporter/expandableTable.jsf
In my app, the view works perfect. I use the toggle and then it shows the 2 tables. The only problem is that it exports only one of the expandables.
Thanks for your time.
Seemes this is simply not supported.
In the exporter component source code when it comes to exporting the row expensions they have hard coded to consider the first child for each rowExpansion only:
if (rowExpansion.getChildren().get(0) instanceof DataTable) {
final DataTable childTable = (DataTable) rowExpansion.getChildren().get(0);
// ...
}
This is why you only get the first sub table in your output.
Using the customExporter feature you have the chance to extend the ExcelExporter and override the method exportCells which seemes responsible for your problem. Then change the behavior to do a loop on rowExpansion.getChildren() instead of just getting the first element.
General steps to configure a custom exporter from the linked site:
Step 1: Create a folder named META-INF under resouces folder.Below
META-INF folder create another folder called services.
Step 2: Creae a
file with the name "ExporterFactory" as a service(Fully binary name of
the service).
Here it should be org.primefaces.extensions.component.exporter.ExporterFactory.
Step 3:
Provide your own implementaions/providers of Exporter factory anywhere
in your project.
And copy the absolute path of custom exporter factory implementation in the ExporterFactory file
How to do : Copy the file content of DefaultExporterFactory and rename the file as CustomExporterFactory.Copy the absolute path
org.primefaces.extensions.showcase.util.CustomExporterFactory in
ExporterFactory file.
Step 4: Copy the exporter implementations and
add your own changes.And call these custom implementations(Ex
PDFCustomExporter,ExcelCustomExporter) instead built-in
implmentations(Ex PDFExporter,ExcelExporter)
Hi i am adding a textbox in a datatable where the user will input data in each row. I need help on how to save the data...because right now it's saving only the last row. Please see code below, can someone help on this? I think there should be some sort of array but i dont know if it is possible to store value in array using el expression. I implemented a nested datatable since i want the data to be side by side. If you have a better idea other than using datatable , I would be glad if you could share it and give proper instruction on how to proceed. ( but it should be side by side)
Thanks in advance
<p:dataTable id="dta" value="#{MyCarComponent.model}" var="cur" rows="15" >
<p:column>
<f:facet name="header">
<h:outputText value="Model:" />
</f:facet>
<h:outputText value="#{current.cptModel}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Type:" />
</f:facet>
<p:dataTable id="dta1" value="#{cur.type}" var="curType" rows="15" >
<p:column>
<h:outputText value="#{curType.cptType}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Origin:" />
</f:facet>
<h:form>
<p:dataTable id="dta3" value="#{curType.origins}" var="curOrigin" rows="15" >
<p:column>
<h:outputText value="#{curOrigin.origin}" />
</p:column>
<p:column>
<h:inputText
value="#{MyCarComponent.origindetails.country}"/>
</p:column>
</p:dataTable>
</h:form>
</p:column>
</p:dataTable>
</p:column>
<f:facet name="footer">
<p:commandButton image="save" ajax="false" value="Save" action=" #. {Mycar.saveMyCar(curOrigin.origin,MyCarComponent.origindetails)}" />
</f:facet>
You're currently binding the input field of all rows to one and same bean property. So when JSF processes the form submit in the same sequence as the component tree, the value of each input field will be set in this one and same property. Of course the property will end up being the one of the last row.
You just need to bind the value of the input field to the currently iterated row, the #{curOrigin}. E.g.
<h:inputText value="#{curOrigin.country}" />
Just create the property of there if it doesn't exist yet.
i have a datatable using the primefaces library, and while i have got all the functions working i have just one small issue, when i press the command link to remove the row, it works and the row gets removed but it does not automatically update the datatable to reflect this, ideally what i want is when the user presses the delete button it automatically updates the datatable to show this, how can i achieve this ?
here is the datatable
<p:dataTable id="UserTable"
widgetVar="usersTable"
value="#{userdetailsController.items}"
var="item"
emptyMessage="No details was found with given criteria">
<!--filteredValue="{userdetailsController.filteredUsers}" -->
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields: " />
<p:inputText id="globalFilter" onkeyup="usersTable.filter()" style="width:150px" />
</p:outputPanel>
</f:facet>
<p:column id="USERID" filterBy="id"
headerText="i.d."
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="#{bundle.ListUserdetailsTitle_id}"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</p:column>
<!--There are four different match modes, "startsWith"(default), "endsWith", "contains" and "exact"-->
<p:column id="USERNAME" filterBy="username"
headerText="username."
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="#{bundle.ListUserdetailsTitle_username}"/>
</f:facet>
<h:outputText value="#{item.username}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value=" "/>
</f:facet>
<p:commandLink action="#{userdetailsController.prepareView}" value="#{bundle.ListUserdetailsViewLink}"/>
<h:outputText value=" "/>
<div class="divider"/>
<p:commandLink action="#{userdetailsController.prepareEdit}" value="#{bundle.ListUserdetailsEditLink}"/>
<h:outputText value=" "/>
<div class="divider"/>
<p:commandLink action="#{userdetailsController.destroy}" value="#{bundle.ListUserdetailsDestroyLink}"/>
</p:column>
</p:dataTable>
You need to use the update attribute of the p:commandLink to tell PF you want to do the ajax request to obtain all data related to table UserTable like this:
<p:commandLink actionListener="#{userdetailsController.destroy}" value="#{bundle.ListUserdetailsDestroyLink}" ajax="true" update="UserTable"/>
Make sure to use actionListener as it is called before action atrib. A more detailed example is here
http://www.primefaces.org/showcase/ui/commandLink.jsf
Per the documentation, you need to make a call to Draw() after you remove a row.
var table = $('#example').DataTable();
$('#example tbody').on( 'click', 'img.icon-delete', function () {
table
.row( $(this).parents('tr') )
.remove()
.draw();
} );
I'm implementing a p:dataTable component, based on the Primefaces Showcase
The code is:
<p:dataTable
id="newDataTable"
editable="true"
editMode="cell"
var="item"
value="#{myBean.listNewDataTable}">
<p:ajax event="cellEdit" listener="#{myBean.newCellEditListener}" update="#this"/>
<p:column width="150" >
<p:cellEditor>
<f:facet name="output">
<h:inputText value="#{item.description}" readonly="true"/>
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{item.id}" style="width: 90%;">
<f:selectItems value="#{myBean.productsMap.entrySet()}" var="entry" itemValue="#{entry.key}" itemLabel="#{entry.value}" />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
-- More Data --
</p:dataTable>
And the backing bean method:
public void newCellEditListener(CellEditEvent event){
... Some work here ...
}
When the value on the editable cell is changed, the p:cellEditor works as expected.
The problem is:
When the value on the editable cell remains unchanged, the p:cellEditor shows the item.id when it should actually be showing the item.description.
Am I missing something obvious? Do I need additional configuration?
I have been googling for a tip or an answer, without success.
UPDATE
Same problem persists on the following code:
<p:column headerText="Money" width="150" >
<p:cellEditor >
<f:facet name="output">
<h:inputText value="#{actual.money}" readonly="true">
<f:convertNumber type="currency" />
</h:inputText>
</f:facet>
<f:facet name="input">
<h:inputText value="#{actual.money}">
</h:inputText>
</f:facet>
</p:cellEditor>
</p:column>
The value on the backing bean its the same for input and output, the difference between each other should be the 'currency' format.
UPDATE
As a workaround I used "p:commandButton" to update the Datatable.
<p:commandButton icon="ui-icon-refresh" update="newDataTable" value="Update" />
The app is running on:
Primefaces 3.5
Primefaces Extensions 0.7.1
Mojarra 2.1.22
Tomcat 7
Thanks for your help.
Kind regards.
Values in output and input should be the same. Try to fix that.
Found the issue reported and fixed on the Primefaces issue site: http://code.google.com/p/primefaces/issues/detail?id=6116
I downloaded the 4.0.RC1 and I do see the issue as being resolved as reported but there are some major differences in 4.0 versus 3.5 so I'm going to be waiting for 3.5.15 to be released.
I have a datatable in my primefaces application . The code for the frontend has
<!-- Start of customer datatable -->
<p:dataTable var="customer" value="#{customerBean.customers}" paginator="true" selection="#{customerBean.selectedCustomer}"
selectionMode="single" onRowSelectUpdate=":custList" onRowSelectComplete="custTab.show()" id="custList" widgetVar="custList" update=":custList">
<f:facet name="header">
List of Customers
<p:outputPanel>
<p:commandButton value="+" type="button" onclick="addCustDlg.show()"/>
</p:outputPanel>
</f:facet>
<p:column sortBy="#{customer.id}" filterBy="#{customer.id}" update=":custList">
<f:facet name="header">
<h:outputText value="ID"/>
</f:facet>
<h:outputText value="#{customer.id}"/>
</p:column>
<p:column sortBy="#{customer.name}" filterBy="#{customer.name}" headerText="NAME" filterMatchMode="contains" update=":custList">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{customer.name}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{customer.name}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="#{customer.description}" filterBy="#{customer.description}" headerText="DESCRIPTION">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{customer.description}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{customer.description}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="#{customer.signupDate}" filterBy="#{customer.signupDate}" headerText="SIGN UP DATE">
<f:facet name="output">
<h:outputText value="#{customer.signupDate}"/>
</f:facet>
</p:column>
<p:column sortBy="#{customer.validUntil}" filterBy="#{customer.validUntil}" headerText="EXPIRY DATE">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{customer.validUntil}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{customer.validUntil}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column sortBy="#{customer.status}" filterBy="#{customer.status}" headerText="STATUS">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{customer.status}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{customer.status}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="CREATION DATE" sortBy="#{customer.creationDate}" filterBy="#{customer.creationDate}">
<f:facet name="output">
<h:outputText value="#{customer.creationDate}"/>
</f:facet>
</p:column>
<p:column headerText="LAST UPDATE DATE" sortBy="#{customer.lastUpdateDate}" filterBy="#{customer.lastUpdateDate}">
<f:facet name="output">
<h:outputText value="#{customer.lastUpdateDate}"/>
</f:facet>
</p:column>
<p:column headerText="Options">
<p:rowEditor/>
</p:column>
</p:dataTable>
<!-- End of dataTable (customer datatable) -->
And the function for handling the rowEvent is specified in the bean as
public void custRowEdit(RowEditEvent event){
Customer cust = (Customer) event.getObject();
EntityManagerHelper.beginTransaction();
custDao.update(cust);
EntityManagerHelper.commit();
}
However , on an update event , when I am editing the cell in the table , I do not get the new updated value of the attribute .
Like in the image below , when I edit the status of the entry with ID 1 from 11 to 4 , in the function custRowEdit , when I try to get the customer object , I still get the status of the customer as 11 and not 4 .
Can anyone help me with understanding why the value of the cell is not being set ?
from Where You are invoking custRowEdit(RowEditEvent event) method. I have not any related thing in your code.
In order to make your listener invoke add below attribute in your datatable declaration.
rowEditListener="#{customerBean.listenerInBackingBean}"
<p:dataTable var="customer" value="#{customerBean.customers}" paginator="true" selection="#{customerBean.selectedCustomer}"
selectionMode="single" onRowSelectUpdate=":custList" onRowSelectComplete="custTab.show()" id="custList" widgetVar="custList" update=":custList">
<f:facet name="header"
rowEditListener="#{customerBean.cutRowEvent}"
>
Check the implementation of customerBean.customers. I reloaded the content from the database every time the method got called. Wrong. This should happen in the constructor instead. Now everything works fine. Thought it was a JavaScript error ...
Thanks this helped me.
May I add that instead of loading the list from a query in the constructor, if one has a #SessionScoped managed bean one can instead use a reset() method to reset lists to null and then lazily populate the lists from the query. The reset can then be called on page load using an f:event:
<f:view>
<f:metadata>
<f:event type="preRenderView" listener="#{sessionScopedBean.reset}"/>
</f:metadata>
</f:view>
I encountered a similar situation that was resolved by removing the update="" tag from the dataTable. The table's default behavior is to update the row, which evidently, in my case, was not occurring.
You are missin the p:ajax event to trigger the method, function or whatever you wanna do after the cell editing
it's something like
<p:ajax event="cellEdit" listener="#{mBean.onCellEdit}" update="elementX" />