Backing bean method is getting null from inputs - jsf-2

This project is made with Primefaces 3.5, JSF 2.0, Oracle database.
The view:
<h:form id="schedule" class="schedule">
// more JSF and forms and dialogs
<p:dialog widgetVar="patientDialog" dynamic="true" header="Find Patient" showEffect="clip" hideEffect="explode" modal="true" >
<h:form id="frmPatient">
<h:panelGrid id="findPatient" columns="1">
<h:panelGrid id="findPatientParameters" columns="2">
<h:outputLabel value="Firstname: " />
<p:inputText id="name" label="name" size="15" value="#{waitinglistBean.name}" />
<h:outputLabel value="Patient Code: " />
<p:inputText id="pcode" label="pcode" size="15" value="#{waitinglistBean.pcode}" />
<br />
<p:commandButton value="Search" process="name" actionListener="#{waitinglistBean.patients}" update="patients"/>
</h:panelGrid>
<h:panelGrid id="findPatientDetails" columns="1">
<p:dataTable id="patients" var="patient" resizableColumns="true" scrollable="true" scrollWidth="1250"
scrollHeight="150" value="#{waitinglistBean.patients}"
rowKey="#{patient.PCode}" selection="#{waitinglistBean.selectedPatient}"
selectionMode="single" >
<f:facet name="header">
Click "Select" button after selecting a row to select patient.
</f:facet>
<p:column width="150" headerText="Code">
#{patient.PCode}
</p:column>
<p:column width="150" headerText="Family Name">
#{patient.PLname}
</p:column>
<p:column width="150" headerText="First Name">
#{patient.PFname}
</p:column>
<p:column headerText="Sex" >
#{patient.PSex}
</p:column>
<p:column headerText="Birthdate">
#{patient.PBorn}
</p:column>
<p:column headerText="Street">
#{patient.PStreet}
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="Select" icon="ui-icon-search"
oncomplete="patientDialog.hide()"
update=":frmDialogs:frmWaiting:tabView:patientDetails"
process="patients"/>
</f:facet>
</p:dataTable>
</h:panelGrid>
</h:panelGrid>
</h:form>
</p:dialog>
<p:dialog widgetVar="patientDialog" dynamic="true" header="Find Patient" showEffect="clip" hideEffect="explode" modal="true" >
<h:form id="frmPatient">
<h:panelGrid id="findPatient" columns="1">
<h:panelGrid id="findPatientParameters" columns="2">
<h:outputLabel value="Firstname: " />
<p:inputText id="name" label="name" size="15" value="#{waitinglistBean.name}" />
<h:outputLabel value="Patient Code: " />
<p:inputText id="pcode" label="pcode" size="15" value="#{waitinglistBean.pcode}" />
<br />
<p:commandButton value="Search" process="name" actionListener="#{waitinglistBean.patients}" update="patients"/>
</h:panelGrid>
<h:panelGrid id="findPatientDetails" columns="1">
<p:dataTable id="patients" var="patient" resizableColumns="true" scrollable="true" scrollWidth="1250"
scrollHeight="150" value="#{waitinglistBean.patients}"
rowKey="#{patient.PCode}" selection="#{waitinglistBean.selectedPatient}"
selectionMode="single" >
<f:facet name="header">
Click "Select" button after selecting a row to select patient.
</f:facet>
<p:column width="150" headerText="Code">
#{patient.PCode}
</p:column>
<p:column width="150" headerText="Family Name">
#{patient.PLname}
</p:column>
<p:column width="150" headerText="First Name">
#{patient.PFname}
</p:column>
<p:column headerText="Sex" >
#{patient.PSex}
</p:column>
<p:column headerText="Birthdate">
#{patient.PBorn}
</p:column>
<p:column headerText="Street">
#{patient.PStreet}
</p:column>
<f:facet name="footer">
<p:commandButton id="viewButton" value="Select" icon="ui-icon-search"
oncomplete="patientDialog.hide()"
update=":frmDialogs:frmWaiting:tabView:patientDetails"
process="patients"/>
</f:facet>
</p:dataTable>
</h:panelGrid>
</h:panelGrid>
</h:form>
</p:dialog>
// more JSF and dialogshizzle
</h:form>
The backing bean:
#ManagedBean(name="waitinglistBean")
#ViewScoped
public class WaitinglistBean implements Serializable
{
private Patients patient;
private OrWaitinglist orWaitinglist;
private List<Patients> patients = new ArrayList<Patients>();
private String name;
private Integer pcode;
public WaitinglistBean() {
}
public void setSelectedPatient(Patients patient) {
this.patient = patient;
}
public Patients getSelectedPatient() {
return patient;
}
public OrWaitinglist getOrWaitinglist() {
return orWaitinglist;
}
public void setOrWaitinglist(OrWaitinglist orWaitinglist) {
this.orWaitinglist = orWaitinglist;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getPcode() {
return pcode;
}
public void setPcode(Integer pcode) {
this.pcode = pcode;
}
public List<Patients> getPatients() {
PatientsDao patientsDao = new PatientsDaoImpl();
patients = patientsDao.getSearchPatient(name, pcode);
System.out.println(name + " " + pcode);
return patients;
}
public void createOrWaitinglist()
{
orWaitinglist.setPatients(patient);
}
So first a user enter a string: "Firstname" and an Integer: "Patient Code".
When he hits the "Search" button it fires the actionListener="#{patientBean.patients}
inside that commandbutton. The method needs 2 parameter, name and pcode which have their own setters/getters.
When I look in console it shows me the printout of these 2 parameters, and they are twice "null", so that means the parameters from the JSF pages were not passed to the backing bean, although the value of the inputText has been set to the backingbean set method: value="#{patientBean.name}"
My question now is why do I get these null-values. I've read several posts which use these setters, but still I get null-values.
after edit i still have the same problem;

for send value of input component in h:panelgrid to the backingbean use somthing like this:
<p:commandButton value="Search" process="#(frmPatient:findPatientParameters :input)"
actionListener="#{patientBean.patients}" update="patients"/>

Related

Primefaces confirmDialog doesn't show up after one call

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);
}
}

