Good Guys,
I have this Web app, after implementing the DataTable from PrimeFaces Showcase, I realized that by clicking on remove a line it always removes the first line in the DataTable, a little help would be welcome.
My DataTable Code:
<p:dataTable value="#{facturaBean.consultasTemp}" paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" selectionMode="single" rowKey="#{consulta.ordem}" rows="5" paginator="true" widgetVar="tblConsultas" var="consulta">
<p:column style="text-align: center" headerText="Operação" width="100">
<p:commandButton style="font-size: 17px" icon="fa fa-trash-o" action="#{facturaBean.removerConsulta(consulta)}" update="#form"/>
</p:column>
<p:column headerText="Consulta/Procedimento">
<h:outputText value="#{consulta.consulta}"></h:outputText>
</p:column>
<p:column headerText="Data/Hora">
<h:outputText value="#{consulta.consultaData}"></h:outputText>
</p:column>
<p:column headerText="Médico">
<h:outputText value="#{consulta.consultaMedico}"></h:outputText>
</p:column>
<p:column headerText="Valor (MT)">
<h:outputText value="#{consulta.consultaValor}"></h:outputText>
</p:column>
<p:column headerText="Quantidade">
<h:outputText value="#{consulta.consultaQuantidade}"></h:outputText>
</p:column>
<p:column headerText="Valor Total (MT)">
<h:outputText value="#{consulta.consultaValorTotal}"></h:outputText>
</p:column>
</p:dataTable>
Removing Line Method:
private ArrayList consultasTemp = new ArrayList();
public String removerConsulta(ConsultaTemp consulta) {
consultasTemp.remove(consulta);
return null;
}
Video for details:
enter link description here
Thank you all very much for your help and knowledge, but I was unable to remove rows using the rowKey="#{consulta.ordem}" attribute of the DataTable, instead of this I created the following class:
public String removerConsulta(ConsultaTemp consulta) {
for (int i = 0; i < consultasTemp.size(); i++) {
if (consultasTemp.get(i).getConsulta().equals(consulta.getConsulta())) {
consultasTemp.remove(i);
}
}
return null;
}
Related
When clicking on the edit button in PrimeFaces I want my listener to get the new value of the column as well as the old one. I am currently only getting the new value:
public void onLicenseEdit(RowEditEvent event) {
selectedItemLicense = (ItemLicense) event.getObject();
}
This is my xhtml:
<p:dataTable id="licenses" var="license"
value="#{itemShowView.itemReference.lastVersionItemLicenses}"
emptyMessage="#{messages['common.emptymessage']}"
class="itemLicensesTable"
selection="itemShowView.selectedLicense"
editable="true">
<p:ajax event="rowEdit" update="#(.itemLicensesTable)" listener="#{itemShowView.onLicenseEdit}" />
<f:facet name="header">
<p:column headerText="#{messages['license.licensenumber']}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{license.licensePK.licenseNumber}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{license.licensePK.licenseNumber}" />
</f:facet>
</p:cellEditor>
</p:column>
...
<p:column>
<p:rowEditor />
</p:column>
...
</p:dataTable>
Please help. Thanks in advance.
Thank you for your comment. I modified the code using valueChangeListener. This is my solution:
<f:facet name="input">
<p:inputText value="#{itemLicense.itemLicensePK.licenseNumber}" valueChangeListener="#{itemShowView.onLicenceChange}"/>
</f:facet>
and the Java code:
private ItemLicense selectedItemLicenseForModification;
...
public void onLicenceChange() {
selectedItemLicenseForModification = (ItemLicense) FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("itemLicense");
}
In my application i added java autocomplete to searchitem.
This item is working good. But it s not working after create row.
i recorded video to youtube.
https://www.youtube.com/watch?v=0FM52YNsDZY
page :
<p:autoComplete id="autocomplete" dropdown="true" value="#{126Controller.tesisAuto}" var="auto"
completeMethod="#{211Controller.complete}" forceSelection="true"
itemLabel="#{auto.tesisAdi}" itemValue="#{auto}">
<f:facet name="itemtip">
<h:panelGrid columns="2" cellpadding="5">
<h:outputText value="Tesis Adı: "/>
<h:outputText value="#{auto.tesisAdi}"/>
<h:outputText value="Şeflik Adı: "/>
<h:outputText value="#{211Controller.getSeflik(auto.seflikKodu)}"/>
<h:outputText value="Adres: "/>
<h:outputText value="#{auto.adres}"/>
</h:panelGrid>
</f:facet>
<p:ajax event="itemSelect" listener="#{126Controller.itemByTesisAuto()}" update=":126ListForm:display"/>
</p:autoComplete>
Complete method:
public List<211> complete(String query) {
return autoComplete(query);
}
public List<211> autoComplete(String auto){
List<211> completed = new ArrayList<211>();
for (211 m211: this.getFacade().getTesisByYetkiIsyeriKodu(yetkiSeflik)){
if(m211.getTesisAdi().startsWith(auto.toUpperCase())){
completed.add(m211);
}
}
return completed;
}
Create method:
public void create() {
persist(PersistAction.CREATE, "Oluşturma");
if (!JsfUtil.isValidationFailed()) {
items = null; // Invalidate list of items to trigger re-query.
}
}
Thanks god.
I solved. I added h:head and worked.
Thank u so much.
<p:panelGrid id="sef" columns="1" style="width: 100%">
<h:head>
<h:form>
<h:panelGrid columns="2" style="width: 100%">
<h:outputText value="Şeflik Seçiniz : " style="width: 20%" rendered="#{211Controller.yetkiliSeflikSayisi gt 1}"/>
<p:selectOneMenu id="seflik" value="#{211Controller.yetkiSeflik}" effect="fold" rendered="#{211Controller.yetkiliSeflikSayisi gt 1}" >
<f:selectItem itemLabel="Seçiniz" itemValue=""/>
<f:selectItems value="#{211Controller.list}"/>
<p:ajax update="autocomplete"/>
</p:selectOneMenu>
<h:outputText value="Tesis Seçiniz : " style="width: 20%"/>
<p:autoComplete id="autocomplete" dropdown="true" value="#{126Controller.tesisAuto}" var="auto"
completeMethod="#{211Controller.complete}" forceSelection="true"
itemLabel="#{auto.tesisAdi}" itemValue="#{auto}">
<f:facet name="itemtip">
<h:panelGrid columns="2" cellpadding="5">
<h:outputText value="Tesis Adı: "/>
<h:outputText value="#{auto.tesisAdi}"/>
<h:outputText value="Şeflik Adı: "/>
<h:outputText value="#{211Controller.getSeflik(auto.seflikKodu)}"/>
<h:outputText value="Adres: "/>
<h:outputText value="#{auto.adres}"/>
</h:panelGrid>
</f:facet>
<p:ajax event="itemSelect" listener="#{126Controller.itemByTesisAuto()}" update=":126ListForm:display :126ListForm:sef"/>
</p:autoComplete>
</h:panelGrid>
</h:form>
</h:head>
</p:panelGrid>
I have been searching for similar issue but I could not find any.
so here is the thing
I am trying to create a web application that deals with HR stuff, like employee requests (Resign, loan, vacation, etc..)
I am using primeface and I have the following problem that I cant figure out.
The thing is I am trying to do is :
1- When user first creates the request and assigns the user and submit the form
the next step is
2- the manager would sees the request and then change the "Person responsible for the request" to a new one using the drop menu in the datatable and I have been trying to solve this problem with no luck.
Here is the dialog script
<h:form id='resignf'>
<p:dialog id='res' header="Resign Request" widgetVar="resign" minHeight="40">
<p:outputLabel value="Employee name" />
<p:inputText value="#{controller.resignName}" required="true" requiredMessage="This field is required" />
<p:outputLabel value="Employee Number" />
<p:inputText value="#{controller.resignEmployeNum}" required="true" />
<p:inputText value="#{controller.resignNationalIDNum}" required="true" />
<p:inputText value="#{controller.resignNotes}" required="true" />
<p:outputLabel for="AssignUser" value="User" />
<p:selectOneMenu id="AssignUser" value="#{controller.assignUser}" style="width:150px" converter="UConverter">
<f:selectItems value="#{controller.usersList}" var="user" itemLabel="#{user.username}"/>
</p:selectOneMenu >
<p:commandButton action="#{controller.createResignRequest()}" onclick="PF('resign').hide();" update="#all"/>
</p:dialog>
And the code is my controller.java file below to create the request in the table
/* Request to resign*/
private List<ResignationRequest> resignList;
private ResignationRequestController rController = new ResignationRequestController();
private String resignName;
private String resignEmployeNum;
private String resignNationalIDNum;
private String ResignNotes;
private int AutoAssignToIDNUM;
/* end of request to resign*/
public void createResignRequest() {
System.out.println("createResignRequest");
ResignationRequest newResign = new ResignationRequest();
newResign.setName(resignName);
newResign.setEmployeeNum(resignEmployeNum);
newResign.setNationalID(resignNationalIDNum);
newResign.setNotes(ResignNotes);
newResign.setUserID(AssignUser);
rController.create(newResign);
resignList = rController.findResignationRequestEntities(); //retrieves all the resigns from the database
}
Now all that is working perfectly, but when I try to change the old user with the new one here I get confused! so far what I have been thinking is I need to find the old user and then switch him, but I could not figure a way to do it using the select list. The script for for changing the "User responsible for the request" below
<p:dataTable id="resignTable1" cellSeparator="true" editMode="cell" editable="true" var="resign" value="#{controller.resignList}" paginator="true" rows="10" rowIndexVar="index1">
<p:ajax id="aj" event="cellEdit" listener="#{controller.editUser(user)}" update="resignTable1"/>
<p:column headerText="Employee number">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{resign.employeeNum}" /></f:facet>
<f:facet name="input"> <h:inputText value="#{resign.employeeNum}" /></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="name">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{resign.name}" /></f:facet>
<f:facet name="input"> <h:inputText value="#{resign.name}" /></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Request Number">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{resign.id}" /></f:facet>
<f:facet name="input"> <h:inputText value="#{resign.id}" /></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="User responsible for the request">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{resign.userID}" /></f:facet>
<f:facet name="input"> <h:inputText value="#{resign.userID}" /></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Comments">
<p:cellEditor>
<f:facet name="output"> <h:outputText value="#{resign.notes}" /></f:facet>
<f:facet name="input"> <h:inputText value="#{resign.notes}" /></f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Send the request to the next employee">
<p:selectOneMenu id="AssignUser" value="#{controller.assignUser}" style="width:150px" converter="UConverter" onchange="submit();">
<f:selectItems value="#{controller.usersList}" var="user" itemLabel="#{user.username}" actionListener="#{controller.editRequestStep(resign)}" >
</f:selectItems>
</p:selectOneMenu >
In my controller file
public void editRequestStep(ResignationRequest r) {
System.out.println("Edit resign");
try {
System.out.println("Edit resign");
rController.edit(r);
} catch (Exception ex) {
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
}
}
I tried to get as much as I could from the code but I have a lot of stuff that I am not sure if I should submit. I tried ajax
NOTE: I am using mySQL, apache tomcat in case if it matters.
Solved it.
public void editRequestStep(ResignationRequest r) {
System.out.println("Edit resign " + EditAssignUser +" this is userthig" + r.getName());
try {
System.out.println("Edit resign");
r.setUserID(EditAssignUser);
} catch (Exception ex) {
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
}
}
<p:selectOneMenu id="AssignUser" value="#{controller.editAssignUser}" style="width:150px" converter="UConverter">
<p:ajax listener="#{controller.editRequestStep(resign)}" update="#all"/>
<f:selectItems value="#{controller.usersList}" var="user" itemLabel="#{user.username}" >
</f:selectItems>
I did not notice that I used the variable assignUser 2 times, which actually missed me up. So what I did is I created new Users variable called "editAssignUser" then in my controller I just set the user look at the code below
public void editRequestStep(ResignationRequest r) {
System.out.println("Edit resign " + EditAssignUser +" this is userthig" + r.getName());
try {
System.out.println("Edit resign");
r.setUserID(EditAssignUser);
} catch (Exception ex) {
Logger.getLogger(Controller.class.getName()).log(Level.SEVERE, null, ex);
}
}
I am very new born babie for Datatable. I use roweditor. But the problem is, the value is it not displaying after an edit was made in some rows. Sometimes the database was not changed as well. I use update query. Can anyone help me?
Thanqu in advance.
here is my code:
public void onRowEdit(RowEditEvent event)
{
System.out.println("hello...");
detail_li.clear();
FacesMessage msg = new FacesMessage("row Edited",selected_bean.get_name());// i have doubt here
FacesContext.getCurrentInstance().addMessage(null, msg);
DBQuery db = new DBQuery();
String code=selected_bean.getCode();
String Student_name = selected_bean.getStudent_name();
System.out.println(" code$..."+code);
String Student_name = selected_bean.getStudent_name();
String rank = selected_bean.getRank();
String feedback = selected_sngbean.getFeedback();
int res = db.special_code(rank,feedback,code);//here used update query
detail_li = db.detaillist(class,code,student_name);
}
This is my datatable code..
<h:form id="for1">
<p:growl id="msgs2" showDetail="true"/>
<div>
<p:dataTable id="s" var="sn" value="#{songdet.song_li}" editable="true" style="font-size: 80%" selectionMode="single" selection="#{songdet.selected_sngbean}" rowKey="#{sn.track_no}" >
<p:ajax event="rowEdit" listener="#{home.onRowEdit(event)}" update="for1:msgs2" process="for1"/>
<p:ajax event="rowEditCancel" listener="#{home.onRowCancel(event)}" update=":for1:msgs2" process="for1"/>
<p:column headerText="Name" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{sn.name}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{sn.name}" style="width:100%"/
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Age" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{sn.age}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput2" value="#{sn.age}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="class" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{sn.class}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput3" value="#{sn.class}" style="width:100%"/
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Rank" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{sn.rank}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput55" value="#{sn.rank}" style="width:100%"/
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="feedback" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{sn.feedback}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput6" value="#{sn.feedback}" style="width:100%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:50px;height: 20px" >
<p:rowEditor />
</p:column>
<p:dataTable>
</div>
public void onRowEdit(RowEditEvent event) {
int z;
System.out.println("the selected row is....."+table.getRowIndex());
z=table.getRowIndex();
check(z);
FacesMessage msg = new FacesMessage("Row Edited",check(z));
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public String check(int i){
String rank="";
String Feedback="";
String name="";
int q;
q=i;
sBean st=new sBean();
st=(sBean) student_list.get(q);
name=st.getname();
roll=st.getcode();
DBQuery db = new DBQuery();
int res = db.update(name,roll,rank);
return rank;
}
I use primefaces single row selection data table , and i want to change a value on the selected row so this is my xhtml page
<h:form id="form">
<p:panel header="Prix des matériaux " style="width : 664px; " >
<br />
<p:dataTable id="cars" var="car" value="#{materielbean.listitemsmaterielBean}"
rowKey="#{car.iditemsmateriel}" paginator="true" rows="20"
selection="#{materielbean.selecteditemforprix}" selectionMode="single" >
<p:ajax event="rowSelect" update=":form:dialog" oncomplete="PF('carDialog').show()"/>
<f:facet name="header">
Liste de de matériel
</f:facet>
<p:column headerText="Désignation" filterBy="designation" >
#{car.designation}
</p:column>
<p:column headerText="Unité">
#{car.unite}
</p:column>
<p:column headerText="Prix en DT" >
#{car.prix}
</p:column>
</p:dataTable>
<p:dialog id="dialog" header="Changer le prix d'un article" widgetVar="carDialog"
resizable="true" showEffect="fade" hideEffect="explode">
<h:panelGrid columns="3">
<h:outputText value=" #{materielbean.selecteditemforprix.designation}" />
<p:inputText value="#{materielbean.selecteditemforprix.prix}"/>
<p:commandButton value="OK" action="#{materielbean.modifprixofitem()}"
onclick="PF('carDialog').hide()" update=":form:cars" />
</h:panelGrid>
</p:dialog>
</p:panel>
</h:form>
And this is the backing bean to modify the selected object
#ManagedBean(name="materielBean")
#SessionScoped
private ItemsMateriel selecteditemforprix;
public ItemsMateriel getSelecteditemforprix() {
return selecteditemforprix;
}
public void setSelecteditemforprix(ItemsMateriel selecteditemforprix) {
this.selecteditemforprix = selecteditemforprix;
}
public void modifprixofitem() {
itemmaterielDAO.Modifitemsmateriel(selecteditemforprix );
selecteditemforprix = new ItemsMateriel();
}
When I click "OK" I take the new value from the inputtext, update my object in the database and finally I update the data table, but when I did it like that, I got an error which says
22:16:48,999 GRAVE [javax.enterprise.resource.webcontainer.jsf.context] (http-localhost-127.0.0.1-8383-6) javax.el.ELException: /Gestionstock/Materiel/Matos.xhtml #28,97 rowKey="#{car.iditemsmateriel}": java.lang.NullPointerException
Well the problem is in the last lign selecteditemforprix = new ItemsMateriel(); i don't really know what's the problem with that lign but when i deleted it everything works fine, any other clarifications will be appreciated .