PrimeFaces, can’t update tab disabled attribute - jsf

I need to update a tab’s disabled attribute when a user edits a dataTable using rowEditor.
I have a ajax tag in a dataTable listening for event="rowEdit" which calls a backing bean method that sets the tab's disabled attribute to true.
If I reference only the tab group with the tabView id as in update=”:tabView” the tab will update but only the edited row of the dataTable renders with no grid lines. If I reference the tab as in update=”:tabView:tab” IDs, the dataTable renders fine but the tab’s disabled attribute doesn't.
The tab being updated is not in the same tab as the dataTable being edited.
The dataTable is in the rates tab and he tab I'm trying to update is tbVSelRates
<p:tab id="rates" title="Select Rates" >
<p:panelGrid id="pnlMultiDealUpdate" header="Select Product Rates for Multipule Deal Update" style="margin-top:10px; border: 2px" >
<p:row>
<p:column>
<h:form id="frmSRDealRates" method="post" action="">
<p:outputLabel id="lblRateAgreed" for="txtRateAgreed" value="#{msgs['srDeal.rates.agreed']}:"/>
<p:inputText id="txtRateAgreed" value="#{dealManagedBean.txtRateAgreedVal}" style="width:40px;" readonly="#{dealManagedBean.readOnly}"/> %
<p:outputLabel id="lblRateCat" for="pklRateCat" value="#{msgs['srDeal.rates.cat']}:"/>
<p:pickList id="pklRateCat" value="#{dealManagedBean.rateCats}" var="cat" itemLabel="#{cat}" itemValue="#{cat}" disabled="#{dealManagedBean.readOnly}"/>
<p:commandButton id="btnApply" value="#{msgs['srDeal.rates.btn.apply']}" style="width:100px;" disabled="#{dealManagedBean.readOnly}"
actionListener="#{dealManagedBean.applyChangesMultiUpdate}" process="frmSRDealRates" update="productsTable,:tbVUpdateDeals"
/>
<p:commandButton id="btnUndo" value="#{msgs['srDeal.rates.btn.undo']}" style="width:100px;" disabled="#{dealManagedBean.readOnly}"
onstart="return confirm('Are you sure that you want to undo all recent changes?\nDoing so will remove all rates.');"
actionListener="#{dealManagedBean.undoMultiDealRateChanges}" process="frmSRDealRates" update="productsTable" />
<p:dataTable var="pr" value="#{dealManagedBean.products}" filteredValue="#{filteredValueManagedBean.filteredProducts}" paginator="true" rows="10"
id="productsTable" editable="true" rowKey="#{pr.molecule}" paginatorPosition="top"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,50, 100, 1000">
<!-- process=":tbVUpdateDeals:frmSRDealRates" -->
<p:ajax event="rowEdit" listener="#{dealManagedBean.applyRowChangesMassUpdate}" update=":tbVUpdateDeals:tbVSelRates" />
<f:facet name="header">
#{msgs['srDeal.rates.prod.header']}
</f:facet>
<p:column headerText="#{msgs['srDeal.rates.prod.cat']}" sortBy="#{pr.category}" filterBy="#{pr.category}" id="category"
filterOptions="#{dealManagedBean.categoryOptions}" filterMatchMode="exact" width="40" filterStyle="width:30px">
<f:facet name="header" >
<h:outputText value="#{msgs['srDeal.rates.prod.cat']}" />
</f:facet>
<h:outputText value="#{pr.category}" />
</p:column>
<p:column headerText="#{msgs['srDeal.rates.prod.molecule']}" sortBy="#{pr.moleculeDescription}" filterBy="#{pr.moleculeDescription}" filterMatchMode="contains" id="molecule"
width="180" filterStyle="width:160px">
<f:facet name="header" >
<h:outputText value="#{msgs['srDeal.rates.prod.molecule']}" />
</f:facet>
<h:outputText value="#{pr.moleculeDescription}" />
</p:column>
<p:column headerText="#{msgs['srDeal.rates.prod.planrate']}" sortBy="#{pr.plannedRate}" id="plannedRateCellEdit" width="60">
<p:cellEditor id="massUpdateRate" >
<f:facet name="output">
<h:outputText value="#{pr.plannedRate}" id="otxtRate">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2"/>
</h:outputText>%
</f:facet>
<f:facet name="input">
<p:inputText value="#{pr.plannedRate}" style="width:100%" label="plndRate" id="txtRate" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column width="35" exportable="false">
<p:rowEditor/>
</p:column>
</p:dataTable>
<p:commandButton id="btnSelectRatesNext" value="Next" actionListener="#{dealManagedBean.goToConfirmRatesTab}" update=":tbVUpdateDeals" />
<p:commandButton value="Cancel" onclick="window.location='salesRepHome.jsf'" style="width:75px;" />
</h:form>
</p:column>
</p:row>
</p:panelGrid>
</p:tab>
<p:tab id="tbVSelRates" title="Confirm Rates" disabled="#{dealManagedBean.conRatesTabDisabled}">
<h:form id="frmSelProdRates" >
<p:panelGrid id="pnlConRates" columns="1">
<p:dataTable var="pr" value="#{dealManagedBean.selectedUpdateProducts}" filteredValue="#{filteredValueManagedBean.filteredProducts}" paginator="true" rows="10"
id="dtSelProductsTable" editable="true" rowKey="#{pr.molecule}" paginatorPosition="top"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,50, 100, 1000">
<f:facet name="header">
Confirm Selected Product Rates
</f:facet>
<p:column headerText="#{msgs['srDeal.rates.prod.cat']}" sortBy="#{pr.category}" filterBy="#{pr.category}" id="category"
filterOptions="#{dealManagedBean.categoryOptions}" filterMatchMode="exact" width="40" filterStyle="width:30px">
<f:facet name="header" >
<h:outputText value="#{msgs['srDeal.rates.prod.cat']}" />
</f:facet>
<h:outputText value="#{pr.category}" />
</p:column>
<p:column headerText="#{msgs['srDeal.rates.prod.molecule']}" sortBy="#{pr.moleculeDescription}" filterBy="#{pr.moleculeDescription}" filterMatchMode="contains" id="molecule"
width="180" filterStyle="width:160px">
<f:facet name="header" >
<h:outputText value="#{msgs['srDeal.rates.prod.molecule']}" />
</f:facet>
<h:outputText value="#{pr.moleculeDescription}" />
</p:column>
<p:column headerText="Planned Rate" sortBy="#{pr.plannedRate}" id="plannedRate" width="60">
<f:facet name="header" >
<h:outputText value="Planned Rate" />
</f:facet>
<h:outputText value="#{pr.plannedRate}" id="oTxtPlanedRate">
<f:convertNumber maxFractionDigits="2" minFractionDigits="2"/>
</h:outputText>%
</p:column>
</p:dataTable>
<div style="float:left; margin-top:10px">
<h:commandLink id="exAll" style="margin-left:10px;">
<spacer width="5"/> <h:outputText value="#{msgs['srDeal.bg.bgs.excelall']}" />
<p:dataExporter type="xls" target="dtSelProductsTable" fileName="Product Rates for Mutil Deal Update"/>
</h:commandLink>
</div>
<div style="margin-top:10px; float:right">
<p:commandButton id="btnNextDeals" value="Next" actionListener="#{dealManagedBean.goToSelectDealsTab}" update=":tbVUpdateDeals"/>
</div>
</p:panelGrid>
</h:form>
</p:tab>
PrimeFaces 3.4.2, JBoss 6.0.1 JSF 2.0
Hope this posts right, first time posting a question on StackOverflow
Thanks
public void applyRowChangesMassUpdate(RowEditEvent event){
DataTable dtRates = (DataTable) event.getSource();
Product dtRow = (Product)dtRates.getRowData();
logger.log(Level.FINE, "Molecule: {0}", dtRow.getMolecule());
logger.log(Level.FINE, "Projected Sales: {0}", dtRow.getYtdProjectedSales());
logger.log(Level.FINE, "Planned Rate: {0}", dtRow.getPlannedRate());
if(dtRow.getPlannedRate()!= null && dtRow.getYtdProjectedSales() != null){
dtRow.setPlannedPAProjected(new BigDecimal(0.01 * dtRow.getYtdProjectedSales().doubleValue() * dtRow.getPlannedRate().doubleValue()));
}
logger.log(Level.FINE, "Planned PA Projected: {0}", dtRow.getPlannedPAProjected());
conRatesTabDisabled = true;
tabIndex = 1;
}

