PrimeFaces DataExporter to XLS for multiple tables - jsf

Am trying to Export XLS format from multiple tables. I have browsed and used some code, But its not working. Using primefaces extensions code is there but complete code is not there it seems in this
link.
I need solution for this.
Code i have used :
Tbl1, Tbl2, Tbl3 are table widgetVar's.
<p:commandLink id="xls" ajax="false" >
<p:graphicImage value="/images/excel.png" />
<pe:exporter type="xlsx" target="Tbl1, Tbl2, Tbl3" fileName="tables"/>
</p:commandLink>

You should not address them by widgetVar. From the PrimeFaces Extensions Exporter (emphasis mine):
Here we can export multiple tables by providing multiple datatable server ids with the delimiter as "comma"(or ",").

I work with primefaces 6.2 and this works for me (I’m not sure about other versions) without use primefaces extension
<p:dataTable id="tbl1" value="#{ManagedBean.listValues}" var="vt">
<p:column headerText="LabelPrint">
<h:outputText value="#{vt.id}"/>
</p:column>
</p:dataTable>
<p:dataTable id="tbl2" value="#{ManagedBean.otherList}" var="vt2">
<p:column headerText="Name Field Print">
<h:outputText value="#{vt2.name}"/>
</p:column>
</p:dataTable>
<h:commandLink>
<p:graphicImage url="#{resource['/images/icons/table-xls.png']}"/>
<p:dataExporter type="xls" target="tbl1, tbl2" fileName="My Data" pageOnly="true" />
</h:commandLink>
You separate your "id" of tables for export with (,) in attribute target of p:dataexporter object.

Related

p:pickList ignores attributes of <p:column>

I am currently developing an application where the user can use a picklist to make certain associations.
I would like to display the object's attributes in different columns inside the picklist, for example the object car would display its id, year and color. However, the headerText of the column is not working. The column only displays the data but PrimeFaces seems to ignore the attribute headerText among others like sortBy. Is there any workaround? What am I doing wrong? p:column seems to work fine on a DataTable but not on a PickList and I really need to use a PickList or at least something with very similar functionalities.
Below is my code:
<p:pickList id="pickListAssociacao" value="#{associacaoPickListView.carsPickListView}" var="car" itemLabel="#{car.brand}" itemValue="#{car}">
<p:column headerText="Header1">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Header2" sortBy="#{car.year}">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Header3">
<h:outputText value="#{car.year}" />
</p:column>
</p:pickList>
Thanks for your time.

Update p:datatable and retain the rowexpansion status

I have datatable with rowexpansion that have another datatable inside it.
The structure like below:
<p:dataTable id="machine-table" value=#{machinePage.machines} var="machine" styleClass="machine-table">
<p:column style="width:16px">
<p:rowToggler rendered="#{machine.projectsInMachine.size() > 0}" />
</p:column>
some other machine column here...
<p:rowExpansion >
<p:dataTable value="#{machine.projectsInMachine}" var="project" styleClass="project-subtable" >
some project column here
</p:dataTable>
</p:rowExpansion>
Then I have a pull that will retrieve the machines and the projects data every couple minute, Is there any way that I can update it and retain the current expansion status? Because currently it will always close all the expansion (I update the entire table using poll below).
<p:poll widgetVar="machinesPoll"
interval="60" listener="#{machinePage.prepare()}"
async="true" global="false"
autoStart="true" process="#this"
update="machine-table" partialSubmit="true"
ignoreAutoUpdate="true" />
I can't find any reference regarding the expansion status that I can save in bean. I use: primefaces 6.0 , JSF 2.2.13

Dynamically adding components in multiple columns & legend creation [duplicate]

