I want to make a weekly range date for selected date which is captured when i clicked a date on calendar . This is the code that i've made.
package com.cc.cielo.backingbean.timesheet;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import org.joda.time.DateTime;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import com.cc.cielo.backingbean.BaseBackingBean;
import com.cc.cielo.managedbean.timesheet.TimesheetManagedBean;
#ManagedBean(name = "timesheetBackingBean")
#RequestScoped
public class TimesheetBackingBean extends BaseBackingBean<TimesheetManagedBean> {
public String createDateRange() {
Date selDate = this.getManagedBean().getSelectedDate();
return null;
}
public TimesheetBackingBean(){
}
}
<p:column colspan="2" >
</p:column>
<p:column colspan="7">
<p:panelGrid style="width:100%">
<p:row style="color: ##bfbfbf">
<p:column style="width:20%">
<p:button icon="ui-icon-triangle-1-w" disabled="false">
<f:param name="productId" value="10" />
</p:button>
</p:column>
<p:column style="width:60%; text-align:center">
<h:outputLabel value="#{timesheetBackingBean.createDateRange}" />
</p:column>
<p:column style="width:20%; text-align:right">
<p:button icon="ui-icon-triangle-1-e" disabled="false">
<f:param name="productId1" value="10" />
</p:button>
</p:column>
</p:row>
</p:panelGrid>
</p:column>
<p:column colspan="7" style="text-align: right;">
<p:calendar id="event" value="#{timesheetBackingBean.managedBean.selectedDate}" showOn="button" pattern="dd/MM/yyyy" mask="true">
<p:ajax event="dateSelect" listener="#{timesheetBackingBean.createDateRange}" />
</p:calendar>
</p:column>
</p:row>
</f:facet>
now i want to paste the weekly range from the date i've choosed into that output label.
With some research on google . i found my answer for my question.
public String createDateRange() {
Date selDate = this.getManagedBean().getSelectedDate();
Date date = new Date();
Calendar c = new GregorianCalendar();
c.setTime(selDate);
c.setFirstDayOfWeek(Calendar.MONDAY);
int i = c.get(Calendar.DAY_OF_WEEK) - c.getFirstDayOfWeek();
c.add(Calendar.DATE, -i);
Date start = c.getTime();
c.add(Calendar.DATE, 6);
Date end = c.getTime();
System.out.println(start + " - " + end);
SimpleDateFormat format1 = new SimpleDateFormat("dd/MM/yyyy");
String formatted = format1.format(start);
String formatted2 = format1.format(end);
this.getManagedBean().setDateRange(formatted + " - " + formatted2);
return null;
}
<p:column style="width:60%;text-align: center;">
<h:outputLabel id="dateRange" value="#{timesheetBackingBean.managedBean.dateRange}"/>
</p:column>
<p:column style="width:20%; text-align:right">
<p:button icon="ui-icon-triangle-1-e" disabled="false">
<f:param name="productId1" value="10" />
</p:button>
</p:column>
</p:row>
</p:panelGrid>
</p:column>
<p:column colspan="7" style="text-align: right;">
<p:calendar id="event" value="#{timesheetBackingBean.managedBean.selectedDate}" imediate="true" showOn="button" pattern="dd/MM/yyyy" mask="true">
<p:ajax event="dateSelect" listener="#{timesheetBackingBean.createDateRange}" update="dateRange" />
</p:calendar>
</p:column>
Related
I am working on #ViewScoped annotation in JSF2.0. Below is the code what I had written. It is not working as I expected. Please review it and let me know if any changes are required to get the exact output that what am thinking of.
Here is my Controller SearchController.java
package com.s2tech.jsfapp.controllers;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import com.s2tech.jsfapp.helper.SearchHelper;
import com.s2tech.jsfapp.managedbean.SearchManagedBean;
#ManagedBean(name ="searchController")
#ViewScoped
public class SearchController implements Serializable{
public SearchController(){
private static final long serialVersionUID = 1L;
SearchHelper searchHelper;
private List<SearchManagedBean> employeeList=new ArrayList<SearchManagedBean>();
public List<SearchManagedBean> getEmployeeList() {
return employeeList;
}
public void setEmployeeList(List<SearchManagedBean> employeeList) {
this.employeeList = employeeList;
}
public void getEmployee(SearchManagedBean searchManagedBean) {
searchHelper=new SearchHelper();
employeeList = searchHelper.getEmployee(searchManagedBean);
//return "search.xhtml";
//return Constants.searchPage;
// return null;
}
Below is my view search.xhtml
<h:body style="background-color:skyblue;">
<ui:include src="mainMenu.xhtml"></ui:include>
<h:form prependId="false">
<table>
<tr style="display:block;margin-top:10px;width:100%;margin-left:40%">
<td style="width:40%">
<p:outputLabel for="firstName" value="First Name:" style="font-weight:bold" />
<p:inputText id="firstName" value="#{searchManagedBean.firstName}" required="true" requiredMessage="please enter First Name"> </p:inputText>
<p:message id="firstNameMsg" for="firstName" showDetail="true" ></p:message>
</td>
<td style="width: 20%"></td>
<td style="width:40%;">
<p:outputLabel for="lastName" value="Last Name:" style="font-weight:bold"/>
<p:inputText id="lastName" value="#{searchManagedBean.lastName}" required="true" requiredMessage="please enter Last Name" />
<p:message id="lastNameMsg" for="lastName" showDetail="true" ></p:message>
</td>
</tr>
<tr style="display:block;margin-top:10px;width:100%;margin-left:78%">
<td style="width:40%"> <p:commandButton value="Search" action="#{searchController.getEmployee(searchManagedBean)}" update="firstNameMsg lastNameMsg emailMsg phoneMsg dataTable"/></td>
</tr>
</table>
</h:form>
<p:dataTable id="dataTable" var="emp" rendered="#{not empty searchController.employeeList}" value="#{searchController.employeeList}" rowStyleClass="table table-striped table-hover table-bordered" resizableColumns="true" resizeMode="expand" scrollWidth="50%" scrollHeight="150" >
<p:column headerText="First Name">
<h:outputText value="#{emp.firstName}"/>
</p:column>
<p:column headerText="Last Name">
<h:outputText value="#{emp.lastName}"/>
</p:column>
<p:column headerText="Email">
<h:outputText value="#{emp.email}"/>
</p:column>
<p:column headerText="Phone">
<h:outputText value="#{emp.phone}"/>
</p:column>
<p:column headerText="Edit">
<p:commandLink value="Edit" action="#{searchController.getEditForm(emp)}" style="margin-left:40px;color:blue;"></p:commandLink>
</p:column>
</p:dataTable>
</h:body>
</html>
My question is that after entering first name and last name, when I click on submit button it need to hit controller's getEmployee() method and it needs to display data table values from controller's getEmployeeList(). Here eventhough using ViewScoped bean Iam not getting output. Any suggestions??
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);
}
}
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"/>
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.
I am using primefaces 3.0 and jsf 2.0.
I have prepared client master which add client using wizard and at the same time reflected in datatable. Then I have updated edit utility in datatable. Then I have added delete button in datatable and try call delete method of bean.
But when I click on delete button wizard validation for adding client is executed.
So I have created another file ClientEditdatatable.xhtml and included in clientmaster.xhtmlbut same result remain.
Now I want to add delete utility in datatable. I have tried many tricks to do it.
I just want to pass client id through action listener,get deleted and refresh datatable but command button not executing method.
Kindly advice.
My code as below:
ClientMaster.xhtml
<h:body>
<ui:composition template="/template/mainLayout.xhtml" >
<ui:define name="pageContent">
<h:form id="cm">
<p:growl life="5000" showDetail="true" showSummary="true" id="mymessage" autoUpdate="true"/>
<br/>
user id :#{sessionScope.USER_ID};
<br/>
<p:wizard widgetVar="wiz" flowListener="#{clientUitility.onFlowProcess}" showNavBar="true" >
<p:tab id="personal" title="Personal" >
<p:panel id="personal1" header="Personal Details">
<!-- <h:messages errorClass="error"/> -->
<h:panelGrid columns="6" styleClass="grid">
<h:outputText value="First Name:*" />
<p:inputText required="true" label="FirstName"
value="#{clientUitility.client.firstName}" >
</p:inputText>
<h:outputText value="Middle Name:*" />
<p:inputText required="true" label="MidddleName"
value="#{clientUitility.client.middleName}" />
<h:outputText value="Last Name:*" />
<p:inputText required="true" label="LastName"
value="#{clientUitility.client.lastName}" />
<h:outputText value="Login ID:* " />
<p:inputText required="true" label="LoginID"
value="#{clientUitility.client.loginID}"/>
<h:outputText value="Password:* " />
<p:inputText required="true" label="Password"
value="#{clientUitility.client.password}"/>
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="address" title="Address" >
<p:panel id="address1" header="Adress Details">
<!-- <h:messages errorClass="error"/> -->
<h:panelGrid columns="6" styleClass="grid">
<h:outputText value="Address:*" />
<p:inputText required="true" label="Address1"
value="#{clientUitility.client.address1}" />
<h:outputText />
<p:inputText label="Address2"
value="#{clientUitility.client.address2}" />
<h:outputText />
<p:inputText label="Address3"
value="#{clientUitility.client.address3}" />
<h:outputText value="City:* " />
<p:inputText required="true" label="City"
value="#{clientUitility.client.city}" />
<h:outputText value="Pincode:* " />
<p:inputText required="true" label="Pincode"
value="#{clientUitility.client.pincode}" />
<h:outputText value="State:* " />
<p:inputText required="true" label="State"
value="#{clientUitility.client.state}" />
</h:panelGrid>
</p:panel>
</p:tab>
<p:tab id="contact" title="Contact" >
<p:panel id="contact1" header="Contact Information">
<!-- <h:messages errorClass="error"/> -->
<p:panelGrid columns="4" styleClass="grid">
<h:outputText value="Mobile:* " />
<p:inputText required="true" label="MobileNo"
value="#{clientUitility.client.mobileNo}" />
<h:outputText value="Email ID: "/>
<p:inputText label="EmailID"
value="#{clientUitility.client.emailID}" />
<h:outputText value="STD Code: "/>
<p:inputText label="STDCode"
value="#{clientUitility.client.stdCode}" />
<h:outputText value="Phone No: "/>
<p:inputText label="PhoneNo"
value="#{clientUitility.client.phoneNo}" /> </p:panelGrid>
</p:panel>
</p:tab>
<p:tab id="confirm" title="Confirmation" >
<p:panel id="confirm1" header="Confirm and Submit">
<h:panelGrid columns="6" styleClass="grid" >
<h:outputText value="First Name: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.firstName}" />
<h:outputText value="Middle Name: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.middleName}" />
<h:outputText value="Last Name: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.lastName}" />
<h:outputText value="Login ID: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.loginID}"/>
<h:outputText value="Password: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.password}"/>
<h:outputText/>
<h:outputText/>
<h:outputText value="Address: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.address1}" />
<h:outputText />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.address2}" />
<h:outputText />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.address3}" />
<h:outputText value="City: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.city}" />
<h:outputText value="State: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.state}" />
<h:outputText value="Pincode: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.pincode}" />
<h:outputText value="Email ID: " />
<h:outputText styleClass="outputLabel"
value="#{clientUitility.client.emailID}" />
<p:commandButton id="addClient" immediate="true" value="Add Client" actionListener="#{clientUitility.save}" oncomplete="wiz.loadStep (wiz.cfg.steps [0], true)" update="#parent,:cm:clientList"> <!-- update="#parent,:cm:clientList" -->
</p:commandButton>
</h:panelGrid>
</p:panel>
</p:tab>
</p:wizard>
<ui:include id="ce" src="ClientEditDatatable.xhtml"/>
</h:form>
</ui:define>
</ui:composition>
</h:body>
ClientEditDatatable.xhtml
<h:body>
<h:form id="fce">
<p:confirmDialog message="Delete client?" severity="alert" widgetVar="confirmDeleteClient" visible="false" appendToBody="true">
<p:commandButton value="Yes" update=":cm:fce:clientList" oncomplete="confirmDeleteClient.hide()" actionListener="#{clientUitility.deleteRecord}" >
</p:commandButton>
<p:commandButton value="No" onclick="confirmDeleteClient.hide()" type="button" />
</p:confirmDialog>
<p:dataTable var="client" value="#{clientUitility.clientAll}" id="clientList" editable="true"
rowKey="#{client.clientID}" paginator="true" rows="10" rowsPerPageTemplate="10,15,20">
<p:column headerText="First Name" style="width:125px" filterBy="#{user.firstname}" sortBy="#{client.firstName}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.firstName}" />
</f:facet>
<f:facet name="input">
<h:outputText value="#{client.firstName}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Middle Name" style="width:125px" filterBy="#{client.middleName}" sortBy="#{client.middleName}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.middleName}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.middleName}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Last Name" style="width:125px" filterBy="#{client.lastName}" sortBy="#{client.lastName}" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.lastName}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.lastName}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Login ID" style="width:125px" filterBy="#{client.loginID}" sortBy="#{client.loginID}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.loginID}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.loginID}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Password" style="width:125px" filterBy="#{client.password}" sortBy="#{client.password}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.password}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.password}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Address1" style="width:125px" filterBy="#{client.address1}" sortBy="#{client.address1}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.address1}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.address1}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Address2" style="width:125px" filterBy="#{client.address2}" sortBy="#{client.address2}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.address2}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.address2}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Address3" style="width:125px" filterBy="#{client.address3}" sortBy="#{client.address3}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.address3}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.address3}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="City" style="width:125px" filterBy="#{client.city}" sortBy="#{client.city}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.city}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.city}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="State" style="width:125px" filterBy="#{client.state}" sortBy="#{client.state}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.state}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.state}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Pincode" style="width:125px" filterBy="#{client.pincode}" sortBy="#{client.pincode}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.pincode}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.pincode}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Mobile No" style="width:125px" filterBy="#{client.mobileNo}" sortBy="#{client.mobileNo}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.mobileNo}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.mobileNo}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="STD Code" style="width:125px" filterBy="#{client.stdCode}" sortBy="#{client.stdCode}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.stdCode}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.stdCode}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Phone No" style="width:125px" filterBy="#{client.phoneNo}" sortBy="#{client.phoneNo}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.phoneNo}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.phoneNo}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Email ID" style="width:125px" filterBy="#{client.emailID}" sortBy="#{client.emailID}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{client.emailID}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{client.emailID}" style="width:100%" >
</p:inputText>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px">
<p:rowEditor />
</p:column>
<p:ajax event="rowEdit" listener="#{clientUitility.editRowListner}" update=":cm:mymessage"/>
<p:column headerText="Delete" style="width:50px">
<p:commandButton id="deleteClient" value="Delete" onclick="confirmDeleteClient.show()" title="Delete this Client" styleClass="ui-icon-closethick">
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
</h:body>
clientUtility.java
#ManagedBean
#ViewScoped
public class ClientUitility {
private ClientBean client = new ClientBean();
private List<ClientBean> clientAll = new ArrayList<ClientBean>();
/** Creates a new instance of ClientUitility */
public ClientUitility() {
clientAll = new ArrayList<ClientBean>();
int userID = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString());
clientAll = ClientService.GenerateClientList(userID);
}
public List<ClientBean> getClientAll() {
return clientAll;
}
public void setClientAll(List<ClientBean> clientAll) {
this.clientAll = clientAll;
}
public ClientBean getClient() {
return client;
}
public void setClient(ClientBean client) {
this.client = client;
}
public String onFlowProcess(FlowEvent event) {
System.out.println("Current wizard step:" + event.getOldStep());
System.out.println("Next step:" + event.getNewStep());
System.out.println("First name : " + client.getfirstName());
System.out.println("Last name : " + client.getlastName());
System.out.println("Age name : " + client.getloginID());
return event.getNewStep();
}
public void editRowListner(RowEditEvent rowEditEvent) {
try {
ClientBean updatedClient = (ClientBean) rowEditEvent.getObject();
System.out.println("Client First Name: " + updatedClient.getfirstName());
ClientService.EditClient(updatedClient);
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, new FacesMessage("Updated", updatedClient.getfirstName() + " " + updatedClient.getlastName()));
} catch (Exception e) {
e.getMessage();
}
}
public void deleteRecord(ActionEvent actionEvent) {
try {
//System.out.println("Client ID: " + actionEvent.getComponent().getAttributes().get("cID").toString());
System.out.println("delete client of User ID: " + FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString());
FacesMessage msg = new FacesMessage("Client Deleted", "");
FacesContext.getCurrentInstance().addMessage(null, msg);
} catch (Exception e) {
e.printStackTrace();
}
}
public void save(ActionEvent actionEvent) { client.setuserID(Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString()));
System.out.println("Client ID : " + client.getclientID());
System.out.println("User ID : " + client.getuserID());
ClientService.AddClient(client);
client = new ClientBean();
clientAll = ClientService.GenerateClientList(Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("USER_ID").toString()));
FacesMessage msg = new FacesMessage("Client Created", "");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
Kindly advice where am I mistaking?
You can't and shouldn't nest forms.
In the ClientMaster.xhtml, replace
<ui:include id="ce" src="ClientEditDatatable.xhtml"/>
</h:form>
by
</h:form>
<ui:include id="ce" src="ClientEditDatatable.xhtml"/>
See also:
commandButton/commandLink/ajax action/listener method not invoked or input value not updated