i have a dynamic form based on dataTable, nested inside another dataTable.
on selecting a row from nested dataTable i'd like to update corresponding row from parent dataTable using <p:ajax>
<h:form id="form">
<h:dataTable var="field" value="#{testBean.propertyList}" varStatus="status">
<h:column>
<h:outputLabel value="#{field.label}"/>
</h:column>
<h:column>
<h:panelGrid columns="2" styleClass="app-grid" rendered="#{field.toOne}">
<h:panelGroup id="value">
<h:outputText value="#{testBean.entity[field.name]}"/>
</h:panelGroup>
<h:panelGroup>
<p:commandButton id="button" type="button" icon="ui-icon ui-icon-search"/>
<p:overlayPanel for="button" my="left bottom" at="left bottom" widgetVar="panel_#{field.name}">
<p:dataTable
id="table"
value="#{field.selectableModel}"
selection="#{testBean.entity[field.name]}"
selectionMode="single"
var="item"
rows="10"
paginator="true"
paginatorAlwaysVisible="true"
paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
currentPageReportTemplate="{totalRecords} records found"
rowsPerPageTemplate="5,10,15">
<p:ajax event="rowSelect" update=":???:value" oncomplete="panel_#{field.name}.hide()"/>
<p:column headerText="entity">#{item}</p:column>
</p:dataTable>
</p:overlayPanel>
</h:panelGroup>
</h:panelGrid>
</h:column>
</h:dataTable>
</h:form>
the problem is that generated component tree does not have repeated explicit child components for dataTable:
<HtmlForm enctype="application/x-www-form-urlencoded" id="form" inView="true" prependId="true" rendered="true" submitted="false" transient="false">
<HtmlDataTable border="-2147483648" first="0" id="j_idt101" inView="true" rendered="true" rowIndex="-1" rowStatePreserved="false" rows="0" transient="false" var="field">
<UIColumn id="j_idt103" inView="true" rendered="true" transient="false">
<HtmlOutputLabel escape="true" id="j_idt120" inView="true" rendered="true" style="" transient="false"/>
</UIColumn>
<UIColumn id="j_idt121" inView="true" rendered="true" transient="false">
<HtmlPanelGrid border="-2147483648" columns="2" id="j_idt122" inView="true" rendered="false" styleClass="app-grid" transient="false">
<HtmlPanelGroup id="value" inView="true" rendered="true" transient="false">
<HtmlOutputText escape="true" id="j_idt227" inView="true" rendered="true" transient="false"/>
</HtmlPanelGroup>
<HtmlPanelGroup id="j_idt117" inView="true" rendered="true" transient="false">
<CommandButton ajax="true" async="false" disabled="false" escape="true" global="true" icon="ui-icon ui-icon-search" iconPos="left" id="button" immediate="false" inView="true" inline="false" partialSubmit="true" readonly="false" rendered="true" transient="false" type="button"/>
<OverlayPanel appendToBody="false" at="left bottom" dynamic="false" for="button" id="j_idt228" inView="true" my="left bottom" rendered="true" transient="false" widgetVar="panel_">
<DataTable currentPageReportTemplate="{totalRecords} records found" draggableColumns="false" editable="false" emptyMessage="No records found." filterEvent="keyup" first="0" id="table" inView="true" lazy="false" liveScroll="false" pageLinks="10" paginator="true" paginatorAlwaysVisible="true" paginatorPosition="bottom" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rendered="true" resizableColumns="false" rowIndex="-1" rowStatePreserved="false" rows="10" rowsPerPageTemplate="5,10,15" scrollHeight="-2147483648" scrollRows="0" scrollWidth="-2147483648" scrollable="false" selectionMode="single" sortOrder="ascending" transient="false" var="item">
<Column colspan="1" disabledSelection="false" filterBy="false" filterMatchMode="startsWith" filterMaxLength="2147483647" filterPosition="bottom" headerText="entity" id="j_idt229" inView="true" rendered="true" resizable="true" rowspan="1" transient="false" width="-1">
#{item}
</Column>
</DataTable>
</OverlayPanel>
</HtmlPanelGroup>
</HtmlPanelGrid>
</UIColumn>
</HtmlDataTable>
</HtmlForm>
for this reason i'm thinking about using <c:forEach> instead of parent dataTable to make every row explicit in component tree.
but the first problem is that testBean is #ViewScoped...
and the second is that using <c:forEach> causes a Java Heap Space error...
some hint?
Give the outer table a fixed id.
<h:dataTable id="table" ...>
Then you'll be able to use
<p:ajax ... update=":form:table:value" />
Related
I have a Primefaces 5.1 tabular UI on front-end.
Each row has upload button.
When browsed and selected file at a particular row, the upload button becomes active at the last row.
It needs to be active where the file is browsed and selected.
There seems to be a javascript bug while using the file uploader combined with tabular UI.
The upload button works(other than its UI at a different row) and the file is uploaded to the right row(the row that the file was browsed previously).
<h:panelGroup rendered="#{datas.attach_doc_ids==null}">
<p:growl id="uploadMSG" showDetail="true"/>
<p:fileUpload
previewWidth="0"
process="data_tab"
id="file_upper"
styleClass="fileUploadStyle"
onstart="showloader();"
oncomplete="hideloader();"
auto="false"
mode="advanced"
label=""
dragDropSupport="false"
widgetVar="fileUploader"
fileUploadListener="#{datasBean.submitUploadedFile}"
allowTypes="/(\.|\/)(gif|jpe?g|png|pdf|doc|docx|doc)$/"
onerror="console.log('bad file type!');"
update="uploadMSG"/>
<script>
registerRowClickForFileUpload(#{indexvar});
</script>
</h:panelGroup>
Would you know what might be causing this?
Also the datatable definition below:
styleClass="wr_datatable"
id="data_tab"
paginatorPosition="bottom"
var="datas"
value="#{datasBean.listDatas}"
widgetVar="dataTable"
emptyMessage="No data found. Please change the search criteria above."
paginator="true"
selection="#{datasBean.selectedData}"
rowKey="#{datas.data_pk}"
selectionMode="single"
rowIndexVar="indexvar"
draggableColumns="true"
resizableColumns="true"
paginatorTemplate="{CurrentPageReport}
{FirstPageLink}
{PreviousPageLink}
{PageLinks}
{NextPageLink}
{LastPageLink}
{RowsPerPageDropdown}"
rows="10"
rowsPerPageTemplate="5,10,15,20"
Datatable:
<p:column headerText="Status" width="150"
sortBy="#{datas.data_status}">
<p:selectOneMenu value="#{datas.data_status}" onchange="selectme(#{indexvar});">
<f:selectItem itemValue="0" />
<f:selectItem itemValue="1" />
<f:selectItem itemValue="2" />
<f:selectItem itemValue="3" >
<f:selectItem itemValue="5" />
<f:selectItem itemValue="4" />
<p:ajax event="change"
async="true"
process="#form"
global="true"
update="data_tab"
listener="#{datasBean.updatedataStatus}">
<f:setPropertyActionListener value="#{datas}"
target="#{datasBean.selecteddata}"/>
</p:ajax>
</p:selectOneMenu>
</p:column>
<p:column headerText=“name” sortBy="#{datas.name}" ><h:outputText value="#{datas.name}"/></p:column>
<p:column headerText=“dob"><h:outputText value="#{datas.date_of_birth}"/></p:column>
<p:column headerText=“number” sortBy="#{datas.number}" ><h:outputText value="#{datas.number}”/></p:column>
<p:column headerText=“date” sortBy="#{datas.data_datetime}"><h:outputText value="#{datas.data_datetime}"/></p:column>
<p:column headerText=“second name“ sortBy="#{datas.second_name}”>
<h:outputText value="#{datas.second_name}”/>
</p:column>
<p:column headerText="Institution" sortBy="#{datas.institution}">
<h:outputText value="#{datas.institution}"/>
</p:column>
<p:column headerText="Documents" >
<p:graphicImage library="images"
name="attach-doc-exist.png"
title="Open Attachement Document"
onclick="selectme(#{indexvar});
openDocJS(‘ATTACHEMET_DOCUMENT');"
rendered="#{datas.attach_doc_ids!=null}"/>
<h:panelGroup rendered="#{datas.attach_doc_ids==null}">
<p:growl id="uploadMSG" showDetail="true"/>
<p:fileUpload
previewWidth="0"
process="data_tab"
id="file_upper"
styleClass="fileUploadStyle"
onstart="showloader();"
oncomplete="hideloader();"
auto="false"
mode="advanced"
label=""
dragDropSupport="false"
widgetVar="fileUploader"
fileUploadListener="#{datasBean.submitUploadedFile}"
allowTypes="/(\.|\/)(gif|jpe?g|png|pdf|doc|docx|doc)$/"
onerror="console.log('bad file type!');"
update="uploadMSG"/>
<script>
registerRowClickForFileUpload(#{indexvar});
</script>
</h:panelGroup>
<p:remoteCommand name="openMedicalReport"
global="true"
async="true"
actionListener="#{datasBean.manageReport}"/>
<p:remoteCommand name="lockFile"
global="true"
async="true"
actionListener="#{datasBean.manageFilePermission}"/>
</p:column>
<p:column headerText="MOD" width="30">
<h:outputText value="#{datas.data_mods}"/>
</p:column>
<p:ajax event="rowSelect" async="true" global="false">
<f:setPropertyActionListener target="#{datasBean.selecteddata}" value="#{datas}" />
</p:ajax>
</p:dataTable>
Replaced the widgetVar with a dynamically generated value to get unique file upload widget which fixed the issue as suggested by the comments above :)
<h:panelGroup rendered="#{datas.attach_doc_ids==null}">
<p:growl id="uploadMSG" showDetail="true"/>
<p:fileUpload
previewWidth="0"
process="data_tab"
id="file_upper"
styleClass="fileUploadStyle"
onstart="showloader();"
oncomplete="hideloader();"
auto="false"
mode="advanced"
label=""
dragDropSupport="false"
widgetVar="#{datas.data_pk}"
fileUploadListener="#{datasBean.submitUploadedFile}"
allowTypes="/(\.|\/)(gif|jpe?g|png|pdf|doc|docx|doc)$/"
onerror="console.log('bad file type!');"
update="uploadMSG"/>
<script>
registerRowClickForFileUpload(#{indexvar});
</script>
</h:panelGroup>
I'm having a problem with primefaces ui. It doesnt render icon that it was supposed to be rendered when I use and the problem is not happening only on this but also on many other pages. I haven't used jquery.
I dont know what's wrong. Googled it but didnt find an answer.
Here is my code
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
template="/WEB-INF/faces/template.xhtml"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:jsf="http://xmlns.jcp.org/jsf" xmlns:p="http://primefaces.org/ui"
xmlns:prettyfaces="http://ocpsoft.com/prettyfaces">
<ui:param name="title" value="List of Employee"/>
<ui:define name="breadcrum1">
<li><h:link value="Employee Management" outcome="pretty:home"/></li>
<li><h:link value="List Employee Record" outcome="pretty:list_employee"/></li>
</ui:define>
<ui:define name="content">
<div class="container">
<div class="row">
<div class="col-xs-10 col-md-10 span3">
<p:messages id="messages" autoUpdate="true" closable="true" globalOnly="true" style="text-align: center;"/>
<h:form id="form">
<p:dataTable
class="panel-primary table table-condensed"
var="employee" value="#{dtLazyView.lazyModel}" paginator="true" rows="10"
emptyMessage="No Employee found with given criteria"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{dtLazyView.selectedEmployee}" widgetVar="employeeTable" lazy="true">
<f:facet name="header">
Employee Information
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter" onkeyup="PF('employeeTable').filter()" style="width:150px" placeholder="Enter keyword"/>
</f:facet>
<p:column headerText="Id">
<h:outputText value="#{employee.employeeCode}" />
</p:column>
<p:column headerText="Employee Name">
<h:outputText value="#{employee.employeeName}" />
</p:column>
<p:column headerText="Employee Mobile Number">
<h:outputText value="#{employee.contact.mobileNumber}" />
</p:column>
<p:column headerText="Employee Role" >
<h:outputText value="#{employee.detail.employeeRole}" />
</p:column>
<p:column headerText="Option">
<h:commandButton action="#{employeeEditController.loadData(employee)}" value="Edit" class="btn btn-primary" style="margin-left: 40px;"> <f:ajax execute="#form"/></h:commandButton>
<p:commandButton update=":form:employeeDetail" oncomplete="PF('employeeDialog').show()" icon="ui-icon-search" title="View">
<f:setPropertyActionListener value="#{employee}" target="#{dtLazyView.selectedEmployee}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Employee Info" widgetVar="employeeDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false" styleClass="">
<p:outputPanel id="employeeDetail" style="text-align:center;">
<p:panelGrid columns="2" rendered="#{not empty dtLazyView.selectedEmployee}" columnClasses="label,value">
<f:facet name="header">
<img src="../../imageshandler/#{dtLazyView.selectedEmployee.employeePicture}" class="img-responsive" style="width:200px;height: 200px;margin-left: 100px;border-radius: 50%"/>
</f:facet>
<h:outputText value="Name :" style="color: black"/>
<h:outputText value="#{dtLazyView.selectedEmployee.employeeName}" />
<h:outputText value="DOB :" style="color: black"/>
<h:outputText value="#{dtLazyView.selectedEmployee.employeeDob}" />
<h:outputText value="Gender :" style="color: black"/>
<h:outputText value="#{dtLazyView.selectedEmployee.sex}" style="color:#{dtSelectionView.selectedCar.color}"/>
<h:outputText value="Salary : " style="color: black" />
<h:outputText value="Rs : #{dtLazyView.selectedEmployee.salary.basicSalary}" />
<h:outputText value="Working date :" style="color: black"/>
<h:outputText value="#{dtLazyView.selectedEmployee.employeeDateOfCommencement}"/>
<h:outputText value="Employee Job Specification :" style="color: black"/>
<h:inputTextarea value="#{dtLazyView.selectedEmployee.detail.jobSpecification}" readonly="true"/>
</p:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</div>
</div>
</div>
</ui:define>
According to Primefaces, you can use Font Awesome for the icons, so try replacing
icon="ui-icon-search"
with
icon="fa fa-search"
Keep in mind
Font Awesome icons are provided out of the box within PrimeFaces. In
order to enable Font Awesome support, enable primefaces.FONT_AWESOME
setting as true via a context param.
jsf Code:
<p:dataTable styleClass="patientlistcolumns" id="patienttable" value="#{patientsBean.rows}" var="patientData"
emptyMessage="#{bundle.noRecordsFound}" paginator="true"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="20,50,100" rows="20" paginatorPosition="bottom" resizableColumns="true" resortMode="single"
draggableColumns="true" selection="#{patientsBean.selectedPatients}" rowKey="#{patientData.ID}"
paginatorAlwaysVisible="false" sortBy="#{patientsBean.sortField}">
<p:ajax event="sort" listener="#{patientsBean.onSort}"/>
<p:ajax event="rowSelect" listener="#{patientsBean.onRowSelect}" />
<p:ajax event="colReorder" listener="#{patientsBean.onReorder}" />
<p:ajax event="rowSelectCheckbox" update="#form" />
<p:ajax event="rowUnselectCheckbox" update="#form" />
<p:ajax event="toggleSelect" update="#form" />
<p:column selectionMode="multiple" style="width:16px;text-align:center" selectRow="false" resizable="false"
visible="#{patientsBean.multiSelectionEnabled}" />
<p:columns id="patientColumns" var="columnIndex" value="#{patientsBean.columnIndices}"
sortBy="#{patientData.getColumnValue(columnIndex).sortValue}">
<ui:param name="column" value="#{patientData.getColumnValue(columnIndex)}" />
<f:facet name="header">
<h:outputText value="#{patientsBean.getColumnName(columnIndex)}" />
</f:facet>
<p:column rendered="#{column.displayType == 'TEXT' or column.displayType == 'LINK'}">
<h:outputText value="#{column.value}" />
</p:column>
</p:columns>
</p:dataTable>
bean Code:
public void onSort(SortEvent event) {
onSort(event, MY_P);
}
as soon as I add the ajax event, sorting doesn't work anymore. Nothing happens and listener i not called.
Without ajax sorting works fine.
Any solution proposals? Would be great :)
I need to save the sorting, so I really need the ajax listener.
I got it solved by changing the onSort(SortEvent event) to onSort(AjaxBehaviourEvent event) in the backend.
You can cast it to SortEvent later on..
Sad that it's explained different on showCases
I am using a complex datatable that can sort and filter with various filter. my problem is as I try to use column filter, global filter or sorting datatable pagination suddenly drops to 1 page and it doesn't turn back to first state with pagination. At the beginning I have 92 pages but after filtering/sorting it becomes a datatable with 1 page, even though I clear the textbox of filter it stays as 1 page.
Here is my datatable:
<h:panelGroup rendered="#{projectsController.items.rowCount > 0}">
<p:growl id="growl" />
<p:dataTable id="datatable" value="#{projectsController.items}" var="item" filterEvent="keyup"
paginator="true" rows="5" emptyMessage="Proje bulunamadı." paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="4,5,6,7,8,9,10"
filteredValue="#{projectsController.filteredProjects}" style="font-size:11px;font-weight: bold;" widgetVar="proj" >
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Tüm Alanlarda Ara: " />
<p:inputText id="globalFilter" onkeyup="proj.filter();" style="width:150px" />
</p:outputPanel>
</f:facet>
<p:column id="c1" headerText="Proje Adı" width="500" filterStyle="display:none" styleClass="wrap" sortBy="#{item.projectname}" filterBy="#{item.projectname}" filterMatchMode="contains" >
<h:outputText value="#{item.projectname}"/>
</p:column>
<p:column headerText="İlçe" width="150" styleClass="wrap" filterStyle="display:none" filterBy="#{item.district}" sortBy="#{item.district}" filterOptions="#{populator.districtsDD}" filterMatchMode="exact">
<h:outputText value="#{item.district}"/>
</p:column>
<p:column headerText="Sektör" width="150" styleClass="wrap" filterStyle="display:none" filterBy="#{item.sector}" sortBy="#{item.sector}" filterOptions="#{populator.sectorsDD}" filterMatchMode="exact">
<h:outputText value="#{item.sector}"/>
</p:column>
<p:column headerText="Başlangıç Tarihi" width="150" styleClass="wrap" filterStyle="display:none" sortBy="#{item.startdate}" filterBy="#{item.startdate}" filterMatchMode="contains">
<h:outputText value="#{item.startdate}"/>
</p:column>
<p:column headerText="Bitiş Tarihi" width="150" styleClass="wrap" filterStyle="display:none" sortBy="#{item.enddate}" filterBy="#{item.enddate}" filterMatchMode="contains">
<h:outputText value="#{item.enddate}"/>
</p:column>
<p:column headerText="İş Durumu" width="150" styleClass="wrap" filterStyle="display:none" sortBy="#{item.workstatus}" filterBy="#{item.workstatus}" filterMatchMode="contains">
<h:outputText value="#{item.workstatus}"/>
</p:column>
<p:column>
<p:commandButton id="selectButton" update=":display" oncomplete="carDialog.show()" icon="ui-icon-search" title="Detayları Gör">
<f:setPropertyActionListener value="#{item}" target="#{projectsController.selectedP}" />
<p:ajax event="click" update=":viewTabs:tabView:mapTab"/>
</p:commandButton>
<p:commandButton id="editButton" update=":displayEdit" oncomplete="editDialog.show()" icon="ui-icon-pencil" title="Düzenle">
<f:setPropertyActionListener value="#{item}" target="#{projectsController.selectedP}" />
</p:commandButton>
<p:commandButton update="growl" title="Projeyi Sil" id="confirm" action="#{projectsController.destroy}" icon="ui-icon-trash" ajax="false" onclick="if (!confirm('Bu projeyi gerçekten silmek istiyor musunuz?'))
return false;"/>
</p:column>
</p:dataTable>
After filtering or sorting how can I reset my datatable to first state? Thanks in advance.
Primefaces 3.5, Oracle WebLogic 10g, JSF 2.2
Here is the snapshot:
![enter image description here][1]
For those who want to know solution, I have removed both jsf-api.jar and jsf-impl.jar from the libraries instead I have put netbeans' own jsf2.1 library. Basically I have downgraded to jsf2.1. I just suspect if jsf-api and jsf-impl gives me the support of jsf2.2.
Hope this helps to someone.
In my application I have a <p:dataTable> with pagination and LazyDatamodel, and at the bottom of the form I have a CommandButton
named update by which I can save the edited rows.
Problem is :
1. When from one page user want to leave the page with out saving edited rows then I want to propagate the fired page event and stay on the current page
not to leave the page , and if there are no change in the current page at that case user can leave the page.
Code of .xhtml is given below :
<h:form id="userListForm">
<p:panel id="userListPanel" header="#{adbBundle['userList.panel.header']}" toggleable="true">
<p:dataTable var="user" id="userTable" value="#{userDataModel}" lazy="true" paginator="true" rows="25" paginatorPosition="bottom"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="25,50,100" widgetVar="userDataTable" styleClass="userTable" selectionMode="single" >
<f:facet name="header">
<p:outputPanel>
<h:panelGroup layout="block" id="resetFiter" styleClass="dataTableResetFilter">
<p:outputLabel value="#{adbBundle['filter.resetText']}" />
<p:spacer width="10" />
<p:commandButton icon="ui-icon-circle-close" actionListener="#{userListController.resetUserTable}" />
</h:panelGroup>
</p:outputPanel>
</f:facet>
<p:column id="nameColumn" headerText="#{adbBundle['name']}" sortBy="#{user.fullName}" filterBy="#{user.fullName}" styleClass="userName">
<h:outputText value="#{user.fullName}" />
</p:column>
<p:column id="statusColumn" headerText="#{adbBundle['status']}" sortBy="#{user.active}" filterBy="#{user.statusText}" filterMatchMode="exact" styleClass="manageStatus"
filterOptions="#{userListController.statusOptions}" rendered="#{manageUser != null and manageUser != ''}">
<h:panelGroup layout="block">
<p:selectOneRadio id="userRadio" value="#{user.statusText}" styleClass="roleRadio">
<f:selectItem itemLabel="#{adbBundle['active']}" itemValue="Active" />
<f:selectItem itemLabel="#{adbBundle['inactive']}" itemValue="Inactive" />
<p:ajax listener="#{userListController.changeStatus}" />
<f:attribute name="user" value="#{user}" />
</p:selectOneRadio>
</h:panelGroup>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
How it can be implemented? Any pointer will be very helpful to me. Thanks..