I have two calendar controls and one command button. basically i want to give a range of date to pick the data from the database and then when i press the command button the datatable is displayed in the dialog box, the problem is java bean class is working it is loading the exact data which i want, but the datatable is not refreshing with command button click
my code is given;
<h:form id="form" >
<p:calendar value="#{calendarBean.dateFrom}" id="calFrom" pattern="yyyy-mm-dd">
<p:ajax event="dateSelect" listener="#{calendarBean.handleDateSelectFrom}" />
</p:calendar>
<p:calendar value="#{calendarBean.dateTo}" id="calTo" pattern="yyyy-mm-dd">
<p:ajax event="dateSelect" listener="#{calendarBean.handleDateSelectTo}" />
</p:calendar>
<p:commandButton value="Submit" action="#{calendarBean.submit()}" update="fTable" onclick="aDlg.show()">
<f:ajax render=":form:fTable" execute="#form"></f:ajax>
</p:commandButton>
<p:dialog id="aDialog" header="Filter List" widgetVar="aDlg"
modal="true" showEffect="explode"
hideEffect="explode" >
<p:panel id="pnl">
<p:dataTable id="fTable" value="#{calenderBean.list}" var="row" >
<p:column headerText="ID">
<h:outputText value="#{row.ID}"/>
</p:column>
<p:column headerText="Name">
<h:outputText value="#{row.Name}"/>
</p:column>
<p:column headerText="Time">
<h:outputText value="#{row.Time}"/>
</p:column>
<p:column headerText="User">
<h:outputText value="#{row.userName}"/>
</p:column>
</p:dataTable>
</p:panel>
</p:dialog>
</h:form>
kindly guide me regarding this issue
First thing to do, is remove the f:ajax, it's not working good with Primefaces. Also the update attribute should do everything.
This said, I have the very same code as yours which is working good.
If removing f:ajax is not working, try to check your managed bean scope (May be it's of request scope and data is re-initialized with every request)
Try Updating the dialog instead.
update="fTable"
Related
I have a datatable, where I add rows dynamically (a button click), and let users edit those rows with primefaces cell editing.
I want to add validation for the cells, however, the validation does not occur when the input texts (in the cell) are pristine.
In order for the validation to work, the user have to actually write something in the input text (make it dirty), then deletes it, only then the validation (required for this case) will be kicked-in.
example code:
<f:view>
<p:growl autoUpdate="true"/>
<h:form>
<p:commandButton value="add row" update="table" action="#{myBean.addRow}"/>
<p:dataTable value="#{myBean.users}" var="var" id="table" editMode="cell" editable="true">
<p:column headerText="Quantity">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{var.name}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{var.name}" required="true">
<f:validateRequired />
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
</p:dataTable>
<p:commandButton value="submit" action="#{myBean.submit}"/>
</h:form>
</f:view>
Using primefaces 5.3 and JSF 2.2.
Update:
This bug is fixed since version 6.2
https://github.com/primefaces/primefaces/issues/2512
I have problem with a primefaces datable, I have a filter on a column and before to filter the result my datatable is displayed properly like this:
When I choose a filter, the combobox of the filter is properly poulated:
A soon I choose the item for the filter, the results are properly filtered but I have a display of the datatable like this:
I just see the results who should be display in a datatable but the table is gone.
The code seems good and I don't see where is the problem:
<p:outputPanel autoUpdate="true" class="ui-g-12">
<div class="card">
<h1>Gestion des noeuds</h1>
<h:form>
<p:dataTable value="#{nodeController.nodes}"
var="node"
tableStyle="table-layout: auto;"
rowKey="#{node.nodeId}"
paginator="true"
paginatorPosition="bottom"
paginatorAlwaysVisible="false"
rows="15"
widgetVar="nodeTable"
filteredValue="#{nodeController.filterNodes}"
editable="true"
selection="#{nodeController.selectedNode}"
selectionMode="single"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
<p:column headerText="ID">
<h:outputText value="#{node.nodeId}"/>
</p:column>
<p:column headerText="Nom">
<h:outputText value="#{node.modeName}"/>
</p:column>
<p:column headerText="Description">
<h:outputText value="#{node.nodeDescription}"/>
</p:column>
<p:column filterBy="#{node.typeNodeId}" filterMatchMode="exact" headerText="Type">
<f:facet name="filter">
<p:selectOneMenu onchange="PF('nodeTable').filter()">
<f:selectItem itemLabel="filtre" itemValue="#{null}" noSelectionOption="true"/>
<f:selectItems value="#{nodeController.nodeTypes}"/>
</p:selectOneMenu>
</f:facet>
<h:outputText value="#{node.typeNodeId}"/>
</p:column>
<p:column headerText="IPv4">
<h:outputText value="#{node.ipv4}"/>
</p:column>
<p:column headerText="IPv6">
<h:outputText value="#{node.ipv6}"/>
</p:column>
<p:column headerText="powwo agent">
<h:selectBooleanCheckbox value="#{node.agentInstalled}"/>
</p:column>
<p:column headerText="Network status" style="text-align:center">
<p:graphicImage rendered="#{node.isconnected}" name="images/ConnectionStatus25.png" library="omega-layout" width="20"/>
<p:graphicImage rendered="#{!node.isconnected}" name="images/Siren-25.png" library="omega-layout" width="20"/>
</p:column>
<p:column>
<p:rowEditor/>
</p:column>
</p:dataTable>
<p:commandButton value="effacer"
update="msg"
actionListener="#{nodeController.deleteSelectedNode()}"
style="width:auto;margin-bottom:10px;margin-top: 10px"/>
</h:form>
</div>
</p:outputPanel>
Did you already meet this issue with the rendered of a datable? Any idea how to fix it?
Effectively, your title and first sentence are not correct. It is not a bug in the datatable but a 'bug' in your code. You should not use autoupdate="true" on the p:outputPanel in this case. It updates all its content on each ajax update that happens inside it, including an ajax update during filtering. This latter also updates the datatable which means two conflicting updates. Off-topic: If you'd created a Minimal, Complete, and Verifiable example , you'd have found this out during removal of code.
If you have this problem when you have an ajax listener on one of the filter/page/sort/... events on the datatable and you need the autoUpdate="true" on the panel for other events in the wrapping panel, you could also prevent the autoUpdate to happen for these specific events by adding a ignoreAutoUpdate="true" to the specific events. So e.g.
<p:ajax event="filter" ignoreAutoUpdate="true" ... />
I need your help in calling a method from a backing bean once I ticked the SelectAll checkbox at the top of a dataTable. I am able to call the method ShowTotal
once I ticked or unticked the checkbox of each individual item, however when I tick the SelectAll checkbox from the top, no listener is called. Here is my code:
<p:dataTable id="PendingRequests" var="hr" selection="#{hrdirector.selectedRequests}"
value="#{hrdirector.listPendingRequests}" rowKey="#{hr.requestNo}"
filteredValue="#{hrdirector.filteredRequests}" widgetVar="dataTableWidgetVar">
<p:ajax event="rowSelectCheckbox" listener="#{hrdirector.ShowTotal}" process="#this"
update=":form:PendingRequests:sum"/>
<p:ajax event="rowUnselectCheckbox" listener="#{hrdirector.ShowTotal}" process="#this"
update=":form:PendingRequests:sum"/>
<p:column selectionMode="multiple" style="width:16px;text-align:center"></p:column>
<p:column headerText="Request No.">
<h:outputText value="#{hr.requestNo}"/>
</p:column>
<p:column headerText="Request Amount">
<h:outputText value="#{hr.requestAmount}"/>
</p:column>
</p:dataTable>
<h:outputText id="Sum" value="#{hr.Sum}"/>
I tried to add the below code in the column which it has the selection, but it gave me an error:
<p:column selectionMode="multiple" style="width:16px;text-align:center">
<p:ajax listener="#{hrdirector.ShowTotal}" />
</p:column>
Page 172 of the fabulous PrimeFaces documentation has the answer for you. What you need is called the toggleSelect event.
Based on the primefaces documentation:
Single Selection with a Command Component
This method is implemented with a command component such as commandLink or
commandButton. Selected row can be set to a server side instance by passing as a parameter if you
are using EL 2.2 or using f:setPropertyActionListener.
<p:dataTable var="car" value="#{carBean.cars}">
<p:column>
<p:commandButton value="Select">
<f:setPropertyActionListener value="#{car}"
target="#{carBean.selectedCar}" />
</p:commandButton>
</p:column>
...columns
</p:dataTable>
I need the row get highlighted when I press the button without selecting the row directly
This is my code:
<p:dataTable
rowKey="${xxx.y1}-${xxx.y2}"
selection="${managedBean.selectedRow}"
selectionMode="single"
value="#{managedBean.listOfBeans}" var="xxx">
<p:column>
<p:commandButton action="${managedBean.saveSomethingInDB}"
update="vvvComponent">
<f:setPropertyActionListener value="#{currentRow}"
target="#{managedBean.selectedRow}" />
</p:commandButton>
</p:column>
</p:dataTable>
I solved it in this way:
<p:dataTable
rowKey="${xxx.y1}-${xxx.y2}"
selection="${managedBean.selectedRow}"
selectionMode="single"
value="#{managedBean.listOfBeans}" var="xxx">
<p:column>
<p:commandButton action="${managedBean.saveSomethingInDB}" onclick="highlightRow(jQuery(this));"
update="vvvComponent">
<f:setPropertyActionListener value="#{currentRow}"
target="#{managedBean.selectedRow}" />
</p:commandButton>
</p:column>
</p:dataTable>
function highlightRow(commandButton) {
$('.ui-state-highlight').removeClass('ui-state-highlight');
commandButton.closest('table').closest('tr').addClass('ui-state-highlight');
}
Your code works for me.
thanks to the propertyActionListener, the row is highlighted when I press the button
<f:setPropertyActionListener value="#{currentRow}"
target="#{managedBean.selectedRow}" />
i know its too late but this works
<p:commandButton action="${managedBean.saveSomethingInDB}" onclick="$('.ui-state-highlight').removeClass('ui-state-highlight');PF('tableWidgetVar').selectRow($(this).parents('tr:first').addClass('ui-state-highlight'));" >
<f:setPropertyActionListener value="#{currentRow}"
target="#{managedBean.selectedRow}" />
</p:commandButton>
and this way u dont need to selection or select mode on datatable
I have primefaces datatable,
<p:panel id="resultpanel">
<p:dataTable id="tbl" var="job" value="#{report.jobModel}"
paginator="true" rows="#{report.jobModel.pageSize}"
paginatorPosition="bottom" lazy="true" scrollable="true"
resizableColumns="true" rendered="#{!empty report.jobModel}"
emptyMessage="#{messages['common.datatable.emptymessage']}">
<p:ajax event="filter" listener="#{report.jobModel.onFilter}"
update="#form" />
<p:column sortBy="#{job.detail4}" filterBy="#{job.detail4}">
<f:facet name="header">
<h:outputText value="#{messages['content.donejobs.ftdi.datatable.fixedfeecolumn.header']}" />
</f:facet>
<h:outputText value="#{job.detail4}">
<f:converter converterId="KurusLiraConverter"></f:converter>
</h:outputText>
</p:column>
<f:facet name="footer">
<h:outputFormat value="#{messages['content.donejobs.ftdi.datatable.footer']}">
<f:param value="#{report.jobModel.rowCount}" />
</h:outputFormat>
<p:panel layout="block" style="border: 0px; text-align: center;">
<p:commandLink ajax="false" title="Download Report">
<p:graphicImage value="/images/excel.png" />
<p:fileDownload value="#{report.excelFileOfReportTable}" />
</p:commandLink>
</p:panel>
</f:facet>
</p:dataTable>
</p:panel>
I want to update the footer part when I filter the table. I have tried to update the footer by putting all the things in the footer in a single panel, giving it an ID, inspecting this ID via firebug, and giving it as a value to the update attribute of the primefaces ajax component. I have also performed this approach, to html outputformat and param components. But no success, lastly I have tried to update the form, this time the whole table has been rendered like a text file. Is there a way to update the table size, after filtering? By the way, I am using primefaces 3.0.RC1-SNAPSHOT, and testing in firefox 7.0.1. Thank you very much for your interest and comment.
There is an open issue for that here and they provide a patch for the dataTable code. My workaround (aka huge hack) doesn't require touching the primefaces codebase, which I prefer. I tested it for the events below, but I can't see why it wouldn't work for the rowEdit event.
<p:remoteCommand name="updateFilters" update="table:totalid"></p:remoteCommand>
<p:dataTable id="tabelaMunicipio" value="#{bean.model}" ...>
<p:ajax event="page" oncomplete="updateFilters()"/>
<p:ajax event="filter" oncomplete="updateFilters()"/>
<p:ajax event="sort" oncomplete="updateFilters()"/>
<p:column headerText="#{msg['id']}" sortBy="#{id}">
<h:outputText value="#{item.id}"></h:outputText>
<f:facet name="footer">
<h:outputText value="#{bean.model.totals['id']}" id="totalid"/>
</f:facet>
</p:column>
...
</p:dataTable>
Yes, I use a p:remoteCommand (invoked by the oncomplete client-side hook in p:ajax) to update the components inside the footer row. This causes a tiny delay on the footer update in comparison to the data itself, but I can live with that.
3.0.RC1-SNAPSHOT is not an official release, and from what I can tell it could mean any number of nightly builds after M4 or between M3 and M4. You should upgrade (or downgrade?) to a stable release such as M3 or M4 and see if you get the same problems.
Also you could try update="#this", but I'm unsure what effect that would have that shouldn't already work with #form.