The plan is to call applyRowChangesMassUpdate via p:remoteCommand and disable the tab
using the PrimeFaces Javascript API. Here's how it can be done:
Give a widgetVar attribute to your p:dataTable for example dataTableWV.
<p:dataTable widgetVar="dataTableWV" value="..." var="...">
Give a widgetVar also to your p:tabView for example tabViewWV.
<p:tabView widgetVar="tabViewWV">
Add the call to applyRowChangesMassUpdate:
<p:remoteCommand name="applyRowChanges" actionListener="#{dealManagedBean .applyRowChangesMassUpdate}" />
Then use this script:
<script>
$(document).ready(function() {
//bind a function on table value changes
dataTableWV.tbody.context.onchange = function() {
//disable the tab you want by index, assuming the tab
//is the second one, its index will be '1'
tabViewWV.disable(1);
//selects view back to the first tab.
tabViewWV.select(0);
//call the 'remoteCommand' function
applyRowChanges();
}
});
</script>
This way, the rowEdit event is no longer needed, so just remove
<p:ajax event="rowEdit" listener="#{dealManagedBean.applyRowChangesMassUpdate}" update=":tbVUpdateDeals:tbVSelRates" />
Also you can remove
conRatesTabDisabled = true;
tabIndex = 1;
from applyRowChangesMassUpdate method, as the tab gets disabled, and the view is moved to another tab with a client-side code, which is better preferred to server-side code when a matter of view that is needed.

