p:dataTable selection executes without any reason - jsf

When I click "create" button Primefaces executes controller.selectedTableItem method, why? I'm not even updating datatable?
<p:panel header="#{title}">
<p:toolbar>
<f:facet name="left">
<p:commandButton id="createButton" icon="ui-icon-plus"
value="#{localization.Create}" ajax="true"
update=":ShipmentFormDiv editButton viewButton">
<p:confirm header="#{localization.ConfirmationHeader}"
message="#{localization.ConfirmCreateMessage}"
icon="ui-icon-alert" />
</p:commandButton>
</f:facet>
</p:toolbar>
<p:dataTable id="datalist" widgetVar="datalist"
value="#{controller.lazyItems}" lazy="true" var="item"
paginator="true" rows="10" rowsPerPageTemplate="10,20,30,40,50"
selectionMode="single" selection="#{controller.selectedTableItem}"
paginatorPosition="bottom" reflow="true"
rowStyleClass="#{item.rowStyleClass}">
<p:ajax event="rowSelect"
update="#form:createButton,#form:viewButton,#form:editButton,#form:deleteButton,#form:InboundShipmentDataTableContextMenu,:ShipmentFormDiv, #form:timeline"
listener="#{controller.onSelect}" />
<p:ajax event="rowUnselect"
update="#form:createButton,#form:viewButton,#form:editButton,#form:deleteButton,#form:InboundShipmentDataTableContextMenu, :ShipmentFormDiv"
listener="#{controller.onUnselect}" />
<p:ajax event="contextMenu"
update="#form:createButton #form:viewButton #form:editButton #form:deleteButton"
listener="#{controller.onContextMenu}" />
<p:ajax event="rowDblselect"
onsuccess="document.getElementById('ShipmentListForm:viewButton').click();" />
<ui:include src="/admin/templates/columns/office.xhtml">
</ui:include>
</p:dataTable>
</p:panel>

I tkink it was because p:commandButton processes every component in ancestor form. It seems that process="#none" helps.
<p:commandButton id="createButton" icon="ui-icon-plus"
value="#{localization.Create}"
actionListener="#{controller.prepareCreate}"
update=":ShipmentFormDiv,:ShipmentListForm, editButton, viewButton"
process="#none">
<p:confirm header="#{localization.ConfirmationHeader}"
message="#{localization.ConfirmCreateMessage}"
icon="ui-icon-alert" />
</p:commandButton>

Related

DataTable isnt editable after i switch the tabs

I'm nesting a datable in tabview. On the first page its all working correctly and i can edit the table, but after i switch the tabs, the datatable isnt editable anymore.
Is there something i'm doing wrong?
Using Primefaces 5.3
<h:form id="form">
<p:tabView id="tabs" value="#{studentsTableView.exams}" activeIndex="#{studentsTableView.activTab}" dynamic="true" var="exam" binding="#{tabView}" cache="false" >
<p:ajax event="tabChange" update="form:tabs" />
<p:tab id="tab" title="#{exam.name}">
<p:dataTable id="students" rowIndexVar="rowIndex" var="student" editable="true" widgetVar="gradetable" editMode="cell" tableStyle="width:auto" styleClass="myTable" value="#{studentsTableView.students}">
<p:ajax event="cellEdit" update="students" />
<p:column headerText="Nr">
<h:outputText value="#{rowIndex+1}" />
</p:column>
<p:column headerText="Vorname">
<h:outputText value="#{student.vorname}" />
</p:column>
<p:column headerText="Nachname">
<h:outputText value="#{student.nachname}" />
</p:column>
<p:column headerText="Matrikelnummer">
<h:outputText value="#{student.matrikelnummer}" />
</p:column>
<p:columns value="#{exam.allExams}" var="subexam" columnIndexVar="colIndex">
<f:facet name="header">
<h:outputText value="#{subexam.examName}" />
</f:facet>
<p:cellEditor>
<f:facet name="output"><h:outputText id="modeloutput" value="#{studentsTableView.getGrade(subexam, student)}" /></f:facet>
<f:facet name="input"><p:inputText id="modelInput" value="#{studentsTableView.currentGrade}" valueChangeListener="#{studentsTableView.insertGrade(subexam, student)}" style="width:90%">
<p:ajax event="change" update="modelInput" />
<p:ajax event="change" update="modeloutput" />
<p:ajax event="change" update="modeloutput" />
<p:ajax event="change" update=":form:tabs:0:students" />
</p:inputText></f:facet>
</p:cellEditor>
</p:columns>
<p:column id="endgrades" headerText="Endnote">
<h:outputText id="endgrade" value="#{studentsTableView.getEndGrade(exam, student)}" />
</p:column>
<p:column headerText="Formel">
<p:selectBooleanButton id="value1" value="true" onLabel="Yes" offLabel="No" style="width:60px" />
</p:column>
<p:column headerText="Kommentar">
<p:commandButton id="public" icon="ui-icon-comment" type="button" >
<p:ajax event="click" listener="#{studentsTableView.setPublicCommentInfos(exam, student)}" update="publicarea" />
</p:commandButton>
<p:overlayPanel id="imagePanel" for="public" hideEffect="fade">
<h:inputTextarea id="publicarea" value="#{studentsTableView.publicComment}" >
<p:ajax event="change" update="publicarea" />
</h:inputTextarea>
</p:overlayPanel>
<p:commandButton id="private" icon="ui-icon-locked" type="button" >
<p:ajax event="click" listener="#{studentsTableView.setPrivateCommentInfos(exam, student)}" update="privatearea" />
</p:commandButton>
<p:overlayPanel id="privatepanel" for="private" hideEffect="fade">
<h:inputTextarea id="privatearea" value="#{studentsTableView.privateComment}" >
<p:ajax event="change" update="privatearea" />
</h:inputTextarea>
</p:overlayPanel>
</p:column>
</p:dataTable>
</p:tab>
</p:tabView>
</h:form>
Your problem could be because you're still referencing the datatable id from the first tab, even though you switched to another. You could try to create a different id for each datatable from each tab and then working with those ids and updating them.

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>

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"/>

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

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>

