I have the following in my xhtml
<h:form id="clientTableForm" prependId="false">
<p:dataTable id="clientTable" widgetVar="clientTableVar"
var="client" value="#{resendEmailController.lazyDataModel}"
paginator="true" rows="15"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}"
rowsPerPageTemplate="5,10,15,20,25,50,75,100"
paginatorPosition="bottom" pageLinks="5" lazy="true"
sortBy="#{client.cclnCode}" sortOrder="ascending"
selection="#{resendEmailController.selectedClient}"
selectionMode="single" filterDelay="500" scrollable="true"
scrollHeight="380">
<p:ajax event="rowSelect"
listener="#{resendEmailController.changeClient}"
update="_accountTableForm_accountTable" />
<p:column id="cclnCodeColumn" headerText="Client Code"
style="width:25%;" sortBy="#{client.cclnCode}"
filterBy="#{client.cclnCode}" filterMaxLength="10">
<h:outputText value="#{client.cclnCode}"
converter="#{trimStringConverter}" />
</p:column>
<p:column id="cclnNamenColumn" headerText="Client Name"
style="width:75%" sortBy="#{client.cclnName}"
filterBy="#{client.cclnName}" filterMaxLength="50">
<h:outputText value="#{client.cclnName}"
converter="#{trimStringConverter}" />
</p:column>
</p:dataTable>
</h:form>
</p:layoutUnit>
<script type="text/javascript">
$(document).ready(function()
{
autoSelectClient();
});
function autoSelectClient()
{
if (clientTableVar.isEmpty() == false)
{
clientTableVar.selectRow(1, false);
}
}
</script>
And I have this in my backing bean
public void changeClient(SelectEvent selectEvent)
{
ResendEmailClient client = (ResendEmailClient) selectEvent.getObject();
selectedClient = client;
String cclnCode = client.getCclnCode();
selectedAccounts = getService().listAccounts(cclnCode);
}
I would just like to ask why the "selectedClient" variable in the backing bean is NULL when executed by the "autoSelectClient();". But if I clicked the rows the "selectedClient" is already set.
As you can see in my backing bean I can get the value I want by getting the object inside the SelectEvent but I just want to know what is the cause of the difference.
Also if possible can any also suggest how to replicate the emulate the second scenario so that the "selectedClient" is already set before the "changeClient()" is invoked.
Using
JSF 2.1
PrimeFaces 3.5
Mojarra 2.1
try to send your datatable id in process of your ajax selection event like this:
<p:ajax event="rowSelect" listener="#{resendEmailController.changeClient}" update="_accountTableForm_accountTable" process="clientTable" />
Because when you call your event the real situation of your selection has no sent.
Related
I have created a <p:dialog> with an embedded <p:carousel> with tabs and in one of the tabs I have a <p:datatable> but I am noticing that actions like Pagination, Filtering and Sorting do not work in my datatable when the datatable is inside a carousel component (I tried to remove the carousel and the actions work perfectly). Are there any known issues concerning the compatibility of carousel and datatable components? Am I doing something wrong?
.xhtml code
<p:dialog header="View information"
widgetVar="dialog" id="dialog"
position="center" modal="true" height="300" width="400"
appendTo="#(body)">
<p:carousel id="carousel" widgetVar="carousel" circular="true" numVisible="1" itemStyle="width:500px;height:400px;" pageLinks="1">
<p:tab>
<h:form prependId="false">
<p:dataTable id="carousel_results" var="obj"
value="#{myBean.myModel.myObjects}"
widgetVar="carouselTable"
rowKey="#{obj.value}"
paginator="true" rows="10"
filteredValue="#{myBean.filteredObjects}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15,20,25,30,35,40,50,100,{ShowAll|'Show All'" paginatorPosition="bottom">
<f:facet name="header">
Information
</f:facet>
<p:column headerText="Value" filterBy="#{obj.value}"
filterValue="#{obj.value}"
filterMatchMode="contains"
sortBy="#{obj.value}">
<h:outputText value="{obj.value}"/>
</p:column>
........
</p:dataTable>
</h:form>
</p:tab>
</p:carousel>
</p:dialog>
MyBean
#ManagedBean
#ViewScoped
public class MyBean implements Serializable {
private Model myModel
private List<CustomObject> filteredObjects // list to store filtered objects
Model
public class Model{
private List<CustomObject> myObjects
}
I am using Primefaces version 7.0.
I've a problem...
I use a datatable with paginator and filter, if I stay in page 3 and submit a operation with commandButton, the paginator return in page 1.
I think this happen because i use a client side filter() function in oncomplete method in commandButton.
Hope somebody can help me :)
THANKS
This is my code:
<p:dataTable
id="myDataTable"
value="#{myBean.myList}"
var="item"
widgetVar="myWidgetVar"
filteredValue="#{myBean.myFilterList}"
paginator="true"
rows="5"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="5,10,15"
resizableColumns="true"
styleClass="noBorders"
>
....
....
....
<p:column>
<p:commandButton
actionListener="#{myBean.myMethod(item)}"
oncomplete="myWidgetVar.filter()"
update="myDataTable"
/>
</p:column>
</p:dataTable>
Try to bind the "first" attribute of your datatable to a backing bean:
<p:dataTable
id="myDataTable"
...
first="#{myBean.firstRow}">
...
>
In your myBean class:
private int firstRow;
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 have an init() function that returns a list of emails that will be displayed in a Primefaces datatable. And I have a commandButton that extract emails and persist them in the dataTable. These new records show up in the dataTable only if I log out and log in.
This is my init() function ( my managed Bean is annotated with #ManagedBean(name = "mailMB") and #SessionScoped) :
#PostConstruct
public void init() {
emails = new ArrayList();
idCustomer = (String) session.getAttribute("idCustomer");
System.out.println(idCustomer + " this is it");
cust = customerBusinessLocal.findById(idCustomer);
System.out.println(cust.getName());
datas = dataBusinessLocal.findByCustomer(cust);
System.out.println(datas.size());
for (Data d : datas) {
for (Email e : mailBusinessLocal.mailsByData(d)) {
emails.add(e);
}
}
public List<Email> getEmails() {
return emails;
}
In my page xhtml i've implemented the code below:
<h:form id="form">
<p:commandButton value="Extract" update="tableemails" id="ajax" widgetVar="extractButton"
action="#{mailMB.searchEmails()}"
icon="ui-icon-disk" styleClass="ui-priority-primary"
onstart="blockUIWidget1.block()"
oncomplete="blockUIWidget1.unblock()"/>
<pe:blockUI target="formulaire" widgetVar="blockUIWidget1">
<h:panelGrid columns="2">
<img src="../../pictures/animated-loading-bar.gif" width="264" height="34" alt="animated-loading-bar"/>
<h:outputText value="Please wait..." style="white-space: nowrap;"/>
</h:panelGrid>
</pe:blockUI>
<p:panel id="display" header="Emails" >
<p:dataTable id="tableemails" value="#{mailMB.emails}" var="item" rowsPerPageTemplate="5,10,15" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
paginator="true" rows="10" styleClass="case-table" emptyMessage="No records found with given criteria" paginatorPosition="bottom"
filteredValue="#{mailMB.filteredMails}" rowKey="#{item.id}"
selection="#{mailMB.selectedMail}" selectionMode="single" >
<p:ajax event="rowSelect" update=":form:display"/>
<p:column styleClass="blockable" filterStyle="width: 250px" filterBy="#{item.email} " sortBy="#{item.email}">
<f:facet name="header">
<h:outputText value="Email"/>
</f:facet>
<h:outputText value="#{item.email}"/>
</p:column>
</p:dataTable>
</p:panel>
</h:form>
it looks like you do not reload your List<Email> emails after persisting some new data. #PostConstract is executed once after your bean is created (sincce it's #SessionScoped it's created once per session), thats why you see changes only after another login. Add a method repopulateEmails() that would load data from database and run it after you add/remove something, just add it to your persist() method.
public void persist()
{
....
getEntityManager().persist(getInstance());
getEntityManager().flush();
emails = null;
......
}
public List<Email> getEmails(){
if(emails == null){
emails = repopulateEmails();
}
return emails;
}
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.