Related

Primefaces Datatable clear filter boolean value is setting to default(false)

I am using primeface6.0, i have a datatable with data of 50 records and have paginator along with filter option, i am filtering data which does not exist in table and onclear boolean column is setting to false, below is the code.
<p:dataTable id="inventorytbl" value="#{inventorybean.inventoryList}"
var="inventory" rows="15" paginator="true"
paginatorPosition="bottom" pageLinks="5"
paginatorAlwaysVisible="false" widgetVar="inventoryWidget"
rowKey="#{inventory.code}"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}">
<f:facet name="header">
<p:outputPanel>
<p:outputPanel>
<p:inputText id="globalFilter"
onkeyup="PF('inventoryWidget').filter()"
onkeypress="if (event.keyCode == 13) {return false; }"
style="width:150px;float: right;margin-left: 5px;"
placeholder=" Enter keyword" />
</p:outputPanel>
</p:outputPanel>
</f:facet>
<p:column headerText="Material Name" style="width:23%"
sortBy="#{inventory.materialName}"
filterBy="#{inventory.materialName}" filterMatchMode="contains"
filterStyle="display:none;visibility:hidden;">
<div title="#{inventory.materialName}">
#{inventory.materialName}</div>
</p:column>
// onfilter clearing button inside column getting disable(default to false)
<p:column style="width: 10%;text-align: -webkit-center;"
headerText="Action" filterBy="#{inventory.activeFlag}"
filterMatchMode="contains"
filterStyle="display:none;visibility:hidden;">
<p:commandButton id="musterupdatelnk"
action="edit"
disabled="#{not inventory.activeFlag}"
icon="fa fa-pencil-square-o"/>
</p:column>
I'm not sure if the built-in filter clear feature works properly, but I've ran into similar issue and have decided to create my own custom 'clear' button and placed it inside a column header.
<p:column style="width: 16px;" exportable="false">
<f:facet name="header">
<p:commandLink id="clearFilterLink" onclick="PF('WidgetVar').clearFilters();" styleClass="clear-filter-icon" />
<p:tooltip for="clearFilterLink" value="Clear Filters" trackMouse="true" position="right"/>
</f:facet>
<p:rowToggler />
</p:column>
This is just for your reference, but I think you can do something similar. Maybe create a button somewhere on the page that clears the filter on click?

Headers are not shown in exported excel file from primefaces datatable