update inputtext via dialog

Please help me to find a example to update p:inputtext with data stored in a bean which is set(solved already) by selecting a row of a datatable of a p:dialog. I have succeeded updating outputtext in the same manner.
I am using (learning) netbeans 7.2 primefaces 3.2, glassfish 3.1
thansk for all your help
rs_ncs
Look at primefaces showcase and the user guide, you'll find everything you need; in detail search for rowSelect event for the datatable component. Good luck =)
If you would like to update a component on select of a row from a datatable, then you can use the update attribute of a <p:ajax> which is listening on rowselect event. Something like this:
<p:ajax event="rowSelect" update=":xx:xx" />
As Suggested by BalusC the code <p:ajax event="rowSelect" update=":xx:xx" /> should work....
Here is an example of updating both inputtext and outputtext .
<h:form>
<p:dataTable id="usertable" var="user" value="#{userManageBean.userList}"
rowKey="#{user.U_ID}" selection="#{userManageBean.selectedUser}"
selectionMode="single" paginator="true" rows="18" >
<p:ajax event="rowSelect" update=":useredit:edituser" />
<p:ajax event="rowSelect" update=":viewuser:displayuser" />
<p:column headerText="User Name">
<h:outputText value="#{user.username}" />
</p:column>
<p:column headerText="FName">
<h:outputText value="#{user.firstname}" />
</p:column>
<p:column headerText="LName">
<h:outputText value="#{user.lastname}" />
</p:column>
</p:dataTable>
</h:form>
<p:dialog id="userview" header="View User" widgetVar="dlg2" >
<h:form id="viewuser">
<h:panelGrid id="displayuser" columns="2" cellpadding="4">
<h:outputText value="User Name:" />
<h:outputText value="#{userManageBean.selectedUser.username}" />
<h:outputText value="First Name" />
<h:outputText value="#{userManageBean.selectedUser.firstname}" />
<h:outputText value="Last Name:" />
<h:outputText value="#{userManageBean.selectedUser.lastname}" />
</h:panelGrid>
</h:form>
</p:dialog>
<p:dialog id="user_edit" header="Edit User" widgetVar="dlgedit" >
<h:form id="useredit">
<h:panelGrid id="edituser" columns="2" cellpadding="4">
<h:outputText value="First Name" />
<h:inputText value="#{userManageBean.selectedUser.firstname}" />
<h:outputText value="Last Name" />
<h:inputText value="#{userManageBean.selectedUser.lastname}" />
<p:commandButton id="updateUser" value="Add" action="#{someaction}"
ajax="false" />
</h:panelGrid>
</h:form>
</p:dialog>

Resources