I have a little probleme with primefaces dataTable,
i have set a commandButton inside my table inorder to delete data from the table
but whene i choose to delete a row i found that it had deleted 2 rows not just one
this is my Bean
package com.beans;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;
import org.primefaces.event.CellEditEvent;
import org.primefaces.event.RowEditEvent;
import com.bo.DiplomeBo;
import com.converter.DiplomeDataModel;
import com.model.Collaborateur;
import com.model.Diplome;
public class DiplomeBean {
public Integer idDiplome;
public String ecole;
public String typeEcole;
public String typeDiplome;
public Integer promotion;
private Set<Collaborateur> collaborateurs = new HashSet<Collaborateur>(0);
public Diplome selectedDiplome;
private DiplomeBo diplomeBo;
public Diplome getSelectedDiplome() {
return selectedDiplome;
}
public void setSelectedDiplome(Diplome selectedDiplome) {
this.selectedDiplome = selectedDiplome;
}
public Integer getIdDiplome() {
return idDiplome;
}
public void setIdDiplome(Integer idDiplome) {
this.idDiplome = idDiplome;
}
public String getEcole() {
return ecole;
}
public void setEcole(String ecole) {
this.ecole = ecole;
}
public String getTypeEcole() {
return typeEcole;
}
public void setTypeEcole(String typeEcole) {
this.typeEcole = typeEcole;
}
public Integer getPromotion() {
return promotion;
}
public void setPromotion(Integer promotion) {
this.promotion = promotion;
}
public Set<Collaborateur> getCollaborateurs() {
return collaborateurs;
}
public void setCollaborateurs(Set<Collaborateur> collaborateurs) {
this.collaborateurs = collaborateurs;
}
public void setDiplomeBo(DiplomeBo diplomeBo) {
this.diplomeBo = diplomeBo;
}
public String getTypeDiplome() {
return typeDiplome;
}
public void setTypeDiplome(String typeDiplome) {
this.typeDiplome = typeDiplome;
}
public String AddDiplome() {
Diplome diplome = new Diplome();
diplome.setEcole(getEcole());
diplome.setPromotion(getPromotion());
diplome.setTypeDiplome(getTypeDiplome());
diplome.setTypeEcole(getTypeEcole());
diplomeBo.addDiplome(diplome);
clearForm();
return "Ajout Bien Fait !!";
}
public String UpdateDiplome(Diplome dip) {
diplomeBo.updateDiplome(dip);
return "Update Bien Fait";
}
public String DeleteDiplome(Diplome diplome){
diplomeBo.deleteDiplome(diplome);
clearForm();
return "";
}
public List<Diplome> getAllDiplome() {
return diplomeBo.findAllDiplome();
}
private void clearForm() {
this.setEcole("");
this.setPromotion(0);
this.setTypeEcole("");
this.setTypeEcole("");
}
public void onEdit(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Diplome Edited");
Integer i = ((Diplome) (event.getObject())).getIdDiplome();
Diplome d = new Diplome();
d.setIdDiplome(i);
d.setEcole(this.getEcole());
this.UpdateDiplome(d);
FacesContext.getCurrentInstance().addMessage(null, msg);
clearForm();
}
public void onCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Diplome Cancelled");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
this is my page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<body>
<f:view>
<h:outputLink value="Admin/default.xhtml">Go to your app</h:outputLink>
<h:form id="form">
<p:growl id="messages" showDetail="true" />
<p:dataTable var="dip" value="#{diplome.getAllDiplome()}" id="diplomeList"
editable="true">
<f:facet name="header">
In-Cell Editing
</f:facet>
<p:ajax event="rowEdit" listener="#{diplome.onEdit}"
/>
<p:ajax event="rowEditCancel" listener="#{diplome.onCancel}"
/>
<p:column headerText="ID" style="width:10%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{dip.idDiplome}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{dip.idDiplome}#{diplome.idDiplome}" style="width:100%" readonly="true" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Ecole" style="width:20%">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{dip.ecole}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{diplome.ecole}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6%">
<p:rowEditor />
</p:column>
<p:column>
<p:commandButton icon="ui-icon-trash"
title="Delete this actor"
action="#{diplome.DeleteDiplome(dip)}"
ajax="false" />
</p:column>
</p:dataTable>
</h:form>
</f:view>
</body>
</html>
Related
I'm trying to use a Primefaces dialog to insert an entity object in a database, it works the first time I use the dialog, the keeps the same bean inside the dialog when I try to use it the second time, here is my code:
this is in the file index.xhtml I have a table called patients and this is the footer:
<f:facet name="footer">
<p:outputPanel>
<p:growl id="growl" showDetail="true" />
<p:commandButton value="Add Patient" icon="ui-icon-extlink"
actionListener="#{patientsViewBean.addNewPatientDialog}">
<p:ajax event="dialogReturn"
listener="#{patientsViewBean.onDialogReturn}" update="patients" />
</p:commandButton>
</p:outputPanel>
</f:facet>
the dialog page is addNewDialog.xhtml it contains:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Add New Patient</title>
<style type="text/css">
.ui-widget {
font-size: 80%;
}
</style>
</h:head>
<h:body>
<p:panel style="margin: 2px;">
<h:form id="form" >
<p:growl id="msgs" showDetail="true" />
<p:panel title="Patient Personal Information" header="Patient Personal Information">
<p:panelGrid style="margin: 2px 2px 2px 2px" columns="2"
columnClasses="label, value">
<p:outputLabel value="First Name: *"></p:outputLabel>
<p:inputText value="#{newPatientView.patient.firstName}"
required="true" label="First Name"></p:inputText>
<p:outputLabel value="Father Name: *"></p:outputLabel>
<p:inputText value="#{newPatientView.patient.fatherName}"
required="true" label="Father Name"></p:inputText>
<p:outputLabel value="Family Name: *"></p:outputLabel>
<p:inputText value="#{newPatientView.patient.familyName}"
required="true" label="Family Name"></p:inputText>
<p:outputLabel value="Mother Name: *"></p:outputLabel>
<p:inputText value="#{newPatientView.patient.motherName}"
required="true" label="Mother Name"></p:inputText>
<p:outputLabel value="Birth Date"></p:outputLabel>
<p:calendar id="bdate" value="#{newPatientView.patient.birthDate}"
locale="ar" navigator="true" yearRange="c-120:c" effect="fade"
mask="true" pattern="yyyy-MM-dd" required="true" />
<p:outputLabel value="Birth Place: "></p:outputLabel>
<p:inputText value="#{newPatientView.patient.birthPlace}"
required="false" label="Birth Place"></p:inputText>
</p:panelGrid>
</p:panel>
<p:panel title="Contact Information" header="Contact Information">
<p:remoteCommand name="updateButtonsStatus"
process="#this contactInfoTable:buttons"
update="contactInfoTable:buttons"></p:remoteCommand>
<p:dataTable id="contactInfoTable" var="cntctInfo"
selectionMode="single" rowKey="#{cntctInfo}"
selection="#{newPatientView.cntctInfo}"
value="#{newPatientView.patient.contactInfoList}" editable="true"
widgetVar="cellCntctInfo">
<p:ajax event="rowEditInit"
listener="#{newPatientView.onRowEditInit}"
oncomplete="updateButtonsStatus()" />
<p:ajax event="rowEdit" immediate="true"
listener="#{newPatientView.onRowEdit}" update=":form:msgs"
oncomplete="updateButtonsStatus()" />
<p:ajax event="rowEditCancel"
listener="#{newPatientView.onRowCancel}"
oncomplete="updateButtonsStatus()" />
<p:column headerText="Email">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cntctInfo.email}" />
</f:facet>
<f:facet name="input">
<p:inputText id="emailInput" value="#{cntctInfo.email}"
style="width:95%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Phone">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cntctInfo.phone}" />
</f:facet>
<f:facet name="input">
<p:inputText id="phoneInput" value="#{cntctInfo.phone}"
style="width:95%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Type">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cntctInfo.type}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu id="typeInput" value="#{cntctInfo.type}"
style="width:100%; height: 95%">
<f:selectItem itemLabel="Main" itemValue="Main"></f:selectItem>
<f:selectItem itemLabel="Home" itemValue="Home"></f:selectItem>
<f:selectItem itemLabel="Work" itemValue="Work"></f:selectItem>
<f:selectItem itemLabel="Perm" itemValue="Perm"></f:selectItem>
<f:selectItem itemLabel="Curr" itemValue="Curr"></f:selectItem>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:32px">
<p:rowEditor />
</p:column>
<f:facet name="footer">
<p:outputPanel id="buttons" autoUpdate="true">
<p:commandButton value="Add New" process="#this contactInfoTable"
actionListener="#{newPatientView.onAddNewContactInfo}"
update="contactInfoTable :form:msgs"
disabled="#{newPatientView.addContactInfoDisabled}" />
<p:commandButton value="Delete Seleced"
process="#this contactInfoTable"
actionListener="#{newPatientView.onDeleteSelectedContactInfo}"
update="contactInfoTable :form:msgs"
disabled="#{newPatientView.deleteSelectedContactInfoDisabled}" />
</p:outputPanel>
</f:facet>
</p:dataTable>
</p:panel>
<p:panel>
<p:commandButton value="Save" actionListener="#{newPatientView.onDialogApprove}"></p:commandButton>
<p:commandButton value="Discard" actionListener="#{newPatientView.onDialogCancel}"></p:commandButton>
</p:panel>
</h:form>
</p:panel>
</h:body>
</html>
I have two baking beans newPatientView with this code:
package me.bttb.crs.beans.patient;
import java.util.ArrayList;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.view.ViewScoped;
import javax.inject.Inject;
import javax.inject.Named;
import org.primefaces.context.RequestContext;
import org.primefaces.event.RowEditEvent;
import me.bttb.crs.model.ContactInfo;
import me.bttb.crs.model.Ptnt;
#Named
#ManagedBean
#ViewScoped
public class NewPatientView {
#Inject
private PatientDAO patientDAO;
private Ptnt patient;
private List<ContactInfo> cntctInfoList;
private ContactInfo cntctInfo;
private boolean addContactInfoDisabled = false;
private boolean deleteSelectedContactInfoDisabled = true;
boolean confirm = false;
public NewPatientView() {
init();
}
public void init() {
this.setPatient(new Ptnt());
this.setCntctInfoList(new ArrayList<>());
this.getPatient().setContactInfoList(this.getCntctInfoList());
}
/////////////// EVENTS//////////////////
public void onAddNewContactInfo(ActionEvent event) {
if (patient.getContactInfoList() == null)
patient.setContactInfoList(new ArrayList<>());
boolean hasNewRow = patient.getContactInfoList().stream()
.filter(ci -> ci.getEmail() == null && ci.getPhone() == null).count() >= 1;
if (hasNewRow) {
FacesMessage msg = new FacesMessage("Can't add new row", "There is an empty row already!!");
FacesContext.getCurrentInstance().addMessage(null, msg);
} else {
ContactInfo cntctInfo = new ContactInfo();
cntctInfo.setType("Main");
cntctInfo.setPrsn(patient);
patient.getContactInfoList().add(cntctInfo);
}
}
public void onDeleteSelectedContactInfo(ActionEvent event) {
if (cntctInfo != null) {
cntctInfoList.remove(cntctInfo);
cntctInfo = null;
}
this.setDeleteSelectedContactInfoDisabled(true);
this.setAddContactInfoDisabled(false);
}
public void onRowEdit(RowEditEvent event) {
this.setDeleteSelectedContactInfoDisabled(true);
this.setAddContactInfoDisabled(false);
ContactInfo editedContactInfo = (ContactInfo) event.getObject();
boolean moreThanOne = patient.getContactInfoList().stream().filter(ci -> ci.equals(editedContactInfo))
.count() > 1;
if (moreThanOne) {
patient.getContactInfoList().remove(editedContactInfo);
FacesMessage msg = new FacesMessage("Row Removed", "The contact information provided is redundent!!");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
public void onRowEditInit(RowEditEvent event) {
if (event.getObject() instanceof ContactInfo) {
this.setCntctInfo((ContactInfo) event.getObject());
this.setDeleteSelectedContactInfoDisabled(false);
}
this.setAddContactInfoDisabled(true);
}
public void onRowCancel(RowEditEvent event) {
this.setDeleteSelectedContactInfoDisabled(true);
this.setAddContactInfoDisabled(false);
}
public void onDialogCancel() {
RequestContext.getCurrentInstance().closeDialog(null);
}
public void onDialogApprove() {
RequestContext.getCurrentInstance().closeDialog(patient);
}
public PatientDAO getPatientDAO() {
return patientDAO;
}
public void setPatientDAO(PatientDAO patientDAO) {
this.patientDAO = patientDAO;
}
public Ptnt getPatient() {
return patient;
}
public void setPatient(Ptnt patient) {
this.patient = patient;
}
public ContactInfo getCntctInfo() {
return cntctInfo;
}
public void setCntctInfo(ContactInfo cntctInfo) {
this.cntctInfo = cntctInfo;
}
public boolean isAddContactInfoDisabled() {
return addContactInfoDisabled;
}
public void setAddContactInfoDisabled(boolean addContactInfoDisabled) {
this.addContactInfoDisabled = addContactInfoDisabled;
}
public boolean isDeleteSelectedContactInfoDisabled() {
return deleteSelectedContactInfoDisabled;
}
public void setDeleteSelectedContactInfoDisabled(boolean deleteSelectedContactInfoDisabled) {
this.deleteSelectedContactInfoDisabled = deleteSelectedContactInfoDisabled;
}
public List<ContactInfo> getCntctInfoList() {
return cntctInfoList;
}
public void setCntctInfoList(List<ContactInfo> cntctInfoList) {
this.cntctInfoList = cntctInfoList;
}
}
and here is how I call the dialog in patienViewBean:
package me.bttb.crs.beans.patient;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.context.RequestContext;
import org.primefaces.event.SelectEvent;
import org.springframework.beans.factory.annotation.Autowired;
import me.bttb.crs.model.Ptnt;
#Named
#ManagedBean
#ViewScoped
public class PatientsViewBean {
#Autowired
private PatientDAO patientDAO;
private List<Ptnt> patients;
private List<Ptnt> filterdPatients;
public PatientsViewBean() {
}
public long getPatientsCount() {
return patientDAO.getPatientsCount();
}
public List<Ptnt> refreshAllPatients() {
this.setPatients(patientDAO.getPatients());
return this.getPatients();
}
public void addNewPatientDialog() {
Map<String, Object> options = new HashMap<String, Object>();
options.put("resizable", false);
options.put("draggable", false);
options.put("modal", true);
//options.put("contentHeight", "95%");
//options.put("height", 400);
//options.put("width", 700);
options.put("closable", false);
RequestContext.getCurrentInstance().openDialog("newPatientDialog", options, null);
}
public void onDialogReturn(SelectEvent event) {
if (event.getObject() != null && event.getObject() instanceof Ptnt) {
patientDAO.addpatient((Ptnt) event.getObject());
refreshAllPatients();
FacesMessage msg = new FacesMessage("Patient Added", "Pateint information added in the database.");
FacesContext.getCurrentInstance().addMessage(null, msg);
} else {
FacesMessage msg = new FacesMessage("operation canceld", "Nothing is saved to the database.");
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
////////////////////////////////////
public PatientDAO getPatientDAO() {
return patientDAO;
}
public void setPatientDAO(PatientDAO patientDAO) {
this.patientDAO = patientDAO;
}
public List<Ptnt> getPatients() {
return patients;
}
public void setPatients(List<Ptnt> patients) {
this.patients = patients;
}
public List<Ptnt> getFilterdPatients() {
return filterdPatients;
}
public void setFilterdPatients(List<Ptnt> filterdPatients) {
this.filterdPatients = filterdPatients;
}
}
what am I doing wrong, shouldn't the newPatientView get recreated every time the dialog shows up??
please explain the life cycle of the view here.
Hi trying to call the method on button click, but it doesnt work i also tried onclick instead action it also doesnt work. i couldnt understand where is the mistake please help me
here is my managed bean
package com.primefaces.managedbean;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.ViewScoped;
import com.primefaces.domain.KenLocation;
import com.primefaces.service.ILocationService;
#ManagedBean(name = "locationbean")
#ViewScoped
public class LocationBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1101264226039168006L;
/**
*
*/
#ManagedProperty(value = "#{LocationService}")
private ILocationService locationService;
private List<KenLocation> locationList = new ArrayList<KenLocation>();
KenLocation kenLocation;
private String locationName;
private String address1;
private String address2;
private String city;
private String pincode;
private String state;
private String contactNo;
private String organisationName;
#PostConstruct
private void init() {
locationList = locationService.onLoad();
}
public void addnewlocation() {
System.out.println("I am inside newlocation");
kenLocation = new KenLocation();
kenLocation.setLocationName(locationName);
kenLocation.setAddress1(address1);
kenLocation.setAddress2(address2);
kenLocation.setCity(city);
kenLocation.setPincode(Integer.parseInt(pincode));
kenLocation.setPhone(contactNo);
System.out.println(kenLocation);
}
public String getLocationName() {
return locationName;
}
public void setLocationName(String locationName) {
this.locationName = locationName;
}
public String getAddress1() {
return address1;
}
public void setAddress1(String address1) {
this.address1 = address1;
}
public String getAddress2() {
return address2;
}
public void setAddress2(String address2) {
this.address2 = address2;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getPincode() {
return pincode;
}
public void setPincode(String pincode) {
this.pincode = pincode;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getContactNo() {
return contactNo;
}
public void setContactNo(String contactNo) {
this.contactNo = contactNo;
}
public String getOrganisationName() {
return organisationName;
}
public void setOrganisationName(String organisationName) {
this.organisationName = organisationName;
}
public ILocationService getLocationService() {
return locationService;
}
public void setLocationService(ILocationService locationservice) {
this.locationService = locationservice;
}
public List<KenLocation> getLocationList() {
return locationList;
}
public void setLocationList(List<KenLocation> a_locationList) {
locationList = a_locationList;
}
}
and JSF
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h5>Product List {9 Products can be added per mail}</h5>
<p:separator></p:separator>
<p:growl id="growlLocationtable"></p:growl>
<p:commandButton id="new_location" title="CreateLocation" type="button"
icon="ui-icon-document" onclick="PF('dlg1').show()" />
<p:commandButton id="edit_location" title="EditLocation"
icon=" ui-icon-pencil" />
<p:commandButton id="delete_location" title="DeleteLocation"
icon="ui-icon-trash" />
<h:form id="Locationdataform">
<h:panelGrid columns="2" id="Locationdatatablepanel" resizable="false"
size="600">
<p:dataTable id="Locationdatatable" var="odt"
value="#{locationbean.locationList}">
<p:column headerText="Location Name">
<h:outputText value="#{odt.locationName}" />
</p:column>
<p:column headerText="Address Line1">
<h:outputText value="#{odt.address1}" />
</p:column>
<p:column headerText="Address Line2">
<h:outputText value="#{odt.address2}" />
</p:column>
<p:column headerText="City">
<h:outputText value="#{odt.city}" />
</p:column>
<p:column headerText="Pincode">
<h:outputText value="#{odt.pincode}" />
</p:column>
<p:column headerText="State">
<h:outputText value="#{odt.state}" />
</p:column>
<p:column headerText="Contact No">
<h:outputText value="#{odt.phone}" />
</p:column>
<p:column headerText="Organisation Name">
<h:outputText value="#{odt.ken_Org_ID.name}" />
</p:column>
</p:dataTable>
</h:panelGrid>
</h:form>
<!-- dialog -->
<p:dialog header="Add Location" widgetVar="dlg1" minHeight="40"
modal="true">
<h:form id="addLocationForm">
<h:panelGrid columns="2" id="grid">
<h:outputLabel value="Location Name"></h:outputLabel>
<p:inputText id="txt_Name" value="#{locationbean.locationName}" />
<h:outputLabel value="Address1"></h:outputLabel>
<p:inputText id="txt_address1" value="#{locationbean.address1}" />
<h:outputLabel value="Address2"></h:outputLabel>
<p:inputText id="txt_address2" value="#{locationbean.address2}" />
<h:outputLabel value="City"></h:outputLabel>
<p:inputText id="txt_city" value="#{locationbean.city}" />
<h:outputLabel value="Pincode"></h:outputLabel>
<p:inputText id="txt_pincode" value="#{locationbean.pincode}" />
<h:outputLabel value="State"></h:outputLabel>
<p:inputText id="txt_state" value="#{locationbean.state}" />
<h:outputLabel value="Contactno"></h:outputLabel>
<p:inputText id="txt_contactno" value="#{locationbean.contactNo}" />
<h:outputLabel value="Organistaion name"></h:outputLabel>
<p:inputText id="txt_orgname"
value="#{locationbean.organisationName}" />
<p:commandButton id="addlocatin_btn" value="Save"
action="#{locationbean.addnewlocation}" type="submit" />
</h:panelGrid>
</h:form>
</p:dialog>
I have a problem that i can't solve. I have my xhtml page:
The problem is that i have a form where i insert the name and select the location of a travel. It renders an external panel "Volo" where the selectionMenu is updated with some values got from DB based on location selected. Next i want to get a value from Volo selection and update the another panel with ID="HE"(is the one called HotelEsc).
I'm in trouble with the selectionMenu in "Volo" because i can't get the value into it. Always gives an NullPointException error. Probably the problem is that i'm trying to understand how Update and render work and i am mistaking something about these operations. Hope on your help thank you.
Code of xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Add a Default Package</title>
</h:head>
<h:body>
<h:form id="form">
<p:panel header="DefaultPackage Form">
<h:panelGrid columns="3" id="regGrid">
<h:outputLabel for="Name">Name:</h:outputLabel>
<p:inputText id="Name"
value="#{addDefaultPackageBean.defpackDTO.name}" />
<p:message for="Name" />
<h:outputLabel for="location">Locations Available:</h:outputLabel>
<h:selectOneMenu for="location"
value="#{addDefaultPackageBean.defpackDTO.location}">
<f:ajax listener="#{addDefaultPackageBean.Search()}" render="Volo" />
<f:selectItems id="location"
value="#{addDefaultPackageBean.availableLocations}" />
</h:selectOneMenu>
</h:panelGrid>
</p:panel>
<p:panel header="Voli Disponibili per la location selezionata"
id="Volo">
<h:outputLabel for="Fly">Volo:</h:outputLabel>
<h:selectOneMenu for="Fly" value="#{addDefaultPackageBean.fly}">
<f:selectItems id="Fly" value="#{addDefaultPackageBean.elelisfly}"
var="ElementDTO" itemValue="#{ElementDTO.name}"
itemLabel="#{ElementDTO.name}" />
</h:selectOneMenu>
<p:commandButton action="#{addDefaultPackageBean.sel()}" value="HE" render=":form,:form:regularGrid,:form:Volo" update=":form:Volo" process="form:regGrid,#this"></p:commandButton>
</p:panel>
<p:panel header="HotelEsc" id="HotelEscursioni">
<h:panelGrid columns="3" id="regularGrid">
<h:outputLabel for="Hotel">Hotel:</h:outputLabel>
<h:selectOneMenu for="Hotel" value="#{addDefaultPackageBean.hotel}">
<f:selectItems id="Hotel"
value="#{addDefaultPackageBean.elelishotel}" var="ElementDTO"
itemValue="#{ElementDTO.name}" itemLabel="#{ElementDTO.name}" />
</h:selectOneMenu>
<p:message for="Hotel" />
<h:outputLabel for="Escursion">Escursioni:</h:outputLabel>
<f:facet name="header">Clicca su view per vedere i dettagli</f:facet>
<p:dataTable id="Escursion" var="esc"
value="#{addDefaultPackageBean.elelisescursion}"
rowKey="#{esc.name}"
selection="#{addDefaultPackageBean.selectedEscursions}"
selectionMode="multiple">
<p:column headerText="Nome"> #{esc.name} </p:column>
<p:column headerText="Costo"> #{esc.cost} </p:column>
<p:column headerText="Data Iniziale"> #{esc.startingDate} </p:column>
<p:column headerText="Data Fine"> #{esc.endingDate} </p:column>
<f:facet name="footer">
</f:facet>
</p:dataTable>
</h:panelGrid>
</p:panel>
</h:form>
</h:body>
</html>
Code of related bean:
package beans;
import java.awt.Event;
import java.io.Serializable;
import java.util.ArrayList;
import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.view.ViewScoped;
import elementManagement.ElementMgr;
import elementManagementDTO.ElementDTO;
import DefaultPackageManagement.DefaultPackageMgr;
import DefaultPackageManagementDTO.DefaultPackageDTO;
#ManagedBean(name="addDefaultPackageBean") //come viene richiamato
#ViewScoped
public class AddDefaultPackageBean{
/**
*
*/
#EJB
private DefaultPackageMgr defpackMgr;
private DefaultPackageDTO defpackDTO;
private ArrayList<ElementDTO> elelisfly;
private ArrayList<ElementDTO> elelishotel;
private ArrayList<ElementDTO> elelisescursion;
private ArrayList<ElementDTO> elelis;
private ElementDTO[] selectedEscursions;
private String fly;
private String hotel;
private boolean flag=true;
private boolean flagdopo=true;
private ArrayList<String> availableLocations;
private ElementDTO flyElem;
#EJB
private ElementMgr elemMgr;
public ElementDTO[] getSelectedEscursions() {
return selectedEscursions;
}
public void setSelectedEscursions(ElementDTO[] selectedEscursions) {
this.selectedEscursions = selectedEscursions;
}
public AddDefaultPackageBean() {
defpackDTO = new DefaultPackageDTO();
}
#PostConstruct
public void init()
{
this.elelisfly=new ArrayList<ElementDTO>();
this.elelishotel=new ArrayList<ElementDTO>();
this.elelisescursion=new ArrayList<ElementDTO>();
this.setElelis(elemMgr.getAllElements());
this.availableLocations=new ArrayList<String>();
this.flyElem=new ElementDTO();
for(ElementDTO e:elelis)
{
if (this.availableLocations.contains(e.getLocation())==false)
{
this.availableLocations.add(e.getLocation());
}
}
}
public String add() {
this.AssignElemFlyFromSelection();
this.AssignElemHotelFromSelection();
this.AssignElemEscursionFromSelection();
defpackMgr.save(defpackDTO);
return "/employee/index?faces-redirect=true";
}
public void sel()
{
System.out.print("ehila" );
this.setElelis(this.elemMgr.getAllElementsByLocation(this.defpackDTO.getLocation()));
for(ElementDTO e:elelis)
{
System.out.print("elemento della location Haiti "+e.getName());
}
this.AssignElemFlyFromSelection();
System.out.print(this.fly+"Il volo selezionato per la location è "+this.getFlyElem().getName() );
this.elelisescursion.clear();
this.elelishotel.clear();
for(ElementDTO e:elelis)
{
if(e.getType().equals("Hotel"))
{
System.out.print("ho un hotel tra gli elementi "+e.getName() );
if(e.getStartingDate().after(this.flyElem.getStartingDate())&&((e.getEndingDate().before(this.flyElem.getEndingDate()))))
{
System.out.print("ho un hotel tra gli elementi con le date giuste"+e.getName());
this.getElelishotel().add(e);
}
}
else
{
if(e.getType().equals("Escursion"))
{
if(e.getStartingDate().after(this.flyElem.getStartingDate())&&(e.getEndingDate().before(this.flyElem.getEndingDate())))
{
this.getElelishotel().add(e);
}
}
}
}
this.setFlag(true);
this.setFlagdopo(true);
}
public DefaultPackageDTO getDefpackDTO() {
return defpackDTO;
}
public void setDefpackDTO(DefaultPackageDTO defpackDTO) {
this.defpackDTO = defpackDTO;
}
public ArrayList<ElementDTO> getElelisfly() {
return elelisfly;
}
public void setElelisfly(ArrayList<ElementDTO> elelisfly) {
this.elelisfly = elelisfly;
}
public ArrayList<ElementDTO> getElelishotel() {
return elelishotel;
}
public void setElelishotel(ArrayList<ElementDTO> elelishotel) {
this.elelishotel = elelishotel;
}
public ArrayList<ElementDTO> getElelisescursion() {
return elelisescursion;
}
public void setElelisescursion(ArrayList<ElementDTO> elelisescursion) {
this.elelisescursion = elelisescursion;
}
public String getFly() {
return fly;
}
public void setFly(String fly) {
this.fly = fly;
}
public String getHotel() {
return hotel;
}
public void setHotel(String hotel) {
this.hotel = hotel;
}
private void AssignElemFlyFromSelection()
{
for (ElementDTO elem:this.elelisfly)
{
if(elem.getName().equals(this.fly))
{
this.flyElem=elem;
}
}
}
private void AssignElemHotelFromSelection()
{
for (ElementDTO elem:this.elelishotel)
{
if(elem.getName().equals(this.hotel))
{
this.defpackDTO.getElem().add(elem);
}
}
}
private void AssignElemEscursionFromSelection()
{
for(int i=0;i<selectedEscursions.length;i++)
{
this.defpackDTO.getElem().add(selectedEscursions[i]);
}
}
public void Search(){
String s=defpackDTO.getLocation();
System.out.print("luogo scelto "+s);
this.setElelis(this.elemMgr.getAllElementsByLocation(s));
for(ElementDTO e:elelis)
{
System.out.print("aggiungo volo "+e.getName());
if(e.getType().equals("Flight"))
{
this.getElelisfly().add(e);
System.out.print("aggiungo volo "+e.getName());
}
}
this.setFlag(true);
}
public ArrayList<ElementDTO> getElelis() {
return elelis;
}
public void setElelis(ArrayList<ElementDTO> elelis) {
this.elelis = elelis;
}
public ArrayList<String> getAvailableLocations() {
return availableLocations;
}
public void setAvailableLocations(ArrayList<String> availableLocations) {
this.availableLocations = availableLocations;
}
public Boolean getFlag() {
return flag;
}
public void setFlag(Boolean flag) {
this.flag = flag;
}
public boolean isFlagdopo() {
return flagdopo;
}
public void setFlagdopo(boolean flagdopo) {
this.flagdopo = flagdopo;
}
public ElementDTO getFlyElem() {
return flyElem;
}
public void setFlyElem(ElementDTO flyElem) {
this.flyElem = flyElem;
}
}
You are somehow misunderstood the use of some attributes.
I'll post my notes on your code.
The p:commandButton inside Volo section is confusing
it doesn't have a render attribute, it's the update instead, you should remove render.
The update you have is updating the current section Volo is that what you need ?
it's processing only the first section which is regGrid, which means that the values inside Volo section won't be updated to the model inside the managedBean (causing the NullPointer), is that what you want ? don't think so.
Your "HE" button should be link this (If I understood what you want correctly)
<p:commandButton action="#{addDefaultPackageBean.sel()}"
value="HE"
update="HotelEscursioni" process="#parent">
</p:commandButton>
Hope this Helps...
After lots of attempts, i understood how render/update works. I hope the solution with the xhtml here down helps other people with the same problem:
The updates have to be done on the components that you want to refresh(for example in my situation the targets of the updates given from chosen values in selections); process has to be used to specificate which components are used to implement the action.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:head>
<title>Add a Default Package</title>
</h:head>
<h:body>
<h:form id="form">
<p:outputLabel for="Name">Name:</p:outputLabel>
<p:inputText id="Name"
value="#{addDefaultPackageBean.defpackDTO.name}" />
<p:message for="Name" />
<p:outputLabel for="Location">Locations Available:</p:outputLabel>
<p:selectOneMenu id="Location"
value="#{addDefaultPackageBean.defpackDTO.location}">
<f:selectItems
value="#{addDefaultPackageBean.availableLocations}" />
</p:selectOneMenu>
<p:commandButton action="#{addDefaultPackageBean.Search()}" value="Ciao" render=":form:Volo" update=":form:Volo :form"></p:commandButton>
<p:panel header="Voli Disponibili per la location selezionata"
id="Volo" rendered="#{addDefaultPackageBean.flag}">
<h:panelGrid columns="3" id="voloGrid">
<p:outputLabel for="Volare">Volo:</p:outputLabel>
<p:selectOneMenu for="Volare" value="#{addDefaultPackageBean.fly}">
<f:selectItems id="Volare" value="#{addDefaultPackageBean.elelisfly}"
var="Ciao" itemValue="#{Ciao.name}"
itemLabel="#{Ciao.name}" />
</p:selectOneMenu>
<p:commandButton actionListener="#{addDefaultPackageBean.sel()}" value="hesef" update=":form:voloGrid :form:HotelEscursioni" process=":form:Location,:form:voloGrid,#this"/>
</h:panelGrid>
</p:panel>
<p:panel header="HotelEscurs" id="HotelEscursioni" rendered="#{addDefaultPackageBean.flagdopo}">
<p:outputLabel for="Hotel">Hotel:</p:outputLabel>
<p:selectOneMenu for="Hotel" value="#{addDefaultPackageBean.hotel}">
<f:selectItems id="Hotel"
value="#{addDefaultPackageBean.elelishotel}" var="ElementDTO"
itemValue="#{ElementDTO.name}" itemLabel="#{ElementDTO.name}" />
</p:selectOneMenu>
<p:message for="Hotel" />
<p:dataTable id="Escursion" var="esc"
value="#{addDefaultPackageBean.elelisescursion}"
rowKey="#{esc.name}"
selection="#{addDefaultPackageBean.selectedEscursions}"
selectionMode="multiple">
<p:column headerText="Nome"> #{esc.name} </p:column>
<p:column headerText="Costo"> #{esc.cost} </p:column>
<p:column headerText="Data Iniziale"> #{esc.startingDate} </p:column>
<p:column headerText="Data Fine"> #{esc.endingDate} </p:column>
</p:dataTable>
</p:panel>
</h:form>
</h:body>
</html>
I have created a complexe dataTable for my DiplomeBean and it shows Correctly
The deal is whene i select a row from the list ,nothing happend
I want whene i select a row it shows me the elements of the diplome.
My Bean
package com.beans;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import com.bo.DiplomeBo;
import com.converter.DiplomeDataModel;
import com.model.Collaborateur;
import com.model.Diplome;
public class DiplomeBean {
public Integer idDiplome;
public String ecole;
public String typeEcole;
public String typeDiplome;
public Integer promotion;
private Set<Collaborateur> collaborateurs = new HashSet<Collaborateur>(0);
public Diplome selectedDiplome;
public Diplome getSelectedDiplome() {
return selectedDiplome;
}
public void setSelectedDiplome(Diplome selectedDiplome) {
this.selectedDiplome = selectedDiplome;
}
public Integer getIdDiplome() {
return idDiplome;
}
public void setIdDiplome(Integer idDiplome) {
this.idDiplome = idDiplome;
}
private DiplomeBo diplomeBo;
public String getEcole() {
return ecole;
}
public void setEcole(String ecole) {
this.ecole = ecole;
}
public String getTypeEcole() {
return typeEcole;
}
public void setTypeEcole(String typeEcole) {
this.typeEcole = typeEcole;
}
public Integer getPromotion() {
return promotion;
}
public void setPromotion(Integer promotion) {
this.promotion = promotion;
}
public Set<Collaborateur> getCollaborateurs() {
return collaborateurs;
}
public void setCollaborateurs(Set<Collaborateur> collaborateurs) {
this.collaborateurs = collaborateurs;
}
public void setDiplomeBo(DiplomeBo diplomeBo) {
this.diplomeBo = diplomeBo;
}
public String getTypeDiplome() {
return typeDiplome;
}
public void setTypeDiplome(String typeDiplome) {
this.typeDiplome = typeDiplome;
}
public String AddDiplome(){
Diplome diplome =new Diplome();
diplome.setEcole(getEcole());
diplome.setPromotion(getPromotion());
diplome.setTypeDiplome(getTypeDiplome());
diplome.setTypeEcole(getTypeEcole());
diplomeBo.addDiplome(diplome);
clearForm();
return "Ajout Bien Fait !!";
}
public List<Diplome> getAllDiplome(){
return diplomeBo.findAllDiplome();
}
private void clearForm(){
this.setEcole("");
this.setPromotion(0);
this.setTypeEcole("Choisir type..");
this.setTypeEcole("Choisir type..");
}
}
My Page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<body>
<f:view>
<h:outputLink value="Admin/default.xhtml">Go to your app</h:outputLink>
<h:form>
<p:dataTable value="#{diplome.getAllDiplome()}" var="d" paginator="true" rows="10" rowKey="diplome.idDiplome"
selection="#{diplome.selectedDiplome}" selectionMode="single"
onRowSelectUpdate="display" onRowSelectComplete="diplomeDialog.show()">
<f:facet name="header">
Diplome Liste
</f:facet>
<p:column sortBy="#{d.idDiplome}" filterBy="#{d.idDiplome}">
<f:facet name="header">
<h:outputText value="Model" />
</f:facet>
<h:outputText value="#{d.idDiplome}" />
</p:column>
<p:column sortBy="#{d.ecole}" filterBy="#{d.ecole}">
<f:facet name="header">
<h:outputText value="Ecole" />
</f:facet>
<h:outputText value="#{d.ecole}" />
</p:column>
</p:dataTable>
<p:dialog header="Diplome Detail" widgetVar="diplomeDialog" resizable="false"
width="200" showEffect="explode" hideEffect="explode">
<h:outputText value="id:" />
<h:outputText value="#{diplome.selectedDiplome.idDiplome}" />
<h:outputText value="Ecole:" />
<h:outputText value="#{diplome.selectedDiplome.ecole}" />
</p:dialog>
</h:form>
</f:view>
</body>
</html>
Thank's :)
Perhaps try modifying it slightly to be more like the Primefaces showcase example. For example, try something like this:
...
<h:form id="form">
...
<p:dataTable value="#{diplome.getAllDiplome()}" var="d" paginator="true" rows="10"
rowKey="diplome.idDiplome" selection="#{diplome.selectedDiplome}" selectionMode="single">
<p:ajax event="rowSelect" update=":form:display" oncomplete="PF('diplomeDialog').show()" />
...
</p:dataTable>
...
<p:dialog header="Diplome Detail" widgetVar="diplomeDialog" resizable="false"
width="200" showEffect="explode" hideEffect="explode">
<h:panelGrid id="display">
...
</h:panelGrid>
</p:dialog>
</h:form>
...
I can't test this right now, but it seems like it should work since it is essentially the same as the showcase's example.
I have a table showing list from a bean. When I click one of the rows, I want to view details from another bean list what would I write to value to second detail datatable list ?
Let say I have a bean of list students datatable containing name, surname and numbers, when I click a row, on the second datatable there is a bean list of student's address, city and country
Now I can System.out.print the adress detail of student when I click to row in student table but I can't show it on datatable
I'm asking how I can take the values to a datatable, what will be the value in datatable?
Thanks for your help
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
<f:view>
<h:form id="form">
<p:dataTable id="users" var="user" value="#{userOS.osList}"
paginator="true" rows="10" rowKey="#{user.kisiid}"
selection="#{userOS.selectedOS}" selectionMode="single">
<f:facet name="header">
Kullanıcı detaylarını görmek için view butonuna tıklayınız
</f:facet>
<p:ajax event="rowSelect" listener="#{userOS.onRowSelect}" update=":form:display"
oncomplete="userDialog" />
<p:column headerText="Student No" sortBy="ogrencino"
filterBy="ogrencino" id="ogrencino">
<h:outputText value="#{user.ogrencino}" />
<f:param name="kid" value="#{userOS.osList.rowIndex}" />
</p:column>
<p:column headerText="Name" sortBy="ad" filterBy="ad" id="ad">
<h:outputText value="#{user.ad}" />
</p:column>
<p:column headerText="Surname" sortBy="soyad" filterBy="soyad"
id="soyad">
<h:outputText value="#{user.soyad}" />
</p:column>
<p:column headerText="Faculty" sortBy="altbirim.ad"
filterBy="altbirim.ad" id="altbirim">
<h:outputText value="#{user.altbirim.ad}" />
</p:column>
<p:column headerText="Department" sortBy="bolum.ad"
filterBy="bolum.ad" id="bolum">
<h:outputText value="#{user.bolum.ad}" />
</p:column>
<p:column headerText="Status" sortBy="ogrencidurum.ad"
filterBy="ogrencidurum.ad" id="ogrencidurum">
<h:outputText value="#{user.ogrencidurum.ad}" />
</p:column>
<f:facet name="footer">
</f:facet>
</p:dataTable>
<p:panel id="dialog" header="User Detail" widgetVar="userDialog">
<h:panelGrid id="panelgrid" columns="2" cellpadding="4">
<p:dataTable id="display" var="adres" value="#{userOS.adresList}">
<p:column headerText="Adres Tipi">
<h:outputText value="#{adres.AddressType}" />
</p:column>
<p:column headerText="Adres">
<h:outputText value="#{adres.Address}" />
</p:column>
<p:column headerText="İl">
<h:outputText value="#{adres.City}" />
</p:column>
<p:column headerText="Ülke">
<h:outputText value="#{adres.Country}" />
</p:column>
</p:dataTable>
</h:panelGrid>
</p:panel>
</h:form>
</f:view>
</h:body>
</html>
And KisiInfoProcess.java code :
package com.revir.process;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.primefaces.event.SelectEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.revir.managed.bean.AddressBean;
import com.revir.managed.bean.OgrenimSureciBean;
import com.revir.domain.Adres;
import com.revir.domain.AdresDAO;
import com.revir.domain.Kisi;
import com.revir.domain.KisiDAO;
import com.revir.domain.Kisiadresi;
import com.revir.domain.Ogrenimsureci;
import com.revir.domain.OgrenimsureciDAO;
import com.revir.domain.Ulke;
import com.revir.process.KisiInfoProcess;
#ManagedBean(name = "userOS")
#SessionScoped
public class KisiInfoProcess implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory
.getLogger(KisiInfoProcess.class);
private List<OgrenimSureciBean> osList;
private List<AddressBean> adresList;
private List<AddressBean> adresListesi;
public List<AddressBean> getAdresListesi() {
return adresListesi;
}
public void setAdresListesi(List<AddressBean> adresListesi) {
this.adresListesi = adresListesi;
}
private OgrenimSureciBean selectedOS;
private AddressBean selectedAdres;
public OgrenimSureciBean getSelectedOS() {
return selectedOS;
}
public void setSelectedOS(OgrenimSureciBean selectedOS) {
this.selectedOS = selectedOS;
}
public AddressBean getSelectedAdres() {
return selectedAdres;
}
public void setSelectedAdres(AddressBean selectedAdres) {
this.selectedAdres = selectedAdres;
}
public List<OgrenimSureciBean> getOsList() {
OgrenimsureciDAO ogrenimsureciDAO = new OgrenimsureciDAO();
List<OgrenimSureciBean> osList = new ArrayList<OgrenimSureciBean>();
for (Iterator i = ogrenimsureciDAO.findByMezunOgrenciler((short) 8)
.iterator(); i.hasNext();) {
Ogrenimsureci og = (Ogrenimsureci) i.next();
OgrenimSureciBean osBean = new OgrenimSureciBean();
osBean.setBolum(og.getBolum());
osBean.setAd(og.getKisiByKisiid().getAd());
osBean.setSoyad(og.getKisiByKisiid().getSoyad());
osBean.setAltbirim(og.getAltbirim());
osBean.setOgrencino(og.getOgrencino());
osBean.setKisiid(og.getKisiByKisiid().getKisiid());
osBean.setOgrencidurum(og.getOgrencidurum());
osList.add(osBean);
System.out.println("osBean : " + osBean.toString());
}
return osList;
}
public void setOsList(List<OgrenimSureciBean> osList) {
this.osList = osList;
}
public void onRowSelect(SelectEvent event) {
System.out.println("On Row Select Metodu çalıştı");
try {
getAdresList();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public List<AddressBean> getAdresList() throws Exception {
if (getSelectedOS() != null) {
log.debug("PersonalInfoProcess - getAddressInfo - Start");
List<AddressBean> adresList = new ArrayList<AddressBean>();
KisiDAO kisiDAO = new KisiDAO();
AdresDAO adresDAO = new AdresDAO();
Long kisiid = getSelectedOS().getKisiid();
System.out.println("kisiid :" + kisiid);
Kisi kisi = kisiDAO.findById(kisiid);
for (Iterator i = kisi.getKisiadresis().iterator(); i.hasNext();) {
Kisiadresi kisiAdresi = (Kisiadresi) i.next();
System.out.println("i :" + i);
Adres tmpAdres = adresDAO.findById(kisiAdresi.getId()
.getAdresid());
if (tmpAdres != null) {
AddressBean address = new AddressBean(kisiid);
if (tmpAdres.getAdresturu() == null) {
address.setAddressType(null);
} else {
address.setAddressType(tmpAdres.getAdresturu().getAd());
System.out.println("Adres Türü:" +tmpAdres.getAdresturu().getAd());
}
address.setAddress(tmpAdres.getAdres());
System.out.println("Şehir:" +tmpAdres.getAdres());
if (tmpAdres.getIl() == null) {
address.setCity(null);
} else {
address.setCity(tmpAdres.getIl().getAd());
System.out.println("Şehir:" +tmpAdres.getIl().getAd());
}
if (tmpAdres.getUlke() == null) {
address.setCountry(null);
} else {
address.setCountry(tmpAdres.getUlke().getAd());
System.out.println("Ülke:" +tmpAdres.getUlke().getAd());
}
adresList.add(address);
System.out.println("adres" + address);
System.out.println("adreslist" + adresList);
}
log.debug("PersonalInfoProcess - getAddressInfo - End / Returning");
}
}
return adresList;
}
public void setAdresList(List<AddressBean> adresList) {
this.adresList = adresList;
}
}