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);
}
}
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");
}
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 .
I have a datatable with 2 columns(name and description) and I want to update my database when a person updates a row and clicks the checkmark which triggers the execBacking.update method.
In this method, I get the new values by casting event.getObject(), but how can i also get the old values? The name is my primary key so i need the old value to know which row to update in the db.
xhtml page
<p:ajax event="rowEdit" listener="#{execBacking.update}" update=":execForm:execMessages" />
<p:column headerText="Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{exec.name}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{exec.name}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Description">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{exec.description}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{exec.description}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Actions">
<p:rowEditor />
<p:commandLink styleClass="ui-icon ui-icon-trash" type="submit" actionListener="#{execBacking.delete}" update=":execForm:execMessages" >
<f:attribute name="execName" value="#{exec.name}" />
</p:commandLink>
</p:column>
</p:dataTable>
Backing bean
public void update(RowEditEvent event) {
Dao dao = new Dao(ds);
Exec exec = (Exec) event.getObject();
System.out.println("name = "+exec.getName()); //New name
System.out.println("desc = "+exec.getDescription()); //New desc
try {
// If the new exec was updated successfully
if(dao.updateExec(accessBacking.getUsername(), null, exec.getName(), exec.getDescription())) {
FacesContext.getCurrentInstance().addMessage("growl", new FacesMessage(FacesMessage.SEVERITY_INFO, "Success", "Exec Updated Successfully!"));
} else {
FacesContext.getCurrentInstance().addMessage("messages", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", "Error Updating Exec!"));
}
} catch (Exception e) {
FacesContext.getCurrentInstance().addMessage("messages", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error", e.getMessage()));
}
}
I would recommend not having name be your primary key, but instead add an auto-incrementing id field and make that your primary key, and don't make that field editable by the user. This guarantees you always have access to the record that you want to update.
Generally speaking it's bad practice to attempt to modify the primary key in a database the way you're trying to do it.
You can register a ValueChangeListener on the component you're interested in using:
<p:column headerText="Description">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{exec.name}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{exec.name}">
<f:valueChangeListener binding="#{keyChangedListener}"/>
<f:ajax/>
</h:inputText>
</f:facet>
</p:cellEditor>
</p:column>
keyChangeListener will correspond to an implementation of ValueChangeListener and we're using <f:ajax/> here to ensure that the valueChanged event is fired on the textbox. Otherwise the listener will not be notified. Your listener should look something like:
#ManagedBean(name="keyChangedListener")
#ViewScoped
public class KeyChangeListener implements ValueChangeListener{
public void processValueChange(ValueChangeEvent event) throws AbortProcessingException{
Object oldValue = event.getOldValue(); //get the old value
Object newValue = event.getNewValue(); //get the new value
}
I'm using the #ViewScopedhere as advised by the JSF Spec, to avoid unwanted side effects.
#ManagedBean(name = "menuCtrl")
#ApplicationScoped
public class MenuControleur extends AbstractControleur implements Serializable {
private static final Logger log = Logger.getLogger(ApplicationControleur.class);
private PanierBeans[] selectedRep;
public PanierBeans[] getSelectedRep() {
return selectedRep;
}
public void setSelectedRep(PanierBeans[] selectedRep) {
this.selectedRep = selectedRep;
}
// cache
private List<Spectacle> spectacles;
private List<Representation> representations;
private Spectacle specSelec = new Spectacle();
private List<Artiste> artistes;
private List<Representation> representationsFiltrees;
private List lignesSelec;
public List getLignesSelec() {
return lignesSelec;
}
public void setLignesSelec(List lignesSelec) {
this.lignesSelec = lignesSelec;
}
and in the facelet i have this table
<p:dataTable id="dataTable" var="rep" value="#{menuCtrl.specSelec.representations}" widgetVar="representationsTable"
emptyMessage="Pas de représentation trouvée avec les criteres précisés" filteredValue="#{menuCtrl.representationsFiltrees}" paginator="true" rows="10"
style="background: none" >
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields:" />
<p:inputText id="globalFilter" onkeyup="representationsTable.filter()" style="width:150px" />
</p:outputPanel>
</f:facet>
<p:column id="photoArtiste" headerText="Artiste" >
<ui:param name="imgPath" value="images:#{menuCtrl.specSelec.artiste.lienPhoto}.png" />
<p:graphicImage value="#{resource[imgPath]}" />
</p:column>
<p:column id="nomArtiste" filterBy="#{rep}"
headerText="Artiste"
filterMatchMode="contains">
<h:outputText value="#{menuCtrl.specSelec.artiste.nom}" />
</p:column>
<p:column id="nomSpectacle" filterBy="#{rep}"
headerText="Spectacle"
filterMatchMode="contains">
<h:outputText value="#{menuCtrl.specSelec.nomSpectacle}" />
</p:column>
<p:column id="addColumn" filterBy="#{rep.adresse}"
headerText="Ville" footerText="contains"
filterMatchMode="contains">
<h:outputText value="#{rep.salle.adresseSalle}" />
</p:column>
<p:column id="dateDebutColumn" headerText="Date" footerText="startsWith">
<h:outputText value="#{rep.dateDebut}"
id="popupDate">
<f:convertDateTime pattern="d/M/yyyy" />
</h:outputText>
</p:column>
<p:column id="dispColumn"
headerText="Disponibilité">
<p:inputText id="champDisBillets" value="100" size="5" readonly="true" />
</p:column>
<p:column id="qteBillets"
headerText="Qte Billets">
<p:selectOneMenu value="#{buttonBean.number}">
<f:selectItem itemLabel="1" itemValue="1" />
<f:selectItem itemLabel="2" itemValue="2" />
<f:selectItem itemLabel="3" itemValue="3" />
<f:selectItem itemLabel="4" itemValue="4" />
<f:selectItem itemLabel="5" itemValue="5" />
<f:selectItem itemLabel="6" itemValue="6" />
</p:selectOneMenu>
</p:column>
<p:calendar value="#{calendarBean.date2}" id="popupCal" />
<p:column id="priceColumn" filterBy="#{rep}"
headerText="Prix" footerText="contains"
filterMatchMode="contains">
<p:inputText id="prixBillets" value="#{rep.prix}" readonly="true" size="5"/>
</p:column>
</p:dataTable>
nom i want to add checkboxes but in that case i would have to add a selection attributes that point to one of the managed bean attributes, thing is the rows are populated with differents inds of objects so what type o object should in selection ?