complete action then update table jsf - jsf-2

What I want is commandButton should complete the action first and then update dataTable, but it is actually updating dataTable before the action is performed. Can someone please suggest how to do this?. Thanks.
<p:dataTable id="files" var="file" value="#{tableBean.lstFiles}" rowKey="#{file.fname}" selection="#
{tableBean.selectedFile}" selectionMode="single" >
<p:ajax event="rowSelect" listener="#{tableBean.onRowSelect}" />
<p:ajax event="rowUnselect" listener="#{tableBean.onRowUnselect}"/>
<p:column headerText="Date"> #{file.fname}</p:column>
<p:column headerText="Type"> #{file.ftype}</p:column>
<p:column headerText="Date"> #{file.fdate}</p:column>
<p:column headerText="View File" >
<p:commandButton id="folder" action="#{folderName.name}" value="Open" update=":form2:files" icon="ui-icon-arrowthichk-s" >
<f:setPropertyActionListener target="#{folderName.foldername}" value="#{file.fname}" />
</p:commandButton>
</p:column>
</p:dataTable>

Related

primefaces datatable checkbox multiselection not updating

Hi in my project:JSF2 with primefaces 5.0, I need to select multiple rows on a datatable and display some data about this selection, as far I can do selection with checkbox, the listener on my back bean is getting fired, but the page does not update, but if I refresh it with F5 it renders correctly. This is how the datatable is defined:
<p:dataTable var="rowItem" scrollWidth="100%" scrollHeight="450"
value="#{fileMatchMB.homeList}"
selection="#{fileMatchMB.selectedHomes}"
rowKey="#{rowItem.pk_num}">
<f:facet name="header">
Home
</f:facet>
<p:ajax event="rowUnselectCheckbox"
ajax="true"
immediate="true"
listener="#{fileMatchMB.onRowUnSelectHome}" />
<p:ajax event="rowSelectCheckbox"
ajax="true"
listener="#{fileMatchMB.onRowSelectHome}"
immediate="true"/>
<p:column selectionMode="multiple"
style="width:16px;text-align:center" />
<p:column headerText="Data Valuta">
<h:outputText value="#{rowItem.data}">
<f:converter
converterId="filematch.interfaccia.CalendarConverter" />
</h:outputText>
</p:column>
<p:column headerText="Importo">
<h:outputText value="#{rowItem.value}">
<o:converter converterId="javax.faces.Number"
currencySymbol="#{rowItem.getCurrencySymbol()}" type="currency" />
</h:outputText>
</p:column>
<!--<h:column>
<h:outputLabel for="hrow" value="#{rowItem.toRow()}"/> sempre 0
</h:column>-->
<p:column headerText="Causale" styleClass="scrollableCell">
#{rowItem.descrizione}:
#{rowItem.causale}
</p:column>
<f:facet name="footer">
"#{fileMatchMB.countHome} / #{fileMatchMB.homeList.size()} #{msg.msg_records}"
</f:facet>
</p:dataTable>
I am a bit confused on how make the request to the server selecting and unselecting the rows of my datatable.

Pass dataTable value of the row to new JSF using managed bean or?

