The data in the following picture is dynamic & that is not looking good actually.
I want to fix the width for these columns.
<p:row styleClass="ui-panelgrid-cell" rowspan="2">
<p:column>
<div style="overflow: auto; width: 100%;">
<p:dataTable var="tPreferences"
value="#{userPreferences.preferences}"
emptyMessage="No Questions Found." id="pTable" styleClass="borderless">
<p:column headerText="PREFERENCES">
<h:outputText id="sName" styleClass="cellLabelMand"
value="#{tPreferences.shortText}" />
<h:outputText value="<br/><br/>" escape="false" />
<h:selectManyCheckbox id="grid"
value="#{tPreferences.preferencesSelectedItem}"
layout="grid" columns="1">
<f:selectItems value="#{tPreferences.catList}" var="pref" />
</h:selectManyCheckbox>
</p:column>
</p:dataTable>
</div>
</p:column>
</p:row>
Related
My problems is that when I click in the button to export data table, It exports only columns headers, my excel file is generated with none rows.
<h:form>
<p:dataTable id="cteTable" var="cte"
emptyMessage="Nenhum Registro Localizado"
reflow="true" value="#{extratorBean.ctes}" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {Exporters}"
style="margin-top: 10px" paginator="true" rows="100" scrollable="true" scrollWidth="1024px">
<f:facet name="{Exporters}">
<h:commandLink>
<p:graphicImage name="images/excel.png" width="24" library="samsung" />
<p:dataExporter type="xls" target="cteTable" fileName="cte-s" />
</h:commandLink>
</f:facet>
<p:column headerText="CNPJ Emissor" width="150" style="text-align: center">
<h:outputText value="#{cte.EMIT_CNPJ}"/>
</p:column>
<p:column headerText="Serie" width="60" style="text-align: center">
<h:outputText value="#{cte.IDE_SERIE}"/>
</p:column>
<p:column headerText="N° CT-e" width="90" style="text-align: center">
<h:outputText value="#{cte.IDE_NCT}"/>
</p:column>
<p:column headerText="Dt. Emissão" width="150" style="text-align: center">
<h:outputText value="#{cte.IDE_DHEMI}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column headerText="Total Frete" width="80" style="text-align: center">
<h:outputText value="#{cte.VPREST_VTPREST}">
<f:convertNumber type="currency" />
</h:outputText>
</p:column>
<p:column headerText="ICMS" width="80" style="text-align: center">
<h:outputText value="#{cte.ICMS_VICMS}">
<f:convertNumber type="currency" />
</h:outputText>
</p:column>
<p:column headerText="% ICMS" width="80" style="text-align: center">
<h:outputText value="#{cte.ICMS_PICMS}">
<f:convertNumber minFractionDigits="2" />
</h:outputText>
</p:column>
<p:column headerText="Nat. Op." width="350" style="text-align: center">
<h:outputText value="#{cte.IDE_NATOP}"/>
</p:column>
<p:column headerText="CNPJ Tomador" width="150" style="text-align: center">
<h:outputText value="#{cte.TOMADOR}"/>
</p:column>
<p:column headerText="Chave Acesso" width="350" style="text-align: center">
<h:outputText value="#{cte.TRANSACTIONID}"/>
</p:column>
<p:column headerText="Dt. Criação" width="120" style="text-align: center">
<h:outputText value="#{cte.IDE_TIMESTAMP}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</p:column>
<p:column headerText="N° Protocolo" width="120" style="text-align: center">
<h:outputText value="#{cte.IDE_AUTHCODESEFAZ}"/>
</p:column>
</p:dataTable>
</h:form>
I'm using primefaces 5.3 and tried to use apache poi 3.8 and 3.10-FINAL but both did not work right.
In the log i've got no errors.
Edit: I already know what is happening.
The problem is that when my table is load, it's empty, but looks like the button to export It to excel, keeps some kind of cache with the table empty, and even after I load data into the table, the button keeps exporting the excel empty.
Now, I don't know how to solve this problem.
Well, if someone else get into this problem, here is the answer that corrects mine:
My managed bean was request scoped. But when I clicked the button to export excel, It makes a new request to the maneged bean. And in this request my list was null. I checked this by putting a breakpoint in the method getList.
So I simply change the scope of my managed bean from request scope to view scope and It works fine.
It seems that the exporter use the property for filtered data, so at the first time, you get only headers because the filtered data is empty. I suggest try adding data to the filtered data in the load of the page.
add f:facet header after your p:column
<p:column>
<f:facet name="header">
<h:outputText value="CNPJ Emissor"/>
</f:facet>
<h:outputText value="#{cte.EMIT_CNPJ}"/>
</p:column>
I want to disable or hide the commandbutton if no record is found.
I have gooogled but could not find the solution.
Here is the code:
<p:column>
<div style="overflow: auto; width: 100%;">
<p:dataTable var="tPreferences"
value="#{userPreferences.preferences}"
emptyMessage="No Questions Found." id="pTable" styleClass="borderless">
<p:column headerText="PREFERENCES">
<h:outputText id="sName" styleClass="cellLabelMand"
value="#{tPreferences.shortText}" />
<h:outputText value="<br/><br/>" escape="false" />
<h:selectManyCheckbox id="grid"
value="#{tPreferences.preferencesSelectedItem}"
layout="grid" columns="1">
<f:selectItems value="#{tPreferences.catList}" var="pref" />
</h:selectManyCheckbox>
</p:column>
</p:dataTable>
</div>
</p:column>
CommandButton:
<h:commandButton value="Submit" id="btnUserInfo"
onclick="return openUpdateDialog();"
actionListener="#{userPreferences.saveUserPreferences}"
styleClass="richButtonSave" style="background:green;"
disabled="#{empty pTable.tPreferences}" />
I need to export datatable row expansion in primefaces but i cannot figure it out. Is there anyway to do that ?
Thanks in advance.
You can export PrimeFaces DataTable with rowExpansion data without an other Java API or you can use custom export method on ManagedBean class with Apache POI API help.
Here trick is, add the columns which to be exporting to the file and append the visible=”false” attribute to the these columns.
Then append the exportable=”false” attribute to the p:rowToggler column.
Thus, you won’t see datatable columns but you will see these columns on the exported file.
Obtained from here
<h:form id="myDtTblFrm">
<h:commandLink>
<img src="../ims/excel.png"/>
<p:dataExporter type="xlsx" target="myTbl" fileName="myExcelFile"/>
</h:commandLink>
<p:dataTable id="myTbl" var="item" value="#{myBean.list}">
<p:rowExpansion>
<p:panelGrid columns="2" columnClasses="label, value" style="width: 50%">
<h:outputText value="Column Header 04" />
<h:outputText value="#{item.property04}" />
<h:outputText value="Column Header 05" />
<h:outputText value="#{item.property05}" />
</p:panelGrid>
</p:rowExpansion>
<p:column exportable="false">
<p:rowToggler />
</p:column>
<p:column headerText="Colum01">
<p:outputLabel value="#{item.property01}" />
</p:column>
<p:column headerText="Column02" visible="false" >
<p:outputLabel value="#{item.property02}" />
</p:column>
<p:column headerText="colum03" >
<p:outputLabel value="#{item.property03}" />
</p:column>
<p:column headerText="colum04" style="display: none">
<p:outputLabel value="#{item.property04}" />
</p:column>
<p:column headerText="colum05" style="display: none">
<p:outputLabel value="#{item.property05}" />
</p:column>
</p:dataTable>
I read many answers abot this issue, they say I should add an item to the list that feed the datatable and then refresh the form, but this does not work in my progect. this is my datatable:
<p:dataTable var="rowItem"
scrollable="true"
scrollHeight="100%"
id="flussiGuestSummary"
emptyMessage="nessun flusso guest selezionato"
value="#{fileMatchMB.selectedGuests}"
rowKey="#{rowItem.row}">
style="width:10px;text-align:center" />
<p:column headerText="Date Valuta"
width="30">
<h:outputText value="#{rowItem.data}">
<f:converter
converterId="filematch.interfaccia.CalendarConverter" />
</h:outputText>
</p:column>
<p:column headerText="Importo"
style="text-align: center; width:30px;">
<h:outputText value="#{rowItem.amount}">
<o:converter converterId="javax.faces.Number"
currencySymbol="#{rowItem.getCurrencySymbol()}"
type="currency" />
</h:outputText>
</p:column>
<p:column headerText="Descrizione"
styleClass="scrollableCell"
style="text-align: center; width:80px;">
<h:outputText value=" #{rowItem.descrizione}">
<f:converter converterId="filematch.interfaccia.StringShortner" />
<f:attribute name="shortnerActive"
value="#{fileMatchMB.shortnerActive}" />
</h:outputText>
</p:column>
<p:column headerText="Causale"
styleClass="scrollableCell"
style="text-align: center; width:30px;">
<h:outputText value=" #{rowItem.causale}"
width="100">
<f:converter converterId="filematch.interfaccia.StringShortner" />
<f:attribute name="shortnerActive"
value="#{fileMatchMB.shortnerActive}" />
</h:outputText>
</p:column>
<p:column headerText="match"
styleClass="scrollableCell"
style="text-align: center; width:10px;">
<h:outputText value=" #{rowItem.match}">
<f:converter converterId="filematch.interfaccia.StringShortner" />
<f:attribute name="shortnerActive"
value="#{fileMatchMB.shortnerActive}" />
</h:outputText>
</p:column>
<f:facet name="footer">
"#{fileMatchMB.countGuest} / #{fileMatchMB.guestList.size()} #{msg.msg_records}"
</f:facet>
</p:dataTable>
the code in the backing bean:
this.selectedGuests = selected_list;
I am sure selected_list is nort empty, but my datatable remains empty, what am I doing wrong?
I am having trouble updating components in primefaces. Here is one example:
<h:form>
<p:panel style="width: 350px;" header="Partial Process">
<p:dataTable id="tablaPersonas" var="per" value="#{manejador.lista}">
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Nombre" />
</f:facet>
<h:outputText value="#{per.nombre}" />
</p:column>
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Apellido" />
</f:facet>
<h:outputText value="#{per.apellido}" />
</p:column>
<p:column headerText="Editar" style="text-align: center;">
<p:commandButton value="Editar"/>
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton value="Abrir" onclick="widgetDlgAgregar.show();"/>
<p:dialog header="Agregar" widgetVar="widgetDlgAgregar" width="250" height="150" closable="true">
<h:panelGrid id="gridAdd" columns="2">
<h:outputLabel value="Nombre:"/>
<p:inputText value="#{manejador.auxiliarAgregar.nombre}"/>
<h:outputLabel value="Apellido:"/>
<p:inputText value="#{manejador.auxiliarAgregar.apellido}"/>
<p:commandButton oncomplete="widgetDlgAgregar.hide();" update="tablaPersonas,gridAdd" value="Agregar" actionListener="#{manejador.agregarPersona}"/>
</h:panelGrid>
</p:dialog>
</h:form>
As you see, I click on a CommandButton called "Abrir" and a Dialog opens with "Agregar" as title. I fill in the input boxes and when I click the CommandButton "Agregar", the DataTable isn't updated. Why is this happening?
Oh sorry i think you forgot this update
try this it should work
<h:form prependId="false">
<p:panel style="width: 350px;" header="Partial Process">
<p:dataTable id="tablaPersonas" var="per"
value="#{manejador.lista}">
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Nombre" />
</f:facet>
<h:outputText value="#{per.nombre}" />
</p:column>
<p:column style="text-align: center;">
<f:facet name="header">
<h:outputText value="Apellido" />
</f:facet>
<h:outputText value="#{per.apellido}" />
</p:column>
<p:column headerText="Editar" style="text-align: center;">
<p:commandButton value="Editar" />
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton value="Abrir" onclick="widgetDlgAgregar.show();" update="gridAdd" />
<p:dialog header="Agregar" widgetVar="widgetDlgAgregar" width="250"
height="150" closable="true">
<h:panelGrid id="gridAdd" columns="2">
<h:outputLabel value="Nombre:" />
<p:inputText value="#{manejador.auxiliarAgregar.nombre}" />
<h:outputLabel value="Apellido:" />
<p:inputText value="#{manejador.auxiliarAgregar.apellido}" />
<p:commandButton oncomplete="widgetDlgAgregar.hide();"
update="tablaPersonas,gridAdd" value="Agregar"
actionListener="#{manejador.agregarPersona}" />
</h:panelGrid>
</p:dialog>
</h:form>
try to put your
<p:dialog header="Agregar" widgetVar="widgetDlgAgregar" width="250" height="150" closable="true">
outside the form and add prependId="false" to your form <h:form prependId="false" >