I'm working on dashboard application where I have to retrieve a set of records and display in dynamic tables boxes. Page frame length is fixed. now of columns and rows can be initialized. It should look like this sample:
Currently I'm using data table to display but it prints all the data in one column. How would I change my code to above pattern?
<o:dataTable id="tabBlSearch" var="item"
onkeyup="handleLeftRightArrowOnDataTable('frmDashBoard:tabBlSearch')"
value="#{bLDashBoardAction.listBondLoc}">
<o:column style="width: 20px;">
<h:outputText value="#{item.awb}" />
</o:column>
</o:dataTable>
You can achieve this with standard JSF components using a <h:panelGrid> wherein <c:forEach> is been used to generate the cells during the view build time. The <ui:repeat> won't work as that runs during view render time.
<h:panelGrid columns="5">
<c:forEach items="#{bean.items}" var="item">
<h:panelGroup>
<h:outputText value="#{item.value}" />
</h:panelGroup>
</c:forEach>
</h:panelGrid>
As to component libraries, I don't see anything in OpenFaces' showcase, but PrimeFaces has a <p:dataGrid> for exactly this purpose, even with pagination support.
<p:dataGrid columns="5" value="#{bean.items}" var="item">
<p:column>
<h:outputText value="#{item.value}" />
</p:column>
</p:dataGrid>

MouseOver-Window in Primefaces Datatable

I have a Primefaces Datatable and each column filled with a OutputLabel. When the String in this label has to many characters, the text is not visible.
I'm looking for a way, to show a MouseOver-window or hint to show the full text. What would be the most painless way? Thanks in advance.
You can Use Primeface Tooltip component.
<p:tooltip value="<CONTENT_OF_TOOLTIP>" for="<COMPONENT_ID_ON_WHICH_TOOLTIP_WILL_APPEAR>" />
Even though the IDs generated in Primefaces Datable inner components are different over iteration of List, if you put p:tooltip also in table as in below example, primefaces will also generated dynamic IDs to p:tooltip component also.
Example:
<p:dataTable value="#{heroMBean.herosList}" var="h">
<p:column headerText="Name">
<h:outputText id="hname" value="#{h.name}"/>
<p:tooltip for="hname" value="#{h.name}"></p:tooltip>
</p:column>
<p:column headerText="Universe">
<h:outputText id="huniverse" value="#{h.universe}"/>
</p:column>
</p:dataTable>

Is there any way to update PrimeFaces data table without updating the table headers?

This is a clumsy question!!! :)
Can this be made possible somehow? Can <p:dataTable> (whatever lazily loaded or otherwise) be updated without updating its headers (The contents (rows) inside the table along with the footer should be updated without updating the table headers)?
Updating of <p:dataTable> may be triggered by any UICommand like <p:commandButton>, <p:commandLink> and alike.
Something like this can be visualized, when we edit/update rows using <p:cellEditor> in conjunction with <p:rowEditor/> in <p:dataTable> (not sure about single cell editing).
<p:dataTable id="dataTable" var="row" value="#{bean}" ...>
<p:column headerText="Header 1" sortBy="#{row.property1}" filterBy="#{row.property1}">
....
</p:column>
<p:column>
<!--They may be our own headers-->
<f:facet name="header">
Header 2
...
</f:facet>
....
</p:column>
...
</p:dataTable>
Easiest way is to use PrimeFaces Selectors (PFS) for this. This only requires the desired cell content being wrapped in another component with an ID and a style class — so that jQuery can find and collect them.
E.g.
<p:dataTable ...>
<p:column>
<f:facet name="header">...</f:facet>
<h:panelGroup id="col1" styleClass="cell">...</h:panelGroup>
</p:column>
<p:column>
<f:facet name="header">...</f:facet>
<h:panelGroup id="col2" styleClass="cell">...</h:panelGroup>
</p:column>
<p:column>
<f:facet name="header">...</f:facet>
<h:panelGroup id="col3" styleClass="cell">...</h:panelGroup>
</p:column>
...
</p:dataTable>
<p:commandButton value="update" update="#(.cell)" />
That wrapping is clumsy, yes, but that's best you can get without homebrewing a custom renderer. You can always create a <my:column> tagfile to reduce the boilerplate.
See also:
How do PrimeFaces Selectors as in update="#(.myClass)" work?

Resources