How do I pass the value in my dataTable to another jsf page? I managed to pass the value by using f:param but I have no clue how to get the data in dataTable and pass the value.
<p:outputPanel id="panelSysMenuList">
<p:dataTable id="dtSysMenu" paginator="true" paginatorPosition="bottom" paginatorAlwaysVisible="true"
var="menu" styleClass="panel-list" filteredValue="#{menuController.filteredList}"
value="#{menuController.resultList}" emptyMessage="#{msg.noRecordsFound}"
rows="#{menuController.datatableMaxResult}" selection="#{menuController.selectMenu}"
widgetVar="widVarTable" rowKey="#{menu}" selectionMode="single">
<p:column sortBy="#{menu.admenuPK.parentNode}" >
#{menu.admenuPK.parentNode}
</p:column>
<p:column sortBy="#{menu.admenuPK.node}" >
#{menu.admenuPK.node}
</p:column>
<p:column sortBy="#{menu.nodeDesc}" >
#{menu.nodeDesc}
</p:column>
<p:column sortBy="#{menu.className}" >
#{menu.className}
</p:column>
<p:column sortBy="#{menu.nodeRemark}" >
#{menu.nodeRemark}
</p:column>
</p:dataTable>
</p:outputPanel>
<p:button id="btnAdd2" value="#{msg.sysMenuAdd}" icon="ui-icon-plus" styleClass="action-buttons" outcome="MenuMaint">
<f:param name="parentNode" value="#{menuController.parentNode}" />
<f:param name="node" value="#{menuController.selectMenu}" />
</p:button>
My MenuMaint
<f:metadata>
<f:viewParam name="parentNode" value="#{menuMaintController.parentNode}" />
<f:viewParam name="node" value="#{menuMaintController.node}" />
</f:metadata>
Or is that anyway that I can do?
BTW, I am using ViewScoped
Thanks in advance!
I have solved my question by adding the param at the end of my URL
MenuMaint?parentNode=parentNode&node=selected
at the managed bean of MenuMaint, I will get the param using
FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("parentNode")
this enable for me to get the value in another way than f:param

Error After Selecting dataTable