I have a datatable like this. But it would not export the headers to excel :
<h:form id="formOptionList">
<p:dataTable id="OptionTable"
var="Options"
widgetVar="OptionTable"
value="#{managedBean.options}"
filteredValue="#{managedBean.filteredOptions}"
emptyMessage="No Options found."
rendered="#{managedBean.userPreferences.showTable}"
paginator="true"
rows="10"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="20,50,100"
>
<p:column id="id" headerText="ID" filterBy="id" filterMatchMode="exact" width="12%" rendered="#{managedBean.userPreferences.showID}" >
<h:outputText value="#{options.optionID}" />
</p:column>
....
....
</p:dataTable>
<h:panelGrid columns="1">
<p:panel header="Export All Data">
<h:commandLink>
<p:graphicImage value="../resources/images/menuicons/options.png" />
<p:dataExporter type="xls" target="OptionTable" fileName="Options" />
</h:commandLink>
</p:panel>
</h:panelGrid>
</h:form>
So I changed it to
<p:column id="id" filterBy="id" filterMatchMode="exact" width="12%" rendered="#{managedBean.userPreferences.showID}" >
<f:facet name="header>">
<h:outputText value="Option ID"/>
</f:facet>
<h:outputText value="#{Options.OptionID}" />
</p:column>
And I still don't see the headers in the excel file. Any ideas ?
Headers are not shown in exported excel file from primefaces datatable
Try this:
<p:column id="id" filterBy="#{Options.OptionID}" filterMatchMode="exact" width="12%" rendered="#{managedBean.userPreferences.showID}" >
<f:facet name="header>">
<h:outputText value="Option ID"/>
</f:facet>
<h:outputText value="#{Options.OptionID}" />
</p:column>
You put a <h:outputText value= ""/> after your </f:facet> ?
<p:column>
<f:facet name="header">
<h:outputText value="Your Column Name" />
</f:facet>
<h:outputText value="Your value" />
</p:column>
You can put a new column with display none, from the existing column just put an exporter false
<p:column id="id" filterBy="# Options.OptionID}"filterMatchMode="exact" width="12%" rendered="#anagedBean.userPreferences.showID}"exporter="false">
<f:facet name="header>">
<h:outputText value="Option ID" />
</f:facet>
<h:outputText value="#{Options.OptionID}" />
</p:column>
Add new column with display none and remove all sorting,filtering and rendering
<p:column exporter="true" style="display:none;">
<f:facet name="header>">
<h:outputText value="Option ID"/>
</f:facet>
<h:outputText value="#{Options.OptionID}" />
</p:column>
This works perfectly.

p:datatable multiple select with checkboxes. Rowtoggler triggers event

I have a datatable inside another datatable. The nested table I need to have a multiple selection checkboxes, a button to fire actionlistener and a p:rowToggler to show more data in row. The toggler and commandbutton works fine without the selection column in the table, but when I add this column the commandButton doesn't go to the backing bean, toggler on click doesn't work properly, and setSelected isn't called. Both throw a NP. I'm using 3.4.2 is this feature on newer releases only?
SEVERE: FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/error.xhtml' will be shown.
java.lang.NullPointerException
Table
<p:dataTable id="gro" var="g" value="#{requestBean.main.childRequest}" styleClass="veaGrid"
paginator="true" rows="1" paginatorTemplate="{CurrentPageReport}" >
<p:column>
<p:ajaxStatus >
<f:facet name="start">
<p:graphicImage value="/resources/images/ajaxloadingbar.gif" />
</f:facet>
<f:facet name="complete">
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
<p:dataTable id="group" var="g2" value="#{g.groups}" rowKey="#{g2.group_name}" selection="#{requestBean.selectedGroups}" >
<p:column selectionMode="multiple" style="width:2%" />
<p:column headerText="#{g.systemCd} - Groups" style="width:25%" >
#{g2.group_name}
</p:column>
<p:column style="width:2%">
View Users <p:rowToggler />
</p:column>
<p:rowExpansion>
<p:dataTable styleClass="veaGrid" var="g3" value="#{g2.group_members}" sortOrder="descending"
paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
filteredValue="#{requestBean.filteredMembers}">
<p:column filterBy="#{g3.first_name}">
<h:outputText value="#{g3.first_name}"/>
</p:column>
<p:column filterBy="#{g3.last_name}">
<h:outputText value="#{g3.last_name}"/>
</p:column>
<p:column filterBy="#{g3.signon}">
<h:outputText value="#{g3.signon}"/>
</p:column>
</p:dataTable>
</p:rowExpansion>
</p:dataTable>
<center>
<p:commandButton id="continue" value="Continue" actionListener="#{requestBean.saveGroups}"/>
</center>
</p:column>
</p:dataTable>
Found the problem.. I had the requestBean.selectedGroups set to
ArrayList<Group>
I changed the property to
Group[]
and now everything is functional again.

Primefaces dataTable Sorting does not seem to work

