In my application in a dialog I displayed a dataTable in each column there are a check box to select corresponding row. At the bottom of dialog I paced two
button one for display selected rows another for reset the datatable means to deselect the selected rows.
.xhtml code is given below:
<p:dialog id="popUp" header="Activity Detail" widgetVar="popUpWidget"
showEffect="fade" hideEffect="explode" resizable="false" modal="true">
<h:panelGrid>
<p:row>
<p:column colspan="2">
<p:dataTable id="userListForAdminpopup" value="#{activityListController.activityUsers}" var="user"
paginator="true" paginatorPosition="bottom" widgetVar="userListForAdminpopUp"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rows="10" selection="#{activityListController.selectedActivityUsers}">
<p:column headerText="#{adbBundle['fullName']}"
sortBy="#{user.lastName}" filterBy="#{user.fullName}"
filterMatchMode="contains" styleClass="userName">
<h:outputLabel value="#{user.firstName}" />
</p:column>
<p:column selectionMode="multiple" />
</p:dataTable>
</p:column>
</p:row>
<p:row>
<p:column colspan="2">
<h:panelGroup layout="block">
<p:commandButton value="Update" oncomplete="confirmation.show()"/>
<p:commandButton value="Reset"/>
</h:panelGroup>
</p:column>
</p:row>
</h:panelGrid></p:dialog>
I want to deselect the rows when click on reset button. How it can be done?
We can deselect p:dataTable rows using unselectAllRows()
<p:dataTable
id="dataTableId"
widgetVar="dtWidgetVar"
value="#{myBean.items}"
var="item"
....>
</p:dataTable>
<p:commandButton value="Reset" onclick="PF('dtWidgetVar').unselectAllRows()" />
From the bean
PrimeFaces.current().executeScript("PF('dtWidgetVar').unselectAllRows()");
You try:
<p:commandButton value="Reset" update="userListForAdminpopup" process="#this" actionListener="#{activityListController.hand}"/>
Bean:
public void hand(){
selectedActivityUsers = new ActivityUsers(); // Type of element of list
}
Try this one:
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("form:dataTable");
dataTable.reset();
Related
I have a problem with PrimeFaces <p:confirmDialog>, when I click on the <p:commandLink> that must show up the dialog and choose 'No', everything is fine. But when I click on yes,everything works just the first time.
When the process is over and I click again on any <p:commandLink>, the dialog doesn't show up unless I refresh the whole page.I had try everything but I cannot figure out what can be the problem.
<h:form>
<p:dataTable border="0" rules="all" value="#{userBean.users}" var="user" autoUpdate="true" styleClass="table table-hover" paginator="true" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="6,10,15" >
<p:column>
<f:facet name="header">
<h:outputText value="Login" />
</f:facet>
<h:outputText value="#{user.login}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="" />
</f:facet>
<p:commandLink class="badge bg-red marge-left" onclick='PF("cdu#{user.id}").show()' title="Supprimer un utilisateur"><span class="fa fa-trash-o"/></p:commandLink>
<p:confirmDialog ajax="true" message="Voulez vous vraiment supprimer l'utilisateur '#{user.login}'" closable="true" header="Confirmation" severity="alert" widgetVar="cdu#{user.id}" >
<p:commandButton value="oui" actionListener="#{userBean.deleteUser}" update="#form" onclick='PF("cdu#{user.id}").hide()' styleClass="btn btn-primary"/>
<p:commandButton value="non" onclick='PF("cdu#{user.id}").hide()' type="button" styleClass="btn btn-danger" />
</p:confirmDialog>
</p:column>
</p:dataTable>
</h:form>
I had finally resolved my problem. I changed the <p:confirmDialog> by a global one and it works.
<h:form>
<p:dataTable border="0" rules="all" value="#{userBean.users}" var="user" autoUpdate="true" styleClass="table table-hover">
<p:column>
<f:facet name="header">
<h:outputText value="Login" />
</f:facet>
<h:outputText value="#{user.login}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Nom" />
</f:facet>
<h:outputText value="#{user.firstName} #{user.lastName}" />
</p:column>
<p:column style="width:200px;">
<f:facet name="header">
<h:outputText value="Email" />
</f:facet>
<h:outputText value="#{user.email}" />
</p:column>
<p:column >
<f:facet name="header">
<h:outputText value="" />
</f:facet>
<p:commandLink class="badge bg-blue marge-left" action="#{userBean.getUserRowToEdit}" title="Editer un utilisateur" ><span class="fa fa-edit"/></p:commandLink>
<p:commandLink class="glyphicon glyphicon-trash icon-trash" actionListener="#{userBean.deleteUser}" title="Supprimer un utilisateur" update="#form">
<p:confirm header="Confirmation" message="Voulez-vous vraiment supprimer l'utilisateur?" icon="ui-icon-alert"/>
</p:commandLink>
</p:column>
</p:dataTable>
<p:confirmDialog global="true">
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check"/>
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close"/>
</p:confirmDialog>
</h:form>
I tried your code and repaired it a little. Hope it will work for you too.
-I removed ajax="true"
-usersBean.deleteUser function need to know which user to so -> deleteusersBean.deleteUser(user)
Under is my code that i use to test your case. A few things are changed due to existing beans i have. This code is tested on latest primefaces(5.2).
my xhtml file:
<p:column>
<f:facet name="header">
<h:outputText value="" />
</f:facet>
<p:commandLink class="badge bg-red marge-left" value="delete" onclick='PF("cdu#{user.userId}").show()' title="Supprimer un utilisateur"><span class="fa fa-trash-o"/></p:commandLink>
<p:confirmDialog message="Voulez vous vraiment supprimer l'utilisateur '#{user.name}'" closable="true" header="Confirmation" severity="alert" widgetVar="cdu#{user.userId}" >
<p:commandButton value="oui" actionListener="#{loginBean.deleteUser(user)}" update="#form" onclick='PF("cdu#{user.userId}").hide()' styleClass="btn btn-primary"/>
<p:commandButton value="non" onclick='PF("cdu#{user.userId}").hide()' type="button" styleClass="btn btn-danger" />
</p:confirmDialog>
</p:column>
</p:dataTable>
</h:form>
my loginBean:
public class LoginBean implements Serializable {
private static final long serialVersionUID = 6188046073588310656L;
private List<User> users= new ArrayList<User>();
public LoginBean() {
}
public List<User> getUsers() {
if(users.size()==0){
for (int i= 0; i<3; i++){
User u = new User();
u.setUserId(i);
u.setName("noob"+i);
users.add(u);
}
}
return users;
}
public void deleteUser(User user){
users.remove(user);
}
}
I am working with jsf 2.0 et Primefaces. i have a selectOneMenu that have dynamic values of datas that correspond to the user connected. I want that when i choose a data and click on the button view the list of emails related to the data selected will be shown on the dataTable.
<p:panel>
<p:selectOneMenu id="data" value="#{mailMB.database}" styleClass="auto" required="true" effect="fade" >
<f:selectItem itemLabel="Select Data" itemValue="" />
<f:selectItems value="#{dataMB.datas}" var="data" itemLabel="#{data.keyword}" itemValue="#{data.keyword}"/>
</p:selectOneMenu>
<p:commandButton value="View" action="#{mailMB.grabemails()}" ajax="true" update="datas" icon="ui-icon-circle-check" styleClass="ui-priority-primary" />
</p:panel>
<p:panel id="panelform" header="Emails List" >
<p:dataTable value="#{mailMB.emailsByData}" var="item" id="datas" rowsPerPageTemplate="5,10,15,20,25,30"
paginator="true" rows="10"
selectionMode="single" filteredValue="#{mailMB.filteredMails}" rowKey="#{item.id}"
selection="#{mailMB.selectedMail}">
<p:ajax event="rowSelect" update=":form:dataView , :form:confirmDelete, :form:viewButton" listener="#{dataMB.onRowSelect}"/>
<p:ajax event="rowToggle" />
<p:column style="width:2%" exportable="false">
<p:rowToggler />
</p:column>
<p:column sortBy="#{item.email}" filterBy="#{item.email}">
<f:facet name="header">
<h:outputText value="Email"/>
</f:facet>
<h:outputText value="#{item.email}"/>
</p:column>
</p:dataTable>
</p:panel>
and this is my method in the managed Bean that returns the list of emails by data using the named query:
public List<Email> getEmailsByData() {
System.out.println("the database" + getDatabase());
return emailsByData = mailBusinessLocal.mails(getDatabase());
}
public List<Email> grabemails() {
return emailsByData = mailBusinessLocal.mails(database);
}
when i choose a data and click view nothing happens and the databate return null as it shown on the glassfish log.
You need to put your <p:selectOneMenu> inside a <h:form>. That's my first guess.
The two main components in my jsf are p:tree and p:dataTable
The idea is to create a table according to the tree node selection.
Jsf:
<h:panelGrid columns="2" style="width: 100%" columnClasses="treeColumn,tableColumn">
<h:panelGroup id="treePanel">
<p:tree id="tree"
value="#{genRepBean.root}"
var="node"
dynamic="true"
cache="true"
animate="true"
selectionMode="single"
selection="#{genRepBean.selectedNode}"
rendered="#{genRepBean.renderTree}">
<p:ajax event="select" listener="#{genRepBean.onNodeSelect}" update=":mainForm:tablePanel"/>
<p:treeNode expandedIcon="ui-icon-folder-open"
collapsedIcon="ui-icon-folder-collapsed">
<h:outputText value="#{node.name}" styleClass="tableTreeText"/>
</p:treeNode>
<p:treeNode type="au" icon="ui-icon-document">
<h:outputText value="#{node.name}" />
</p:treeNode>
</p:tree>
</h:panelGroup>
<h:panelGroup id="tablePanel">
<p:dataTable id="acqDataTable"
var="acq"
value="#{genRepBean.acqList}"
rendered="#{genRepBean.renderTable}"
filteredValue="#{genRepBean.filteredAcqList}"
paginator="true"
paginatorPosition="bottom"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
rowsPerPageTemplate="5,10,15"
rows="10"
lazy="false"
style="width: 100%">
<p:column headerText="ID" sortBy="#{acq.Id}" styleClass="tableTreeText">
<h:outputText value="#{acq.Id}" />
</p:column>
<p:column headerText="IP ADDRESS" sortBy="#{acq.ipAddress}" styleClass="tableTreeText">
<h:outputText value="#{acq.ipAddress}"/>
</p:column>
<p:column headerText="STEP" sortBy="#{acq.Step}" filterBy="#{acq.Step}" filterMatchMode="contains" styleClass="tableTreeText">
<h:outputText value="#{acq.Step}"/>
</p:column>
<p:column headerText="STATUS" sortBy="#{acq.status}" filterBy="#{acq.status}" styleClass="tableTreeText">
<h:outputText value="#{acq.status}"/>
</p:column>
</p:dataTable>
The bean (onNodeSelect):
public void onNodeSelect() {
acqList.clear();
this.acqList = AcqHelper.getAllViaStartDate(new java.sql.Date(startDate.getTime()));
if (!acqList.isEmpty()) {
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("mainForm:acqDataTable");
dataTable.reset();
renderTable = true;
}
I don’t want to remove the filter option since its very usable to the client but I don’t know why its blocking the table refresh ??
Any help would be great
Thanks
You don't need to perform changes into a DataTable model. Primefaces is taking data from #{genRepBean.acqList}. Just set proper values in that list and reset #{genRepBean.filteredAcqList} list. After the request is completed, datatable will be refreshed with new values.
I need some help on including a mouseover event for a datatable column in JSF. Can you please let me know how to include a popup list on mouseover a jsf column. Below is the code corresponding to my JSF column.
<p:column style="text-align: left;" styleClass="foo" rendered="#{demandBean.screeRenderVo.adjustedRenderer}" >
<f:facet name="header">
<h:outputText id="AdjustedID" value="#{demandBean.dmdScreenLabelVO.adjustedValue}"/>
</f:facet>
<h:inputText id="AdjustedValueID" value="#{car.adjustedValue}" style="height: 20px;width: 50px;"></h:inputText>
</p:column>
Not sure how to add the mouserover event for the above column. Please Assist.
You can do something like this:
<script>
jQuery(document).ready(function(){
jQuery('td').mouseover(function(){
var th = jQuery(this).closest('table').find('th').eq( this.cellIndex );
if (th.attr('id') == "datatable:column3"){
dlg1.show();
}
else{
dlg1.hide();
}
});
});
</script>
<h:form prependId="false">
<p:dataTable id="datatable" var="car" value="#{tableBean.carsSmall}">
<p:column id="column3" style="text-align: left;" styleClass="foo" rendered="#{demandBean.screeRenderVo.adjustedRenderer}" >
<f:facet name="header">
<h:outputText id="AdjustedID" value="#{demandBean.dmdScreenLabelVO.adjustedValue}"/>
</f:facet>
<h:inputText id="AdjustedValueID" value="#{car.adjustedValue}" style="height: 20px;width: 50px;"></h:inputText>
</p:column>
</p:dataTable>
<p:dialog id="basicDialog" header="Basic Dialog" widgetVar="dlg1">
<h:outputText value="Resistance to PrimeFaces is futile!" />
</p:dialog>
</h:form>
I am using primefaces datatable with clickable rows and I need to find way how to set selected row from backing bean.
There is my datatable definition:
<p:dataTable id="cablePathTable" var="cablePath" value="#{commonTableBean.cableLazyModel}" rows="100"
selectionMode="single" selection="#{commonTableBean.selectedCablePathTblRow}"
rowIndexVar="rowIndex" widgetVar="datatableVar"
emptyMessage="---">
<p:ajax event="rowSelect" process="#this" update=":form:portFieldset" />
<p:column headerText="No">
<h:outputText value="#{cablePath.column1}" />
</p:column>
<p:column headerText="Port A">
<h:outputText value="#{cablePath.column4}" />
</p:column>
<p:column headerText="Port B">
<h:outputText value="#{cablePath.column5}" />
</p:column>
I have tried following approach, but with no success.
In backing bean I have added method:
public void test(){
DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("form:cablePathTable");
dataTable.setRowIndex(2);
}
And I have added test butoon to the XHTML page:
<p:commandButton process="#this" update=":form:cablePathTable" value="set2row" action="commonTableBean.test"/>
But nothig is changed on the datatable, selection didn't change...
Please any ideas how to solve this problem?
Just set the value behind selection="#{commonTableBean.selectedCablePathTblRow}".
public void test(){
selectedCablePathTblRow = cablepath;
}