When I make selection in dataTable it gives error below
[javax.faces.FacesException: DataModel must implement org.primefaces.model.SelectableDataModel when selection is enabled or you need to define rowKey attribute]]
But in my dataTable rowKey attribute is already define and I checked it's value is unique. What could be the possible reason I am getting this error
DataTable code is as below
<p:dataTable id="scenarioDataTableId" var="scenarioDataTable" value="#{myBean.scenarioApplicationColumnBOList}" tableStyle="width:90%" rowKey="scenarioDataTable.scenarioApplicationColumnId" selection="#{myBean.selectedScenarioApplicationColumnRow}" >
<f:facet name="header">Database Columns That will be updated in this Scenario</f:facet>
<p:ajax event="rowSelectRadio" listener="#{myBean.editSelectedScenarioApplicationColumnAction}"></p:ajax>
<p:column selectionMode="single" style="width:10%" />
<p:column id="Id" headerText="Id" >
#{scenarioDataTable.scenarioApplicationColumnId}
</p:column>
<p:column id="scenarioId" headerText="Scenario Id" >
#{scenarioDataTable.scenarioId}
</p:column>
<p:column id="appId" headerText="Application Column Id" >
#{scenarioDataTable.applicationColumnId}
</p:column>
<p:column id="tableNameId" headerText="Table Name" >
#{scenarioDataTable.tableName}
</p:column>
<p:column id="columnNameId" headerText="Column Name" >
#{scenarioDataTable.columnName}
</p:column>
<p:column id="columnValidValueId" headerText="Column Valid Value" >
#{scenarioDataTable.columnValidValue}
</p:column>
<p:column id="dbActionId" headerText="DB Action" >
#{scenarioDataTable.dbAction}
</p:column>
<f:facet name="footer">
<p:commandButton value="Add New Row" action="#{myBean.openDialogScenarioUpdateColumn}" oncomplete="dialogScenarioUpdateColumn.show()" rendered="#{myBean.scenarioInputFieldRendered}"></p:commandButton>
<p:spacer width="20" ></p:spacer>
<p:commandButton id="editButton" value="Edit" action="#{myBean.editSelectedScenarioApplicationColumnAction}" update=":formSelectCriteria:ScenarioMainPanel" ></p:commandButton>
<p:spacer width="20" ></p:spacer>
<p:commandButton id="deleteButton" value="Delete"></p:commandButton>
</f:facet>
</p:dataTable>
Take a look at the Primefaces Showcase. A rowKey must refer to an attribute shown in your p:dataTable (which is an attribute of one of your #{myBean.scenarioApplicationColumnBOList} objects), e.g.
rowKey="#{scenarioDataTable.scenarioApplicationColumnId}"
but not
rowKey="scenarioDataTable.scenarioApplicationColumnId"

Primefaces dataTable instant Row Selection not working

I am working with Primefaces 3.5, Spring 3.2, JSF 2.2 and Apache is my server.
My problem is that whenever i click on the row, the row select event is never triggered in my backing bean and my store details panel is never updated.
My backing bean is in request scope and contains onRowSelect method.
However when i change my backing bean to sessions scope(it requires a few changes in backing bean), instant row selection works.
For the simplicity of my question i have modified my code to include only relevant part. In my param, for the sake of testing i just put existing customer with ID 35 in my test page.
Here is my dialog.xhtml
<h:form id="customerListingsForm">
<p:dialog id="manageStoresDialog"
header="Manage #{manageStoreBean.store.owner.name}'s Stores"
widgetVar="manageStoresDlg"
modal="true"
resizable="false">
<p:panelGrid id="storePanel" rendered="#{manageStoreBean.owner != null}">
<f:facet name="header">
<p:row>
<p:column>Store Details</p:column>
<p:column>Customer Store List</p:column>
</p:row>
</f:facet>
<p:row>
<p:column>
<p:panelGrid id="storeDetails">
<p:row>
<p:column>Name: </p:column>
<p:column>
<h:inputText value="#{manageStoreBean.store.name}" />
</p:column>
</p:row>
<p:row>
<p:column>Description: </p:column>
<p:column>
<h:inputText value="#{manageStoreBean.store.description}" />
</p:column>
</p:row>
<p:row>
<p:column>Short Code: </p:column>
<p:column>
<h:inputText value="#{manageStoreBean.store.shortCode}" />
</p:column>
</p:row>
<p:row>
<p:column>Owner name:</p:column>
<p:column>
<h:inputText value="#{manageStoreBean.store.owner.name}" readonly="true" />
</p:column>
</p:row>
<p:row>
<p:column>Store Type: </p:column>
<p:column>
<p:selectOneMenu
id="storeTypeSelected"
value="#{manageStoreBean.placeType}"
var="storeType"
style="height:25px"
converter="#{placeTypeConverter}">
<f:selectItems
value="#{manageStoreBean.typeList}"
var="storeTypeItem"
itemLabel="#{storeTypeItem.code}"
itemValue="#{storeTypeItem}"/>
<p:column>#{storeType.description}</p:column>
</p:selectOneMenu>
</p:column>
</p:row>
<p:row>
<p:column>Country: </p:column>
<p:column>
<p:selectOneMenu
id="storeCountrySelected"
value="#{manageStoreBean.country}"
var="country"
style="height:25px"
converter="#{countryConverter}">
<f:selectItems
value="#{manageStoreBean.countryList}"
var="countryItem"
itemLabel="#{countryItem.isoNumericCode}"
itemValue="#{countryItem}"/>
<p:column>#{country.isoNumericCode}</p:column>
</p:selectOneMenu>
</p:column>
</p:row>
<p:row>
<p:column>Localisation: </p:column>
<p:column>
<p:selectOneMenu
id="storeLocalisationSelected"
value="#{manageStoreBean.localisationData}"
var="storeLocal"
style="height:25px"
converter="#{localisationConverter}">
<f:selectItems
value="#{manageStoreBean.localisationList}"
var="local"
itemLabel="#{local.regionCode}"
itemValue="#{local}"/>
<p:column>#{storeLocal.id} - #{storeLocal.regionCode}</p:column>
</p:selectOneMenu>
</p:column>
</p:row>
</p:panelGrid>
</p:column>
<p:column style="width:250px">
<p:dataTable id="stores"
var="store"
value="#{manageStoreBean.storeList}"
rowKey="#{store.id}"
scrollHeight="240"
scrollable="true"
selectionMode="single"
selection="#{manageStoreBean.selectedStore}"
lazy="true">
<p:ajax event="rowSelect" immediate="true"
listener="#{manageStoreBean.onRowSelect}"
update=":customerListingsForm:storeDetails"/>
<p:column headerText="Salon Name">
<h:outputText value="#{store.name}" />
</p:column>
<p:column headerText="ID">
<h:outputText value="#{store.id}" />
</p:column>
</p:dataTable>
</p:column>
</p:row>
</p:panelGrid>
<p:commandButton
value="Save"
action="#{manageStoreBean.saveStore}"
oncomplete="manageStoresDlg.hide()">
<f:param name="storeCustomerId" value="#{manageStoreBean.owner.id}" />
</p:commandButton>
<h:outputText value=" " />
<p:commandButton
value="Close"
oncomplete="manageStoresDlg.hide()"/>
</p:dialog>
<p:commandButton value="Add Store"
oncomplete="manageStoresDlg.show()"
update=":customerListingsForm:manageStoresDialog"
process="#this">
<f:param name="storeCustomerId" value="35" />
</p:commandButton>
</h:form>
Also i'm new to primefaces and web dev, but did a lot of learning myself before i started this project.
I spent 2 days try to understand what's wrong and searched all web but could not find any solution. May be i'm missing something or doing wrong not sure.
Any help is much appreciated.
Try making your bean view scoped.
If you are making it request scoped, then you are telling JSF to throw out all of your existing data every time the user is done talking to your server. So it makes no sense to have JSF run a listener on an existing page. In particular, PrimeFaces has a tendency to malfunction when it encounters an odd set of scopes.
See also Difference between View and Request scope in managed beans
By searching a lot of stuff on the internet i came to conclusion that datatable does not work very well with backing bean in request scope when table is loaded using dynamic argument. That is very shame. I do not see any other option but to implement viewscope in spring for my beans.

Display dynamic rows with Column using Jsf 2.0 and Primefaces 3.0

I have student records which I need to display as per shown in this image.
I am using Jsf 2.0 and primefaces 3.0 , I am trying by using but still unable to get correct format.
My problem is , there is a coulmn with name Exam like FE, SE, TE which
comes under single column and there are fixed as there will be only 3
examinations.Means for first 3 columns in images need row span 3 as
each record will have FE -Math ,SE-Math and TE-Maths and... so on
marks for all s3 subjects So how can we make this structure possible
like 'for 1 record 3 rowspan' ?
How can we achieve this structure as per shown in this image ?
<p:dataTable var="s" value="#{tableBean.studentSummary}">
<p:column headerText="ID">
<h:outputText value="#{s.ID}" />
</p:column>
<p:column headerText="Name">
<h:outputText value="#{s.name}" />
</p:column>
<p:column headerText="Passing Date">
<h:outputText value="#{s.passDate}" />
</p:column>
<p:column headerText="Exam">
<h:outputText value="#{s.exam}" />
</p:column>
<p:column headerText="Maths">
<h:outputText value="#{s.math}" />
</p:column>
<p:column headerText="Physiscs">
<h:outputText value="#{s.phy}" />
</p:column>
<p:column headerText="Chemistry">
<h:outputText value="#{s.chem}" />
</p:column>
</p:dataTable>
Give this a try. First add rowIndexVar to your p:dataTable tag then render the output conditionally. So your code will look something like this:
<p:dataTable rowIndexVar="currRow" value=#{myBean.student} val="s">
<p:column headerText="Name">
<h:outputText value="#{s.name}" rendered="#{currRow lt 1}"/>
</p:column>
<p:column headerText="Passing Date">
<h:outputText value="#{s.passDate}" rendered="#{currRow lt 1}"/>
</p:column>
<p:column headerText="Exam">
<h:outputText value="#{s.exam}" />
</p:column>
<p:column headerText="Maths">
<h:outputText value="#{s.math}" />
</p:column>
<p:column headerText="Physiscs">
<h:outputText value="#{s.phy}" />
</p:column>
<p:column headerText="Chemistry">
<h:outputText value="#{s.chem}" />
</p:column>
</p:dataTable>
UPDATE: Ok, just realized the error of that approach, but will leave because the rowIndexVar may be useful for someone. Instead modify the rendered attribute to look at the exam field (not positive the syntax is correct):
<h:outputText value="#{s.name}" rendered="#{s.exam eq 'fe'}"/>

Resources