How to increment visible rows of p:datatable with p:outputLink - jsf

I want increment visible rows of p:dataTable when click on p:outputLink. Here is picture:
and my code is:
<p:dataTable value="#{tasks}" styleClass="dashTable"
var="tasklar" rows="5" lazy="true"
selection="#{flowScope.selectedTask}" selectionMode="single" >
<p:ajax event="rowSelect" />
<p:column headerText="#{messages.label_task_temasy}">
<h:outputText value="#{tasklar.taskTemasy}"/> </p:column>
</p:dataTable>
Thank`s for help.

I have resolved my problem. Here is code:
<h:form id="dataForm">
<p:dataTable value="#{tasks}" styleClass="dashTable"
var="tasklar" rows="#{taskCriteria.pageSize}" lazy="true"
selection="#{flowScope.selectedTask}" selectionMode="single" >
<p:ajax event="rowSelect" />
<p:column headerText="#{messages.label_task_temasy}">
<h:outputText value="#{tasklar.taskTemasy}"/> </p:column>
</p:dataTable>
<p:commandLink style="float:left" update=":dataForm"
action="#{taskCriteria.setPageSize(taskCriteria.pageSize+5)}">
<h:outputText value="Show more..." />
</p:commandLink>
</h:form>

Related

cannot show header text of primefaces datatable

I have the below code, but find that the headerText doesn't show. Any advice?
<p:dataTable var="toDoList" value="#{dtView}" tableStyle="width:auto" >
<p:columnGroup type="header">
<p:row><p:column headerText="#{toDoList.schoolScrn}">
<p:outputLabel value="#{toDoList.schoolScrn}" />
</p:column></p:row>
</p:columnGroup>
<p:column>
<p:dataTable var="info" value="#{toDoList.infoList}" >
<p:column >
<h:outputText value="#{info}" />
</p:column>
</p:dataTable>
</p:column>
</p:dataTable>

Select row when a selectOneMenu changes

When I change the value of the selectOneMenu I need to set the row in the backing bean and update a button which is in the same row.
<p:dataTable
id="dataTableId" rowIndexVar="rowIndex" rowKey="#{record.id}"
rows="10" selection="#{bean.selectedRecord}" selectionMode="single"
value="#{bean.allRecords}" var="record" widgetVar="dataTableWV">
<p:column>
<p:selectOneMenu converter="omnifaces.SelectItemsConverter"
id="selectOnMenuId" value="#{bean.recordDTO}">
<f:selectItems
itemLabel="#{status.name}" itemValue="#{status.id}" value="#{bean.statusList}" var="status" />
<p:ajax event="change" update="saveButtonId">
<f:setPropertyActionListener target="#{bean.selectedRecord}" value="#{record}" />
</p:ajax>
</p:selectOneMenu>
</p:column>
<p:column>
<p:commandButton action="#{bean.someMethod}" icon="ui-icon-disk" id="saveButtonId" update="someId"/>
</p:column>
</p:dataTable>
Edit #Tiny suggestions:
<p:dataTable
id="dataTableId" rowIndexVar="rowIndex" rowKey="#{record.id}"
rows="10" selection="#{bean.selectedRecord}" selectionMode="single"
value="#{bean.allRecords}" var="record" widgetVar="dataTableWV">
<p:ajax event="rowSelect"
listener="#{bean.anotherMethod(record)}"
update="somesIds" />
<p:column>
<p:selectOneMenu converter="omnifaces.SelectItemsConverter"
id="selectOnMenuId" value="#{bean.recordDTO}">
<f:selectItems
itemLabel="#{status.name}" itemValue="#{status.id}" value="#{bean.statusList}" var="status" />
<p:ajax event="change"
listener="#{bean.anotherMethod(record)}"
update="saveButtonId" />
</p:selectOneMenu>
</p:column>
<p:column>
<p:commandButton action="#{bean.someMethod}" icon="ui-icon-disk" id="saveButtonId" update="someId"/>
</p:column>
</p:dataTable>

DataList data in one Row

I want to show the data from an DataList in one row. Here is a picture to show what I want to do https://www.dropbox.com/s/p7pcn67bt0304lo/pic.JPG
I use primefaces 4.0 and jsf 2.1
<p:dataTable id="sentTable" var="task" value="#{taskboxBean.taskboxSentList}" paginator="true"
rows="5" selection="#{taskboxBean.selectedTaskbox}" selectionMode="single" rowKey="#{task.ID}"
paginatorPosition="bottom" emptyMessage="">
<p:ajax event="rowSelect"
update=":contentForm, :postForm:tabViewPosts:trashTable, :postForm:tabViewPosts:inboxTable, :postForm:tabViewPosts:sentTable"
listener="#{taskboxBean.onTaskboxRowSelect}" />
<p:column headerText="Post">
<p:dataGrid var="task_to_user" value="#{task.TASKBOX_TO_USERS}" emptyMessage="Keine Daten">
<p:scrollPanel>
<p:outputLabel
value="#{task_to_user.USER.FIRST_NAME} #{task_to_user.USER.LAST_NAME} #{task_to_user.USER.EMAIL}" />
</p:scrollPanel>
</p:dataGrid>
<h:outputText value="#{task.TASKTYPE.NAME}" />
<br />
<h:outputText value="#{task.CREATE_TIMESTAMP}" />
</p:column>
</p:dataTable>
try This
<p:dataGrid var="task_to_user" value="#{task.TASKBOX_TO_USERS}" emptyMessage="Keine Daten" rows="1" />
Assigning 1 row only

Primefaces 3.5 DataTable Single Selection does not work with ContextMenu

I tried to make a <p:dataTable> with <p:contextMenu> using primefaces 3.5 on Mojarra 2.2.1.
The ContextMenu Code :
<p:contextMenu for="actionnairesDT">
<p:menuitem value="View" update="displayActionnaires" icon="ui-icon-search" oncomplete="actDialog.show()"/>
<p:menuitem value="Delete" update="actionnairesDT" icon="ui-icon-close" />
</p:contextMenu>
the problem is that the dialog box is displayed empty.
I tried to show my object in the setter setSelecedActionnaire(), it displays nothing
not even null.
public void setSelectedActionnaire(Actionnaires selectedActionnaire) {
System.out.println(selectedActionnaire);
this.selectedActionnaire = selectedActionnaire;
}
<p:dataTable> and <p:dialog> code is below. thank you in advance for your help !
<p:dataTable id="actionnairesDT" paginatorPosition="bottom"
pageLinks="10" paginator="true" rows="20" value="#{actionnairesBean.actionnairesList()}" var="actionnaires"
rowKey="#{actionnaires.nomAct}" selection="#{actionnairesBean.selectedActionnaire}" selectionMode="single"
>
<p:ajax event="rowSelect" update="actionnairesDT" oncomplete="actDialog.show()" />
<p:column sortBy="#{actionnaires.actionnairesPK.codeAct}" headerText="N°">
#{actionnaires.actionnairesPK.codeAct}
</p:column>
<p:column headerText="Nom" sortBy="#{actionnaires.nomAct}">
#{actionnaires.nomAct}
</p:column>
<p:column>
#{actionnaires.quatiteAct}
</p:column>
<p:column headerText="Sicav">
#{actionnaires.actionnairesPK.codeSicav}
</p:column>
</p:dataTable>
<p:dialog header="Détail Actionnaire" widgetVar="actDialog" resizable="false"
showEffect="clip" hideEffect="fold" id="actDialog" closable="true" modal="true">
<h:panelGrid id="displayActionnaires" columns="2" cellpadding="4">
<h:outputText value="Nom Actionnaire"/>
<h:outputText value="#{actionnairesBean.selectedActionnaire.nomAct}"/>
<h:outputText value="Quantité"/>
<h:outputText value="#{actionnairesBean.selectedActionnaire.quatiteAct}"/>
<h:outputText value="Sicav"/>
<h:outputText value="#{actionnairesBean.selectedActionnaire.sicavs.libelleSicav}"/>
</h:panelGrid>
</p:dialog>
In the end, I found the solution
I add <p:ajax> to the <p:dataTable>:
<p:ajax event="contextMenu"/>

datatable row remains selected/highlighted where selectionMode="single"

I've been running Primefaces 3.0, no issues, and now am trying an upgrade to 3.4.x - I've tried 3.4, 3.4.1, and 3.4.2 and this problem occurs in all 3 - basically for the datatable with the selectionMode="single" option when I click on a row it remains selected no matter how many other rows I select. At the same time I'm quite sure the selection="#{databrowser.selectedData}" variable is not being set when I'm clicking on the rows. The table is fully populated and no 2 rows have the exact same data in all columns. Tested and this occurs in both Chrome and Firefox. I can't find any similar problem posted - wondering if anyone else has had this issue?
Apart from the element referencing this is the 3.0 code I've used:
<p:layoutUnit position="center" resizable="true" header="Data Set Details" styleClass="east_panel_header" >
<h:form id="tblbrowser">
<p:dataTable id="dataTable" emptyMessage="No data sets found." style="width: 100%" var="datlis" resizableColumns="true" value="#{databrowser.selectedDataModel}" widgetVar="dataTable" selection="#{databrowser.selectedData}" selectionMode="single" >
<p:ajax event="rowSelect" update=":usercomments:commentsTable, :tblbrowser:dataTable" />
<f:facet name="header" >
<p:outputPanel>
<h:outputText value="Search all fields " />
<p:inputText id="globalFilter" onkeyup="dataTable.filter()"/>
</p:outputPanel>
</f:facet>
<p:column id="owner" filterBy="#{datlis.uname}" headerText="Added By" filterMatchMode="contains" >
<h:outputText value="#{datlis.uname}" />
</p:column>
<p:column id="name" filterBy="#{datlis.name}" headerText="Name" >
<h:outputText value="#{datlis.name}" />
</p:column>
<p:column id="description" filterBy="#{datlis.description}" headerText="Description" filterMatchMode="endsWith" >
<h:outputText value="#{datlis.description}" />
</p:column>
<p:column id="datatype" filterBy="#{datlis.data_type}" headerText="Data Type"
filterOptions="#{databrowser.dataTypeOptions}" filterMatchMode="exact" >
<h:outputText value="#{datlis.data_type}" />
</p:column>
<p:column id="quality" filterBy="#{datlis.quality}" headerText="Source Type"
filterOptions="#{databrowser.qualityOptions}" filterMatchMode="exact" >
<h:outputText value="#{datlis.quality}" />
</p:column>
<p:column id="added" headerText="Date Added" filterMatchMode="endsWith" >
<h:outputText value="#{datlis.added}" />
</p:column>
<p:column headerText="Metadata" style="width:40px" >
<p:commandButton id="selectButton" rendered="#{datlis.has_metadata}" icon="ui-icon-circle-arrow-s" title="View" ajax="false" >
<f:param name="filepath" value="#{datlis.filepath}" />
<p:fileDownload value="#{filedownloader.mfile}" />
</p:commandButton>
</p:column>
<p:column headerText="Data File(s)" style="width:90px" >
<p:commandButton id="selectButton2" rendered="#{datlis.has_datafiles}" icon="ui-icon-circle-arrow-s" title="View" ajax="false" >
<f:param name="datafiles" value="#{datlis.datafiles}" />
<p:fileDownload value="#{filedownloader2.dfile}" />
</p:commandButton>
<h:outputText value=" " />
<h:outputText value="#{datlis.zipsize}" />
</p:column>
</p:dataTable>
</h:form>
</p:layoutUnit>
You are missing the rowKey attribute which should be the unique identifier of each row.
Example, if your selectedData object has a unique field id, your dataTable component should look like:
<p:dataTable id="dataTable" rowKey=#{datlis.id}
value="#{databrowser.selectedDataModel}" var="datlis"
selection="#{databrowser.selectedData}" selectionMode="single" >
No need to update the same table within p:ajax to see the selection, so you can probably remove the :tblbrowser:dataTable from the update target and have only:
<p:ajax event="rowSelect" update=":usercomments:commentsTable" />

Resources