Initializing primefaces datatable rowkey

I have a primefaces datatable that I'm populating with properties of objects in an ArrayList once the user clicks a search button. I need to add a column with a radio button so that the user can select a row of the table to update. I'd like to set the rowkey to be the metadataKey property of my objects, but I get the following error:
rowKey="#{result.metadataKey}": Property 'metadataKey' not found on
type java.lang.String
I believed that this was caused by the metadataKey not existing at the time the table is rendered. To remedy it, I set the table to render only after the user had completed their search, but this resulted in the same error.
Here is the relevant html:
<h:form id="dataForm">
<p:panel styleClass="centered">
<p:messages id="message" showDetails="true" autoUpdate="true" />
<p:outputLabel id="searchLabel" value="Search for Metadata: " />
<p:inputText id="search"
value="#{updateMetadataItemsBean.searchTerm}" />
<p:commandButton id="searchButton" value="Search"
action="#{updateMetadataItemsBean.search}"
update="dataForm:metadataitems, message, dataForm:dataPanel" />
<br />
<br />
<br />
</p:panel>
<p:panel styleClass="center" id="dataPanel" >
<p:dataTable id="metadataitems" var="result"
value="#{updateMetadataItemsBean.results}" styleClass="center"
resizableColumns="true"
selection="updateMetadataItemsBean.selectedMetadataItem"
rowKey="#{result.metadataKey}" rendered="#{updateMetadataItemsBean.show}">
<p:column headerText="Select Item to Update" selectionMode="single"></p:column>
<p:column headerText="Metadata Key">
<h:outputText value="#{result.metadataKey}" />
</p:column>
<p:column headerText="Map Name">
<h:outputText value="#{result.mapName}" />
</p:column>
<p:column headerText="Metadata Name">
<h:outputText value="#{result.metadataName}" />
</p:column>
<p:column headerText="Metadata Value">
<h:outputText value="#{result.metadataValue}" />
</p:column>
<p:column headerText="WTX Adapter">
<h:outputText value="#{result.wtxAdapter}" />
</p:column>
<p:column headerText="Card Number">
<h:outputText value="#{result.cardNumber}" />
</p:column>
<p:column headerText="Create Date TS">
<h:outputText value="#{result.createDateTS}" />
</p:column>
</p:dataTable>
<br />
<br />
<br />
</p:panel>
This is the relevant code from the bean:
public class UpdateMetadataItemsBean implements Serializable{
public static final long serialVersionUID = 4;
private String metadataKey;
private String mapName;
private String metadataName;
private String metadataValue;
private String wtxAdapter;
private String cardNumber;
private String createDateTS;
private String searchTerm;
private String selectedDataKey;
private boolean show = false;
private MetadataItems selectedMetadataItem;
private ArrayList<MetadataItems> results = new ArrayList<MetadataItems>();
[getters and setters]
public void search() {
Search s = new Search();
setResults(s.search(searchTerm));
setShow(true);
}
Thanks in advance to anyone who can point me in the right direction.
Alter
selection="updateMetadataItemsBean.selectedMetadataItem"
to
selection="#{updateMetadataItemsBean.selectedMetadataItem}".

I can't delete a row from datatable primefaces

I know this ask is repeated, but none response help me to solve this problem.
I'm trying to delete a row from a primefaces datatable with a commandButton and a confirmDialog, this doesn't work because the backBean isn't getting the values. When I'm trying to delete this show me a null pointer exception. well see my code if you can help me.
This is my XHTML:
<h:form id="principalForm">
<p:menubar>
<p:menuitem value="Nuevo" icon="ui-icon-plusthick" oncomplete="PF('wdlgIngresar').show();"/>
</p:menubar>
<p:dataTable id="dtpacientes" value="#{beanPersona.listPersona}" var="per"
paginator="true" rows="15" rowsPerPageTemplate="15,20,30" paginatorPosition="bottom"
paginatorTemplate="{RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
selectionMode="single" selection="#{beanPersona.currPersona}" rowKey="#{per.id}">
<p:ajax event="rowSelect" listener="#{beanPersona.onRowSelect}" update=":dlgVer" oncomplete="PF('wdlgVer').show()" />
<p:column headerText="Id" sortBy="#{per.id}" filterBy="#{per.id}">
<h:outputText value="#{per.id}" />
</p:column>
<p:column headerText="Nombre" sortBy="#{per.nombres} #{per.apellidos}" filterBy="#{per.nombres} #{per.apellidos}">
<h:outputText value="#{per.nombres} #{per.apellidos}" />
</p:column>
<p:column headerText="Correo" sortBy="#{per.correo}" filterBy="#{per.correo}">
<h:outputText value="#{per.correo}" />
</p:column>
<p:column headerText="Edad" >
<h:outputText value="#{beanPersona.getEdad(per.nacimiento)}" />
</p:column>
<p:column headerText="Sexo" >
<h:outputText value="#{beanPersona.getSexo(per.sexo)}" />
</p:column>
<p:column id="actions" headerText="Acciones">
<p:commandButton title="Borrar" icon="ui-icon-trash" update=":principalForm:deleteConfirmDialog"
oncomplete="PF('deleteConfirmation').show();" actionListener="#{beanPersona.nullMethod}">
<f:setPropertyActionListener value="#{per}" target="#{beanPersona.currPersona}" />
</p:commandButton>
</p:column>
</p:dataTable>
<!-- HERE beanPersona.currPersona.id HAVE THE CURRENT VALUE CORRECTLY-->
<p:confirmDialog id="deleteConfirmDialog" header="Atencion!" severity="alert" widgetVar="deleteConfirmation"
message="Desea eliminar paciente Nº #{beanPersona.currPersona.id} ?" >
<p:commandButton id="confirm" value="Sí" oncomplete="PF('deleteConfirmation').hide();"
update=":principalForm:dtpacientes" action="#{beanPersona.eliminar(beanPersona.currPersona)}" />
<p:commandButton id="decline" value="No" oncomplete="PF('deleteConfirmation').hide();"/>
</p:confirmDialog>
</h:form>
This is my Bean:
#ManagedBean
#ViewScoped
public class BeanPersona implements Serializable {
private Persona persona = new Persona();
private Persona currPersona = new Persona();
public BeanPersona() {
persona = new Persona();
currPersona = new Persona();
}
public Persona getCurrPersona() {
return currPersona;
}
public void setCurrPersona(Persona currPersona) {
this.currPersona = currPersona;
}
public Persona getPersona() {
return persona;
}
public void setPersona(Persona persona) {
this.persona = persona;
}
public void eliminar(Persona currPersona) {
if(currPersona != null) {
new Dml().delete(currPersona, currPersona.getId());
listar();
System.out.println("succefull delete !!!!");
} else if(this.currPersona != null){
new Dml().delete(this.currPersona, this.currPersona.getId());
this.currPersona = new Persona();
listar();
System.out.println("succefull delete this.currPersona!!!!");
} else {
System.out.println("currPersona is null !!!!");
}
}
public String nullMethod () {return null;}
}
currPersona still null when I throw the method
The attribute onclick is for client side behaviour like executing some JS or showing up a dialog etc. You are not defining an actionListener for your commandButton at all.
Try to remove the onclick completely and use a proper actionListener instead:
<p:column id="actions" headerText="Acciones">
<p:commandButton title="Borrar" icon="ui-icon-trash"
update=":principalForm:deleteConfirmDialog"
oncomplete="PF('deleteConfirmation').show();"
actionListener="#{beanPersona.someActionListener}">
<f:setPropertyActionListener value="#{per}"
target="#{beanPersona.currPersona}" />
</p:commandButton>
</p:column>
I solved it, I just put process tag into "confirm" commandButton with value at "#this"
<p:column id="actions" headerText="Acciones">
<p:commandButton title="Borrar" icon="ui-icon-trash" update=":principalForm:deleteConfirmDialog"
oncomplete="PF('deleteConfirmation').show();" actionListener="#{beanPersona.setCurrPersona(per)}">
<f:setPropertyActionListener value="#{per}" target="#{beanPersona.currPersona}" />
</p:commandButton>
</p:column>
</p:dataTable>
<!-- HERE beanPersona.currPersona.id HAVE THE CURRENT VALUE CORRECTLY-->
<p:confirmDialog id="deleteConfirmDialog" header="Atencion!" severity="alert" widgetVar="deleteConfirmation"
message="Desea eliminar a paciente Nº #{beanPersona.currPersona.id} ?" closeOnEscape="true" >
<p:commandButton id="confirm" value="Sí" oncomplete="PF('deleteConfirmation').hide();"
update=":principalForm:dtpacientes" action="#{beanPersona.eliminar}" process="#this"/>
<p:commandButton id="decline" value="No" oncomplete="PF('deleteConfirmation').hide();"/>
</p:confirmDialog>

PrimeFaces DataTable inCell Editing roweditevent

I've problem with datatable incell editing. My update query is running but updating old values. I'm using JDBC, PrimeFaces 3.4 GlassFish 3.1 JSF 2+. When I counted execute rows =1.
updated user and update_time is changing. But edited inputs values are not changing.
My xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<p:panel header="Ürün Ekleme Formu" toggleOrientation="vertical" toggleable="true">
<p:panelGrid columns="2">
<h:outputText value="Ürün Adı:"/><p:column><p:inputText value="#{urunlist.mahsul.urunAdi}" required="true" requiredMessage="Ürün adı?"/></p:column>
<h:outputText value="Tüik Kodu:"/><p:inputText value="#{urunlist.mahsul.tuikKodu}"/>
<h:outputText value="İva Kodu:"/><p:inputText value="#{urunlist.mahsul.tvaKodu}"/>
<h:outputText value="Üretim Dönemi:"/><p:autoComplete value="#{urunlist.mahsul.uretimDonemi}" completeMethod="#{urunlist.autoComplate(ud)}" var="ud_list" itemLabel="#{ud_list.uretimDonemi}" converter="javax.faces.Character" itemValue="#{ud_list}" forceSelection="false" multiple="false"/>
<h:outputText value="Üretim Şekli"/><p:inputText value="#{urunlist.mahsul.uretimSekli}"/>
<p:commandButton action="#{urunlist.urunKaydet()}" value="Kaydet" update="dataTable"/><input name="hiddo" type="hidden" value="#{login.kullaniciAdi}"/>
</p:panelGrid>
</p:panel>
</ui:insert>
</p:panel>
<p:panel id="viewPanel">
<ui:insert>view Layout</ui:insert>
</p:panel>
<p:panel id="updatePanel">
<ui:insert>Update Form</ui:insert>
</p:panel>
</p:panelGrid>
</div>
<div>
<p:outputPanel id="dataTable" >
<p:panel header="Ürünler">
<p:dataTable value="#{urunlist.urunGetir()}" var="u" paginator="true" rows="5" editable="true" sortOrder="true" draggableColumns="true" rowKey="#{u.urunKodu}">
<p:ajax event="rowEdit" listener="#{urunlist.urunGuncelle}" update=":mainForm:messages"/>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.urunKodu}"/>
</f:facet>
<f:facet name="input">
<input name="ukod" value="#{u.urunKodu}" type="hidden" disabled="true" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.tuikKodu}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{u.tuikKodu}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.tvaKodu}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{u.tvaKodu}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.urunAdi}"/>
</f:facet>
<f:facet name="input">
<h:inputText value="#{u.urunAdi}"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{u.uretimDonemi}(#{u.uretimSekli}-#{u.sulama})"/>
</f:facet>
<f:facet name="input">
<p:panelGrid columns="3">
<p:column>
<h:inputText size="2" value="#{u.uretimDonemi}" title="Üretim Dönemi"/>
</p:column>
<p:column>
<h:inputText size="2" value="#{u.uretimSekli}"/>
</p:column>
<p:column>
<h:inputText size="2" value="#{u.sulama}"/>
</p:column>
</p:panelGrid>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
#{u.ekleyen}
</p:column>
<p:column>
<h:outputText value="#{u.eklemeZamani}">
<f:convertDateTime pattern="dd.MMMM.yy--hh:mm:ss" timeZone="Turkey"/> </h:outputText>
</p:column>
<p:column>
<p:rowEditor/>
</p:column>
</p:dataTable>
</p:panel>
</p:outputPanel>
</div>
</h:form>
</ui:define>
My ManagedBean
public LoginBean getLoginned() {
return loginned;
}
public void setLoginned(LoginBean loginned) {
this.loginned = loginned;
}
public urunBean(){
mahsul=new urun();
loginned=new LoginBean();
}
public urun getMahsul() {
return mahsul;
}
public void setMahsul(urun mahsul) {
this.mahsul = mahsul;
}
public List<urun> urunGetir() throws SQLException{
try {
vk=DriverManager.getConnection("jdbc:postgresql://localhost:5432/uretim","postgres","Fa1276");
} catch (SQLException ex) {
System.out.println("DriverManager hatası "+ex);
}
PreparedStatement ps=vk.prepareStatement("select urun_kodu, tuik_kodu, iva_kodu, urun_adi, uretim_donemi, uretim_sekli, sulama, ekleyen, ekleme_zamani from urunler order by urun_kodu desc");
ResultSet sonuc=ps.executeQuery();
liste = new ArrayList<urun>();
while (sonuc.next()){
masul=new urun();
masul.setUrunKodu(sonuc.getLong("urun_kodu"));
masul.setTuikKodu(sonuc.getLong("tuik_kodu"));
masul.setTvaKodu(sonuc.getLong("iva_kodu"));
masul.setUrunAdi(sonuc.getString("urun_adi"));
masul.setUretimDonemi(sonuc.getString("uretim_donemi"));
masul.setUretimSekli(sonuc.getString("uretim_sekli"));
masul.setSulama(sonuc.getBoolean("sulama"));
masul.setEkleyen(sonuc.getString("ekleyen"));
masul.setEklemeZamani(sonuc.getTimestamp("ekleme_zamani"));
liste.add(masul);
}
return this.liste;
}
public void urunKaydet(){
String urunEkle=("insert into urunler(urun_kodu, tuik_kodu, iva_kodu, urun_adi, uretim_donemi, uretim_sekli, sulama, ekleyen, ekleme_zamani) values (nextval('urunler_urun_kodu_seq'),?,?,?,?,?,?,?, now())");
try {
PreparedStatement insert=vk.prepareStatement(urunEkle);
insert.setLong(1, mahsul.getTuikKodu());
insert.setLong(2,mahsul.getTvaKodu());
insert.setString(3,mahsul.getUrunAdi());
insert.setString(4,mahsul.getUretimDonemi());
insert.setString(5, mahsul.getUretimSekli());
insert.setBoolean(6,false);
insert.setString(7,session);
//insert.setString(9,java.sql.Timestamp);
//insert.executeQuery();
insert.executeUpdate();
insert.close();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage( mahsul.urunAdi+" ürünü\nkaydedildi "));
//String selectInput= UIComponent.getCurrentComponent(null).getId().toString();
//System.out.println(selectInput);
}
catch (SQLException sqe){
System.out.println("sorguda hata var "+sqe);
}
}
public List<urun> autoComplate(urun ud) throws SQLException{
PreparedStatement udps=vk.prepareStatement("select uretim_donemi from urunler group by uretim_donemi");
ResultSet udset=udps.executeQuery();
List<urun> ud_list=new ArrayList<urun>();
while(udset.next()){
ud.uretimDonemi=udset.getString("uretim_donemi");
ud_list.add(ud);
}
/*
PreparedStatement usps=vk.prepareStatement("select uretim_sekli from urunler group by uretim_sekli");
ResultSet usset=usps.executeQuery();
List<urun> us_list=new ArrayList<urun>();
while(usset.next()){
urun us=new urun();
us.uretimSekli=usset.getString("uretim_sekli");
us_list.add(us);
return us_list;
}
*/
return ud_list;
}
public void urunGuncelle(RowEditEvent olay){
this.vk=vk;
urun urn=(urun)olay.getObject();
ExternalContext getirici=FacesContext.getCurrentInstance().getExternalContext();
String gullanici=getirici.getRequestParameterMap().get("hiddo");
//String gullanici=user.getKullaniciAdi();
Long id=(Long)urn.getUrunKodu();
System.out.println(id+"-"+gullanici);
try {
PreparedStatement urunguncelle=vk.prepareStatement("update urunler set urun_adi=?, uretim_donemi=?, uretim_sekli=?, guncelleyen=?, guncelleme_zamani=now() where urun_kodu=?");
urunguncelle.setString(1, urn.getUrunAdi());
urunguncelle.setString(2, urn.getUretimDonemi());
urunguncelle.setString(3, urn.getUretimSekli());
urunguncelle.setString(4, gullanici);
urunguncelle.setLong(5, id);
urunguncelle.executeUpdate();
int etkilenen=urunguncelle.executeUpdate();
if (etkilenen > 0) {
System.out.println(urn.getUrunAdi()+" adlı ürün güncellendi "+etkilenen+" satır.");
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(urn.urunAdi+" adlı ürün güncellendi"));
System.out.println(urn.getUrunAdi()+" adlı ürün güncellendi!");
}else{
System.out.println("Güncelleme olmadı");
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage("Güncelleme olmadı."));
}
urunguncelle.close();
vk.close();
} catch (SQLException ex) {
System.out.println("Güncelleme hatası "+ex);
}
}
/*
public void deneme(urun u){
String mesaj=("Ellediğiniz satırın id'si "+u.urunKodu+"!");
FacesContext.getCurrentInstance().addMessage(null,new FacesMessage(mesaj));
}*/
}
I solved my problem. I overrideded boolean, hashcode and toString methods. I added a constructor my bean about my select query methods.