I am having difficulties sorting a dynamic dataTable
dataTable
<h:form prependId="false" id="Main_Form">
<p:dataTable id="dataTable" var="c" value="#{databaseSearch.customerList}"
paginator="true" rows="10" paginatorAlwaysVisible="false"
paginatorTemplate="Page {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} Rows per page {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,30" draggableColumns="True">
<p:column sortBy="#{c.machine}" headerText="Machine">
<h:outputText value="#{c.machine}" />
</p:column>
<p:column sortBy="#{c.company}" headerText="Company">
<h:outputText value="#{c.company}" />
</p:column>
<p:column sortBy="#{c.contact}" headerText="Contact">
<h:outputText value="#{c.contact}" />
</p:column>
<p:column sortBy="#{c.phone}" headerText="Phone">
<h:outputText value="#{c.phone}" />
</p:column>
<p:column sortBy="#{c.email}" headerText="Email">
<h:outputText value="#{c.email}" />
</p:column>
<p:column exportable="false" headerText="Modify">
<center>
<p:commandButton id="basic" value="Update"
action="#{updateEntry.setMachine(c.machine)}"
oncomplete="dlg1.show();"
styleClass="ui-Machinebutton" update=":Update_Entry"/>
<p:tooltip for="basic" value="Update/Delete Database Entry"
showEffect="fade" hideEffect="fade" />
</center>
</p:column>
</p:dataTable>
</h:form>
I am using a #SessionScoped bean where databaseSearch.customerList would query the database and populate the dataTable. When I click on the column name to sort, the sort arrow mark changes but the table contents do not sort.
I am using PF 3.4.2
If you are querying your database in your getCustomerList method in every request this will not work. You may try with a local variable
public class DatabaseSearch{
private List<C> customerList;
public List<C> getCustomerList () {
if (customerList == null)
customerList = dao.getcustomerList();
return customerList ;
}
}

Primefaces Dialog is not displayed for the second time

I'm working with Primefaces.My functionality is to display the records in a datatable with primefaces inline editing .Here we have an "Add" button which displays a dialog to enter new record.After entering the values and click on "Save" button,the record is inserted and the datatable is updated with the record.
My problem is, when i click on "Add" button for the second time the dialog box is not opening.Here is my code.
<h:form id="myForm" prependId="false">
<p:dataTable var="client" id="clientTable" value="#{clientView.clientModelList}" paginatorPosition="top" paginator="true" rows="10"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,20,25" rowEditListener="#{clientView.rowEditListener}" onRowEditUpdate="growl" >
<p:column style="width:60px;">
<p:rowEditor/>
<h:commandButton style="padding-left:5px;" image="/resources/images/delete.jpeg" styleClass="spa" value="delete" immediate="true" actionListener="#{clientView.delete}" >
<f:attribute name="username" value="#{client}" />
</h:commandButton>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{myLoginBean.multilangMap['everis.client.idCliente']}" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.codCliente}" />
</f:facet>
<f:facet name="input">
<h:inputText required="true" requiredMessage="#{msg.idClienteEmpty}" maxlength="80" value="#{client.codCliente}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="#{myLoginBean.multilangMap['everis.client.desCliente']}" />
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.desCliente}" />
</f:facet>
<f:facet name="input">
<h:inputText required="true" requiredMessage="#{msg.desClienteEmpty}" maxlength="255" value="#{client.desCliente}" />
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
</div>
<div class="divButPosition">
<h:panelGroup id="buttonPanel">
<p:commandButton id="buttons" value="Add" actionListener="#{clientView.addEmptyClient}"
async="true" update="buttonPanel,dlgForm:table" rendered="#{!clientView.addNewRow}" oncomplete="alert('complete');clientDialog.show();" />
</h:panelGroup>
</div>
</h:form>
<p:growl id="growl" showDetail="false" />
<p:dialog id="clientDialog" header="Client Detail" widgetVar="clientDialog" resizable="false" width="500" showEffect="explode" hideEffect="explode" modal="false" closable="false">
<h:form id="dlgForm" >
<h:dataTable var="newclient" id="table" value="#{clientView.newClient}">
<h:column>
<f:facet name="header">
<h:outputText value="#{myLoginBean.multilangMap['everis.client.idCliente']}" />
</f:facet>
<h:inputText value="#{newclient.codCliente}" required="true" requiredMessage="#{msg.idClienteEmpty}" maxlength="80"/>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="#{myLoginBean.multilangMap['everis.client.desCliente']}" />
</f:facet>
<h:inputText value="#{newclient.desCliente}" required="true" requiredMessage="#{msg.desClienteEmpty}" maxlength="255"/>
</h:column>
</h:dataTable>
<p:commandButton value="everis.save" actionListener="#{clientView.saveClient}" async="true" update="growl,buttonPanel,clientTable" oncomplete="handleRequest(args ,document.getElementById('clientDialog'))" />
<p:commandButton value="#{myLoginBean.multilangMap['everis.cancel']}" immediate="true" update="buttonPanel,table" async="true" actionListener="#{clientView.cancelClient}" oncomplete="clientDialog.hide();" />
</h:form>
</p:dialog>
Thanks alot for every one.
Now correct me if i'm wrong, but if you click save on the dialog you never close it? I won't know if it will help but you can try atleast

Resources