I have a question I have a DataTable, where I have a button in a column edit, capture the Id of the record, and make a list that record to load the data in the object system, peroHola, I have a question I have a DataTable, where I have a button in a column edit, capture the Id of the record, and make a list that record to load the data in the object system, but my text box value is charging.
<p:dataTable id="dataTable" var="sis" value="#{listSistMB.system}"
paginator="true" rows="10" rowIndexVar="rowIndex" selection="#{listSistMB.system}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:column>
<f:facet name="header">
<h:outputText value="Status" />
</f:facet>
<p:selectBooleanButton value="#{sis.stStatus}" onLabel="A" offLabel="I" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Edit" />
</f:facet>
<p:commandButton id="selectEdit" action="#{listSistMB.editSystem}"
icon="ui-icon-search" title="Editar System">
<f:param name="codCode" value="#{sis.cdCode}"/>
</p:commandButton>
</p:column>
</p:dataTable>
In the controller I headed this way the system object.
#Component("listSistMB")
#Scope("view")
public class MantenanceSystemController implements Serializable{
private System system = new System();
public String editSystem(){
try {
String cdCode = (String)FacesContext.getCurrentInstance().getExternalContext().
getRequestParameterMap().get("codCode");
system = confSistemaService.buscarPorId(Long.valueOf(cdCode));
} catch (Exception e) {
e.printStackTrace();
}
return "register-system";
}
It's not charging me the value of the text box.
<p:inputText value="#{listSistMB.system.nbNomCorto}" />
The MantenanceSystemController bean is in #Scope("view")
If the p:dataTable and p:inputText are not on the same view, the information will be lost when changing views.
Consider a different scope (e.g., Conversation) for the bean.
Related
I'm looking for ways to update p:dataTable after running delete method. In my case a user is expected to fill p:dataTable first with a parametrized search. Table contains rows that can be cancelled using delete method. This doesn't mean that they are deleted completely, delete method rather just changes some columns in db table. For example changes hasCancellationReference column to true. Now this means that I need the table still be shown on dataTable row, just with a changed status. Now I'm looking for the correct way to implement dataTable refresh after delete method.
My dataTable and delete button:
<h:form prependId="false" rendered="#{myController.lst ne null and myController.lst.size() gt 0}" id="dataTable">
<p:dataTable value="#{myController.lzy}" lazy="true" var="tra" rows="10" paginator="true" id="dtas"
selectionMode="single" selection="#{myController.cur}" rowKey="#{tra.transactionId}"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {NextPageLink} {LastPageLink}"
paginatorPosition="top"
rowsPerPageTemplate="10,25,50">
<p:ajax event="rowSelect" listener="#{myController.receipt}" update="#{parent}:tradlg" process="#this" global="false" oncomplete="PF('tradlg').show()"/>
<p:ajax event="page" update=""/>
<p:column headerText="Timestamp" width="30">
<h:outputText value="#{path.toGet.myTimeVariable}">
<f:convertDateTime pattern="dd.MM.yyyy HH:mm:ss" timeZone="EET"/>
</h:outputText>
</p:column>
<p:column headerText="Line" width="10">
<h:outputText value="#{var.lineCode}"/>
</p:column>
<p:column headerText="Stop" width="60">
<h:outputText value="#{var.stopCode} #{var.stopName}" />
</p:column>
<p:column headerText="Vechicle" width="30">
<h:outputText value="#{var.vehicleNumber}"/>
</p:column>
<p:column headerText="Status" width="40">
<h:outputText value="Deleted" style="color: red" rendered="#{var.hasCancellationReference eq true}"/>
<p:commandButton value="Delete"
action="#{emvController.deleteTransaction(tra.transitAccount, tra.transactionId)}"
rendered="#{tra.hasCancellationReference eq false}"/>
</p:column>
</p:dataTable>
</h:form>
Things i have tried:
Running search method inside delete method in backend code:
public void deleteRow(int var, String varId) {
try {
MyParameterClass.getInstance().deleteRow(var, varId);
message = MyParameterClass.getInstance().getMessage();
if (message.equals("success 200")) {
successMsg();
//If delete was succesfull run searchMethod
searchMethod();
} else {
errorMsg();
System.out.println("Faces Message Controller: " + message);
}
} catch (Exception ex) {
Logger.getLogger(EmvController.class).error(ex);
return;
}
}
Doing plain refresh on page after delete method. This does work, but i suspect will cause problems with new features I plan to implement in the future.
I use NetBeans 8.2, GlassFish 5.0, PrimeFaces 5.0.
I created a page with a cell editable data table. When I do the modification on one cell after the ajax event the whole data table replaced by the modified value. Just like the ajax respond does not send back the whole table contents. How can I correct it?
The facelet:
<h:form id="frmDemands">
<p:growl id="msgs" showDetail="true"/>
<div>
<p:dataTable
id="dtblDemands"
value="#{demandUtility.demands}"
var="demand"
editable="true"
editMode="cell"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:ajax event="cellEdit" listener="#{applicantBean.onCellEdit}" update=":frmDemands :frmDemands:msgs"/>
<f:facet name="header">Demands</f:facet>
<p:column headerText="ID">
<h:outputText value="#{demand.id}"/>
</p:column>
<p:column headerText="Amount">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{demand.amount}"/></f:facet>
<f:facet name="input"><p:inputText value="#{demand.amount}"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="State">
<h:outputText value="#{demand.state}"/>
</p:column>
<p:column>
<p:commandButton value="Delete" rendered="#{applicantBean.isDemandDeleteable( demand )}" actionListener="#{applicantBean.onDeleteDemand( demand.id )}" update="#form"/>
</p:column>
</p:dataTable>
</div>
</h:form>
The backing bean handle the cellEdit event:
#Named
#RequestScoped
#Data
public class ApplicantBean
{
#Inject
private DemandUtility demandUtility;
...
public void onCellEdit( CellEditEvent event_ )
{
int rowIndex = event_.getRowIndex();
double newValue = (Double) event_.getNewValue();
Demand demand = demandUtility.getDemands().get( rowIndex );
demand.setAmount( newValue );
Event event = new Event( demandUtility.getNextEventId(), new Date(), "Demand (" + demand.getId() + ") modified! New amount: " + newValue );
demandUtility.getEvents().add( event );
}
...
}
When I try to set the #parent value to the update attribute of the ajax event the dataTable disappears as well.
Can somebody help me, please?
Create a which updates you table and change your Scope to #ViewScoped
It worked for me.
<h:form id="frmDemands">
<p:growl id="msgs" showDetail="true"/>
<p:remoteCommand name="rcCellEditUpdate"
update=":frmDemands:dtblDemands :frmDemands:msgs" />
<div>
<p:dataTable
id="dtblDemands"
value="#{demandUtility.demands}"
var="demand"
editable="true"
editMode="cell"
paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15">
<p:ajax event="cellEdit" listener="#{applicantBean.onCellEdit}" oncomplete="rcCellEditUpdate();"/>
<f:facet name="header">Demands</f:facet>
<p:column headerText="ID">
<h:outputText value="#{demand.id}"/>
</p:column>
<p:column headerText="Amount">
<p:cellEditor>
<f:facet name="output"><h:outputText value="#{demand.amount}"/></f:facet>
<f:facet name="input"><p:inputText value="#{demand.amount}"/></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="State">
<h:outputText value="#{demand.state}"/>
</p:column>
<p:column>
<p:commandButton value="Delete" rendered="#{applicantBean.isDemandDeleteable( demand )}" actionListener="#{applicantBean.onDeleteDemand( demand.id )}" update="#form"/>
</p:column>
</p:dataTable>
</div>
</h:form>
I'm developing a web-app in JSF 2.1 + Primefaces 5.1. I have a datatable with editable rows. I catch the rowEdit event and call a DB procedure to do some validations of the new data and update the record when the user clicks the "check" button. But there's a problem: the datatable row in the GUI is updated whether the validations succeed or fail. I want the changes in the row data to be reversed to their previous state if the validations done in the DB procedure fail. How can I do that?
<p:dataTable id="users_table_id" var="user" value="#{usersBean.users}" rowKey="#{user.id}" paginator="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15" emptyMessage="#{msgs.no_records}" sortBy="#{user.id}" sortOrder="ascending" rows="15" editable="true">
<f:facet name="header">
#{msgs.users}
</f:facet>
<p:ajax event="rowEdit" listener="#{usersBean.onRowEdit}"/>
<p:ajax event="rowEditInit" listener="#{usersBean.onRowEditInit}"/>
<p:column headerText="#{msgs.id}" sortBy="#{user.id}" styleClass="centered-column">
#{user.id}
</p:column>
<p:column headerText="#{msgs.description}" sortBy="#{user.description}" styleClass="centered-column">
<p:cellEditor>
<f:facet name="output">#{user.description}</f:facet>
<f:facet name="input"><p:inputText value="#{user.description}" styleClass="editable-cell"/></f:facet>
</p:cellEditor>
</p:column>
...
<p:column styleClass="datatable-row-editor">
<p:rowEditor/>
</p:column>
</p:dataTable>
#ManagedBean
#ViewScoped
public class UsersBean implements Serializable {
private List<DtoUser> users;
public void onRowEdit(RowEditEvent event) {
logger.entry();
DtoUser dtoUser = (DtoUser)event.getObject();
this.updateUser(dtoUser);
logger.exit();
}
public void updateUser(DtoUser dtoUser) {
try {
logger.entry(dtoUser);
DtoBoUsers dtoBoUsers = dtoUser.toDtoBoUsers();
DtoTypeGenericResponse genericResponse = usersService.updateUser(dtoBoUsers);
if (genericResponse.isError()) {
// error in user update
} else {
// update successful
}
logger.exit(dtoUser);
} catch (Exception e) {
logger.error(ExceptionUtils.getStackTrace(e.fillInStackTrace()));
}
}
}
Im trying to create a select all button or check box that when clicked all the selectbooleanCheck boxes will be checked. is there no straight forward easy way.ive started creating the selectcheckbox that will when changed selectAll. thanks
<p:dataTable value="#{illRequestModel.list}"
var="illRequestRecord" width="100%" styleClass="request-table"
rows="10" paginator="true" id="requestGrid"
currentPageReportTemplate="Viewing Page {currentPage}"
paginatorTemplate="{CurrentPageReport} {PageLinks} "
paginatorPosition="bottom">
<p:column >
<f:facet name="header">
<h:selectBooleanCheckbox id="checkbox2" title="emailUpdates2" onchange="CheckAll()" >
</h:selectBooleanCheckbox>
</f:facet>
<h:selectBooleanCheckbox id="checkbox" title="emailUpdates"
value="#{illRequestRecord.selected}"
onchange="addNumber(#{illRequestRecord.localRequestId})">
<f:ajax listener="#{illRequestRecord.selectmethod}" />
</h:selectBooleanCheckbox>
</p:column>
<p:column id="localRequestIdCol"
sortBy="#{illRequestRecord.localRequestId}">
<f:facet name="header">
<h:outputText value="ID" />
</f:facet>
<h:commandLink value="#{illRequestRecord.localRequestId}"
action="#{requestListController.displaySingleRecord}">
<f:param name="selectedItemId"
value="#{illRequestRecord.localRequestId}"></f:param>
</h:commandLink>
</p:column>
Why don't you use the same multi-selection datatable used in the PrimeFaces DataTable showcase
As you can see in:
<p:dataTable id="multiCars" var="car" value="#{tableBean.mediumCarsModel}" paginator="true" rows="10" selection="#{tableBean.selectedCars}">
It will automatically add a check-all functionality.
In case you want an external checkbox to check all, you can do the following.
Give a widgetVar to you datatable, let's call it dataTableWV
<p:dataTable widgetVar="dataTableWV" id="multiCars" var="car" value="#{tableBean.mediumCarsModel}" paginator="true" rows="10" selection="#{tableBean.selectedCars}">
And you have a checkbox:
<input id="checkAll" type="checkbox" />
You can register a click event on it like the next:
<script>
$(document).ready(function() {
$('#checkAll').on('click', function() {
//selects all records on the displayed page if pagination is supported.
dataTableWV.selectAllRowsOnPage();
//or you can select all the rows across all pages.
dataTableWV.selectAllRows();
});
});
</script>
<p:dataTable widgetVar="dataTableWV" id="multiCars" var="car" value="#{tableBean.mediumCarsModel}" paginator="true" rows="10" selection="#{tableBean.selectedCars}">
<f:facet name="header">
<p:commandButton value="select" onclick="PF('dataTableWV').selectAllRows()" />
<p:commandButton value="unselect" onclick="PF('dataTableWV').unselectAllRows()" />
</f:facet>
</p:dataTable>
Sample Code:-
**JAVA (your backing bean class)
==============================**
//Stores the checked items from data table.
private List<String> selectedIds = new ArrayList<>();
private List<String> getSomeList() {
// return list of strings to data table
return someList;
}
public void selectAllCheckboxes(ToggleSelectEvent event) {
if (selectedIds != null) {
selectedIds.clear();
if (event.isSelected()) {
selectedIds.addAll(someList); //Add all the elements from getSomeList()
}
}
}
**XHTML
=====**
<p:dataTable id="data-table-id" value="#{backingBean.someList}"
selection="#{backingBean.selectedIds}" rowKey="#{id}" var="id"
paginator="true" rows="10" paginatorPosition="bottom"
paginatorAlwaysVisible="false" rowSelectMode="checkbox"
rowsPerPageTemplate="10,20,30,50">
<p:column selectionMode="multiple" />
<p:ajax event="toggleSelect"
update="#this"listener="#backingBean.selectAllCheckboxes}"/>
</p:dataTable>
I am having difficulties sorting a dynamic dataTable
dataTable
<h:form prependId="false" id="Main_Form">
<p:dataTable id="dataTable" var="c" value="#{databaseSearch.customerList}"
paginator="true" rows="10" paginatorAlwaysVisible="false"
paginatorTemplate="Page {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} Rows per page {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,30" draggableColumns="True">
<p:column sortBy="#{c.machine}" headerText="Machine">
<h:outputText value="#{c.machine}" />
</p:column>
<p:column sortBy="#{c.company}" headerText="Company">
<h:outputText value="#{c.company}" />
</p:column>
<p:column sortBy="#{c.contact}" headerText="Contact">
<h:outputText value="#{c.contact}" />
</p:column>
<p:column sortBy="#{c.phone}" headerText="Phone">
<h:outputText value="#{c.phone}" />
</p:column>
<p:column sortBy="#{c.email}" headerText="Email">
<h:outputText value="#{c.email}" />
</p:column>
<p:column exportable="false" headerText="Modify">
<center>
<p:commandButton id="basic" value="Update"
action="#{updateEntry.setMachine(c.machine)}"
oncomplete="dlg1.show();"
styleClass="ui-Machinebutton" update=":Update_Entry"/>
<p:tooltip for="basic" value="Update/Delete Database Entry"
showEffect="fade" hideEffect="fade" />
</center>
</p:column>
</p:dataTable>
</h:form>
I am using a #SessionScoped bean where databaseSearch.customerList would query the database and populate the dataTable. When I click on the column name to sort, the sort arrow mark changes but the table contents do not sort.
I am using PF 3.4.2
If you are querying your database in your getCustomerList method in every request this will not work. You may try with a local variable
public class DatabaseSearch{
private List<C> customerList;
public List<C> getCustomerList () {
if (customerList == null)
customerList = dao.getcustomerList();
return customerList ;
}
}