JSF 2 view scoped bean not updated when action is called second time

I have a view scoped arrayList as bean. This is used to display the editable columns of dataTable. When the page is displayed initially and I try to update the table contents the update works fine, however when I try to update any column the second time the values which are changed do not reflect in the arrayList bean (verified in the action method using break point). The action method is also a managed bean with view scope.
<managed-bean>
<managed-bean-name>financialListBean</managed-bean-name>
<managed-bean-class>java.util.ArrayList</managed-bean-class>
<managed-bean-scope>view</managed-bean-scope>
</managed-bean>
Below is the code for dataTable
<h:form id="myform">
<h:dataTable id="financialListBean1"
value="#{financialListBean}" var="varfinancialListBean"
styleClass="dataTableEx" headerClass="headerClass"
footerClass="footerClass"
rowClasses="rowClass1, rowClass2"
columnClasses="columnClass1" border="0" cellpadding="2"
cellspacing="0">
<h:column id="columnEx17">
<h:selectBooleanCheckbox styleClass="inputRowSelect"
id="rowSelect3"
value="#{varfinancialListBean.rowSelected}"></h:selectBooleanCheckbox>
<f:facet name="header"></f:facet>
</h:column>
<h:column id="amount1column">
<f:facet name="header">
<h:outputText styleClass="outputText" value="Amount"
id="amount1text"></h:outputText>
</f:facet>
<h:inputText styleClass="small8Input" id="amount1"
value="#{varfinancialListBean.amount}" onkeypress="return only5DigitsEntry(this, event);" onkeyup="return checkRequiredFieldsForUpdateFinancialBtn(this.form, event);">
</h:inputText>
</h:column>
<h:column id="type1column">
<h:selectOneMenu styleClass="selectOneMenu" id="menu1" value="#{varfinancialListBean.type}">
<f:selectItem itemLabel="M" itemValue="M" />
<f:selectItem itemLabel="Y" itemValue="Y" />
<f:selectItem itemLabel="Z" itemValue="Z" />
<f:selectItem itemLabel="O" itemValue="O" />
<f:selectItem itemLabel="S" itemValue="S" />
</h:selectOneMenu>
<f:facet name="header">
<h:outputText styleClass="outputText" value="Type"
id="type1text"></h:outputText>
</f:facet>
</h:column>
<h:column id="recDate1column">
<f:facet name="header">
<h:outputText styleClass="outputText"
value="Recieve Date" id="recDate1text"></h:outputText>
</f:facet>
<h:inputText styleClass="outputText" id="recDate1"
value="#{varfinancialListBean.recDate}"
onclick="getClock($(this).attr('id'))" >
<f:convertDateTime pattern="MMM d, yyyy"/>
</h:inputText>
</h:column>
</h:dataTable>
<h:commandButton type="submit"
value="Update Financial Information"
styleClass="commandExButton" id="updateFinancialBtn"
action="#{pc_SocialServicesView.doFinancialUpdateBtnAction}">
<f:param name="mrn" value="#{pc_SocialServicesView.mrn}" />
</h:commandButton>
</h:form>
The action method:
public String doFinancialUpdateBtnAction() {
System.out.println("I am at doFinancialUpdateBtnAction");
try{
if(mrn.length()==0){
mrn=getFacesContext().getExternalContext().getRequestParameterMap().get("mrn");
}
setFinancialListBean(dba.updateFinancialAsistance
(getFinancialListBean(), mrn));
setErrorMsgBean("Updated successfully ...");
doInit(mrn);
}catch (Exception e) {
System.out.println("There is an exception at doFinancialUpdateBtnAction");
Log.out.error("Error in doFinancialUpdateBtnAction: "+e);
setErrorMsgBean("No record was updated ...");
e.printStackTrace();
}
return "";
}

Resources