Disable Datatable commandlinks when in editmode - jsf

I have I datatable. I want to disable the commandlinks when I go to rowedit mode by pressing on the edit link:
JSF:
<p:growl id="messages" showDetail="true" />
<p:dataTable value="#{employeeBean.employees}"
var="employee" id="employeeDTable"
editable="true">
<p:ajax event="rowEdit" listener="#{employeeBean.edit}" update=":employeeForm:messages" />
<p:ajax event="rowEditCancel" listener="#{employeeBean.undoEdit}" update=":employeeForm:messages" />
<p:column id="id" headerText="Id">
<h:outputText value="#{employee.id}"/>
</p:column>
<p:column id="firstname" headerText="Voornaam">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{employee.firstName}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{employee.firstName}" label="firstname"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column id="editButtonsId" headerText="">
<p:rowEditor />
</p:column>
<p:column id="cashbook" headerText="">
<div align="center">
<h:panelGroup id="cashbookPanel">
<p:commandLink title="Cashbook" update="employeeDTable" styleClass="ui-icon ui-icon-cart" /> <!-- DISABLE THIS IN EDITMODE -->
</h:panelGroup>
</div>
</p:column>
</p:dataTable>
CODE:
#Component("employeeBean")
#Scope("session")
public class EmployeeBean {
List<EmployeeModel> employees;
private EmployeeModel employeeModel;
#Autowired
private EmployeeService employeeService;
public EmployeeBean() {
if(employeeService == null){
employeeService = ServiceRepository.getInstance().getEmployeeService();
}
employeeModel = new EmployeeModel();
if(employees == null){
this.employees = this.employeeService.getEmployees();
}
}
public void edit(RowEditEvent event) {
EmployeeModel employee = ((EmployeeModel) event.getObject());
EmployeeModel updatedEmployee = this.employeeService.updateEmployee(employee);
if(updatedEmployee != null){
FacesMessage msg = new FacesMessage("Employee Edited", employee.getFirstName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}
public void undoEdit(RowEditEvent event) {
}
public EmployeeModel getEmployeeModel() {
return employeeModel;
}
public void setEmployeeModel(EmployeeModel employeeModel) {
this.employeeModel = employeeModel;
}
public List<EmployeeModel> getEmployees() {
return employees;
}
public void setEmployees(List<EmployeeModel> employees) {
this.employees = employees;
}
}

Put your link and disabled link inside a <p:cellEditor/>
<p:column id="cashbook" headerText="">
<p:cellEditor>
<f:facet name="output">
<div align="center">
<h:panelGroup id="cashbookPanel">
<p:commandLink title="Cashbook" update="employeeDTable" styleClass="ui-icon ui-icon-cart" />
</h:panelGroup>
</div>
</f:facet>
<f:facet name="input">
<div align="center">
<h:panelGroup id="cashbookPanel">
<p:commandLink disabled="true" title="Cashbook" update="employeeDTable" styleClass="ui-icon ui-icon-cart" />
</h:panelGroup>
</div>
</f:facet>
</p:cellEditor>
</p:column>

Related

Filtered jsf outputtext

I would like to know how to filter so that only the patents of vehicles that are available appear.
<p:column headerText="Patent car">
<h:outputText value="#{v.fkcar.patent}"/>
</p:column>
In the database there is a table called State with 2 income
id_state 1 ---- name_state Available and id_state 2 ---- name_state Not available
What I need is that only the patents of the vehicles that have the State in Available are shown
The State table has its respective Bean
I hope you can help me: D
Entry code Rent
<h:head>
<title>Realizar Alquiler</title>
<h:outputStylesheet library="css" name="style.css" />
</h:head>
<h:body>
<h2>Realizar Alquiler</h2>
<h:form id="fv">
<h:panelGrid columns="1" styleClass="panelGridCenter">
<h:outputText value="Precio"/>
<p:inputText value="#{alquilerBean.precio}" required="true"/>
<p:outputLabel for="datetime" value="Fecha" />
<p:calendar id="datetime" value="#{alquilerBean.fecha3}" pattern="MM/dd/yyyy HH:mm:ss" required="true"/>
Cliente
<p:selectOneMenu value="#{alquilerBean.cliente.idCliente}">
<f:selectItems value="#{clienteBean.cliente}" var="e" itemLabel="#{e.rut}" itemValue="#{e.idCliente}"/>
</p:selectOneMenu>
Patente
<p:selectOneMenu value="#{alquilerBean.vehiculo.idVehiculo}">
<f:selectItems value="#{vehiculoBean.vehiculos}" var="o" itemLabel="#{o.patente}" itemValue="#{o.idVehiculo}"/>
</p:selectOneMenu>
¿Entregado?
<p:selectOneMenu value="#{alquilerBean.entregado.idEntregado}">
<f:selectItems value="#{entregadoBean.entregado}" var="o" itemLabel="#{o.nombreEntregado}" itemValue="#{o.idEntregado}"/>
</p:selectOneMenu>
<br/>
<h:outputText value=""/>
<p:commandButton actionListener="#{alquilerBean.crear()}" value="Agregar Alquiler" update="fv"/>
</h:panelGrid>
<br/>
<p:dataTable value="#{alquilerBean.alquiler}" var="v" emptyMessage="No hay registros" >
<p:column headerText="Fecha">
<h:outputText value="#{v.fecha}"/>
</p:column>
<p:column headerText="Precio">
<h:outputText value="#{v.precio}"/>
</p:column>
<p:column headerText="Entregado">
<h:outputText value="#{v.fkEntregado.nombreEntregado}"/>
</p:column>
<p:column headerText="Rut Cliente">
<h:outputText value="#{v.fkCliente.rut}"/>
</p:column>
<p:column headerText="Patente Auto"
<h:outputText value="#{v.fkVehiculo.patente}"/>
</p:column>
</p:column>
<f:facet name="footer">
Se han alquilado #{alquilerBean.alquiler.size()} Vehiculos.
</f:facet>
</p:dataTable>
</h:form>
<br/>
<h:form>
<h:commandLink action="index">
<h:graphicImage value="resources/images/atras2.png" />
</h:commandLink>
</h:form>
</h:body> </html>
Here is the state bean code.
private int id_entregado;
private String nombre_entregado;
public EntregadoBean() {
}
public String crear(){
Entregado e = new Entregado();
e.setNombreEntregado(nombre_entregado);
entregadoFacade.create(e);
return "#";
}
public List<Entregado> getEntregado(){
return entregadoFacade.findAll();
}
public EntregadoFacadeLocal getEntregadoFacade() {
return entregadoFacade;
}
public void setEntregadoFacade(EntregadoFacadeLocal entregadoFacade) {
this.entregadoFacade = entregadoFacade;
}
public int getId_entregado() {
return id_entregado;
}
public void setId_entregado(int id_entregado) {
this.id_entregado = id_entregado;
}
public String getNombre_entregado() {
return nombre_entregado;
}
public void setNombre_entregado(String nombre_entregado) {
this.nombre_entregado = nombre_entregado;
}
}

PrimeFaces table selection, For two approve and disapprove columns

I have developed an approval screen(for user creation). There I have included two states which were approval and disapproval. Currently it takes the reading only as approval and it doesn't check disapproval. approval process is working fine for me. but I want to have disapproval part as well.
I want to improve my code to take separate readings for above mentioned two different states.
How can I get the approval and disapproval objects to two separate List??? Cant find example for two selection ways in primeface.
I want to know how do i get a column selection as approve and disapprove.
I have the following screen
I have the following datatable
<p:dataTable id="userApprovals" var="user" value="#{userApprovalBean.userApprovals}"
selection="#{userApprovalBean.selectedUser}"
widgetVar="usersTable"
rowKey="#{user.username}"
reflow="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
paginator="true" rows="10" style="margin-bottom:20px">
<f:facet name="header">
<h:commandLink style="float:right;">
<p:graphicImage name="/images/excel.png" width="24" />
<p:dataExporter type="xls" target="userApprovals" fileName="cars" />
</h:commandLink>
User Approval
<h:commandLink style="float:right;">
<p:graphicImage name="/images/pdf.png" width="24" />
<p:dataExporter type="pdf" target="userApprovals" fileName="cars" />
</h:commandLink>
<p:commandButton id="toggler" type="button" value="Columns"
style="width:100px;float:left;" icon="ui-icon-calculator" />
<p:columnToggler datasource="userApprovals" trigger="toggler" />
</f:facet>
<p:column sortBy="#{user.username}">
<f:facet name="header">
<h:outputText value="Username" />
</f:facet>
<h:outputText value="#{user.username}" />
</p:column>
<p:column sortBy="#{user.firstName}">
<f:facet name="header">
<h:outputText value="Name" />
</f:facet>
<h:outputText value="#{user.firstName}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Geneder" />
</f:facet>
<h:outputText value="#{user.gender}" />
</p:column>
<p:column style="width:160px;">
<f:facet name="header">
<h:outputText value="Address" />
</f:facet>
<h:outputText value="#{user.addressLine1}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="User Role" />
</f:facet>
<h:outputText value="#{user.userRole.userRoleDescription}" />
</p:column>
<p:column sortBy="#{user.entUser}">
<f:facet name="header">
<h:outputText value="Created User" />
</f:facet>
<h:outputText value="#{user.entUser}" />
</p:column>
<p:column styleClass="myTable">
<f:facet name="header">
<h:outputText value="Created Date" />
</f:facet>
<h:outputText value="#{user.entDate}" />
</p:column>
<p:column style="width:60px;float:center;" >
<f:facet name="header">
<h:outputText value="View" />
</f:facet>
<p:commandLink update=":form:documentPanel" oncomplete="PF('documentDialog').show()" title="View Detail" styleClass="ui-icon ui-icon-search">
<f:setPropertyActionListener value="#{user}" target="#{userApprovalBean.gridUser}" />
</p:commandLink>
</p:column>
<p:column selectionMode="multiple" style="width:55px;text-align:center">
</p:column>
<p:column selectionMode="multiple" style="width:55px;text-align:center">
</p:column>
<f:facet name="footer">
<p:commandButton process="userApprovals" update=":form:multiCarDetail"
icon="ui-icon-search" value="Selected Records" style="width:200px;height:22px"
oncomplete="PF('multiCarDialog').show()" />
</f:facet>
</p:dataTable>
I have the following Bean
public class UserApprovalBean {
private List<UserDetail> userApprovals;
private String recordStatus;
private List<UserDetail> selectedUser;
private UserDetail gridUser;;
private FacesContext context;
private UserDetail loggedUserDetail;
#PostConstruct
public void init(){
try {
context = FacesContext.getCurrentInstance();
userApprovals = UserApprovalDao.getInstance().findAllUserApproval();
//selectedUser.clear();
} catch (Exception e) {
e.printStackTrace();
}
}
public void submitData(){
context = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage();
RequestContext context1 = RequestContext.getCurrentInstance();
boolean dataFill = true;
if (selectedUser.isEmpty()) {
message = new FacesMessage(FacesMessage.SEVERITY_ERROR,
"Validation Error", "You need to select something....!");
FacesContext.getCurrentInstance().addMessage(null, message);
context1.addCallbackParam("loggedIn", dataFill);
}
else{
try{
for(UserDetail ud: selectedUser){
ud.setRecordStatus("ACTIVE");
ud.setApprovedUser(loggedUserDetail.getUsername());
ud.setApprovedDate(new Timestamp(System.currentTimeMillis()));
UserApprovalDao.getInstance().update(ud);
}
context.getApplication().getNavigationHandler()
.handleNavigation(context, null,
"/approveUserForm.xhtml?faces-redirect=true");
}
catch(Exception e){
e.printStackTrace();
}
}
}
public void refresh() {
HttpServletRequest req = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
context = FacesContext.getCurrentInstance();
if (req.getMethod().equalsIgnoreCase("GET")) {
try {
reload();
} catch (Exception e) {
e.printStackTrace();
}
}
}
private void reload() {
clear();
loadData();
}
private void clear() {
userApprovals.clear();
}
private void loadData() {
try {
userApprovals = UserApprovalDao.getInstance().findAllUserApproval();
loggedUserDetail = (UserDetail) context.getExternalContext()
.getSessionMap().get("user");
} catch (Exception e) {
e.printStackTrace();
}
}
public List<UserDetail> getUserApprovals() {
return userApprovals;
}
public void setUserApprovals(List<UserDetail> userApprovals) {
this.userApprovals = userApprovals;
}
public String getRecordStatus() {
return recordStatus;
}
public void setRecordStatus(String recordStatus) {
this.recordStatus = recordStatus;
}
public List<UserDetail> getSelectedUser() {
return selectedUser;
}
public void setSelectedUser(List<UserDetail> selectedUser) {
this.selectedUser = selectedUser;
}
public UserDetail getGridUser() {
return gridUser;
}
public void setGridUser(UserDetail gridUser) {
this.gridUser = gridUser;
}
public UserDetail getLoggedUserDetail() {
return loggedUserDetail;
}
public void setLoggedUserDetail(UserDetail loggedUserDetail) {
this.loggedUserDetail = loggedUserDetail;
}
}
You can use p:selectBooleanCheckbox in approval and disapproval column with unique value objects and can easily get the approval and disapproval selection list using If condition

primefaces datable dont refresh new data

Hi I have a datatable which publishes the information very well, however, for this particular case something happens, in one column have a Boolean value that can only be true once the entire table of the database, so if I detect someone puts another record as true then update the above false and so the cycle ends. The update is done right in the database but when I want to refresh the datatable to also show the modification of another record, and does not work ...
this is my xhtml:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="template.xhtml">
<ui:define name="content">
<h:form id="someForm">
<p:growl id="msg" showDetail="true" life="3000" autoUpdate="true"/>
<p:panelGrid style="100%">
<p:row>
<p:column style="350px">title 1</p:column>
<p:column>
<p:inputText id="cveSituacion" value="#{someBean.cve}" maxlength="20" />
</p:column>
</p:row>
<p:row>
<p:column style="350px">title 2</p:column>
<p:column>
<p:inputText id="name" value="#{someBean.name}" />
</p:column>
</p:row>
<p:row>
<p:column colspan="2">
<p:spacer></p:spacer>
</p:column>
</p:row>
<p:row>
<p:column>
<p:commandButton action="#{someBean.searchAll}" value="Search All" ajax="true" update="someForm" immediate="true"/>
</p:column>
</p:row>
<p:row>
<p:column colspan="4">
<p:spacer></p:spacer>
</p:column>
</p:row>
<p:row>
<p:column colspan="4">
<p:dataTable id="resultSearch" var="someVariable" value="#{someBean.listOfData}" editable="true">
<p:ajax event="rowEdit" listener="#{someBean.onEdit}" update=":someForm:msg :someForm:resultSearch" />
<p:ajax event="rowEditCancel" listener="#{someBean.onCancel}" update=":someForm:msg" />
<p:column headerText="Clave Sit Ticket" sortBy="#{someVariable.cve}">
<h:outputText value="#{someVariable.cve}" />
</p:column>
<p:column headerText="Name" sortBy="#{someVariable.name}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{someVariable.name}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Description" sortBy="#{someVariable.desc}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.desc}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{someVariable.desc}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Sit" sortBy="#{someVariable.situation}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.situation}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu id="cboBox" value="#{someVariable.situation}" style="width=200px">
<f:selectItems value="#{commonCboBean.listOfData}" var="cboBox" itemValue="#{cboBox.cve}" itemLabel="#{cboBox.desc}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Default" sortBy="#{someVariable.BSitDefault}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{someVariable.BSitDefault}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu id="cboVoF" value="#{someVariable.BSitDefault}" style="width=200px">
<f:selectItems value="#{fovBean.fov}" var="fov" itemValue="#{fov.bandera}" itemLabel="#{fov.descripcion}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px;" >
<p:rowEditor />
</p:column>
</p:dataTable>
</p:column>
</p:row>
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>
this is my backing bean:
#SuppressWarnings("serial")
#ManagedBean
#ViewScoped
public class SomeBean implements Serializable{
private String cve;
private String name;
private List<SomeObject> listOfData;
private SomeObject newDefault;
private SomeObject sitDefault;
private RequestContext context = null;
... some methods ....
public void onEdit(RowEditEvent event) {
/*
IF I JUST UPDATE DATA LIKE THIS: updateData(SomeObject obj) THE DATATABLE
IS UPDATED CORRECTLY, BUT IF A LEAVE THE NEXT CODE, IT DOESNT
*/
newDefault = (SomeObject)event.getObject();
if( newDefault.getFlag.equals(Constants.V) ){
List<SomeObject> list = ejb.find(newDefault.getCve);
if( list == null || list.size() <= 0 ){
updateData( newDefault );
}else{
if( list.get(0).getCve().equals( newDefault.getCve() ) ){
updateData( newDefault );
}else{
SomeObject sitDefault = list.get(0);
if( ejb.update(sitDefault) > 0 ){
updateData(newDefault);
searchAll();
}else
FacesContext.getCurrentInstance().addMessage( null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"sometitle",
"some messsage")
);
}
}
}else{
updateData( newDefault );
}
}
public void updateNewDefault(){
sitDefault.setBSitDefault("F");
if( ejb.update(sitDefault) > 0 ){
updateData(newDefault);
searchAll();
}else
FacesContext.getCurrentInstance().addMessage( null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"error",
"some error has ocurred")
);
}
private void updateData(SomeObject obj){
int result = ejb.update( obj );
if( result > 0 ){
FacesContext.getCurrentInstance().addMessage( null,
new FacesMessage(FacesMessage.SEVERITY_WARN,
"OK",
"OK"
)
);
searchAll();
}else{
FacesContext.getCurrentInstance().addMessage( null,
new FacesMessage(FacesMessage.SEVERITY_ERROR,
"ERROR",
"SOME ERROR")
);
}
}
public void searchAll(){
setListOfData( ejb.findAll() );
}
/******** getters & setters *************/
}
Please help!!! took a while stuck with it :(

primefaces datatable :rowedit not working

I'm trying to edit row data in primfaces dataTable but not working
I try the same code of primefaces showcases in below link
http://www.primefaces.org/showcase/ui/data/datatable/edit.xhtml
my jsf page
<h:form id="form">
<p:dataTable id="depTable" value="#{departmentBean.departments}"
var="dep" editable="true">
<f:facet name="header">
All departments
</f:facet>
<p:ajax event="rowEdit" listener="#{departmentBean.onRowEdit}"
update=":form:depTable" />
<p:ajax event="rowEditCancel"
listener="#{departmentBean.onRowCancel}" update=":form:depTable" />
<p:column headerText="Id">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{dep.id}" />
</f:facet>
<f:facet name="input">
<p:inputText id="modelInput" value="#{dep.id}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Name">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{dep.name}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{dep.name}" style="width:100%" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:32px">
<p:rowEditor />
</p:column>
</p:dataTable>
</h:form>
and method in bean
public void onRowEdit(RowEditEvent event) {
System.out.println(((Department) event.getObject()).getName());
FacesMessage msg = new FacesMessage("Car Edited",
((Department) event.getObject()).getName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onRowCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Edit Cancelled",
((Department) event.getObject()).getName());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
I'm using primfaces 4.0
In my case it was the problem that my backing bean was #SessionScoped (in PF example it is #ViewScoped) so I need to modify dataTabe value:
<p:dataTable id="settingsTbl" value="#{settingsBean.settingsList}" var="item" editable="true">
.....
public List<Settings> getSettingsList() {
if(settingsList==null){
settingsList = settingsFacade.findAll();
}
return settingsList;
}
I had encountered this issue and my workaround was to put the dataTable within a Form.
https://plnkr.co/edit/nYxHfY8PsGH586Om?open=lib%2Fscript.js
<div ng-controller="MainCtrl">
<div ui-grid="gridOptions" ui-grid-edit ui-grid-row-edit ui-grid-cellNav class="grid">
</div>
<button id='flushDirty' ng-click='flushDirty()'>Flush Dirty</button>
<button id='addRow' ng-click='addRow()'>Add Row</button>
<br/>
<p>Dirty rows: {{dirtyRows.length}}</p>
<div ng-repeat="row in dirtyRows">
{{row.entity.id}}, {{row.entity.gender}}
</div>
</div>

updating rowediting datatable of primefaces and saving it in the database

I'm using prime faces 3.4.2 and I'm trying to update an entity that contains a list of another object, using a row editing datatable. My problem is that when I validate the change , the simple attributes of the entity are updated in the database , but the list is not. I don't know how to save the whole object in the data base.
here you find the editing page :
`
<p:panel style="width:1000px; ;font: lighter 70.5% Arial, Helvetica, sans-serif ; " header="Informations Générales">
<p:growl id="growl" showDetail="true" sticky="true" style="font-size: small;" />
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel value="Société" />
<p:inputText id="custSoc" value="#{CustomerCtrl.selectedCust.company}"/>
<h:outputLabel value="Secteur d'activité" />
<p:inputText id="custActivite" value="#{CustomerCtrl.selectedCust.secteurActivite}" />
<h:outputLabel value="Nom du propriétaire" />
<p:inputText id="custprop" value="#{CustomerCtrl.selectedCust.proprietaire}" />
</h:panelGrid>
<p:tabView id="tabView">
<p:tab title="Coordonnées">
<p:growl id="messages" showDetail="true"/>
<p:dataTable var="cu" value="#{CustomerCtrl.selectedCust.coordonnee}" id="carList" editable="true">
<f:facet name="header">
Coordonnées
</f:facet>
<p:columnGroup type="header">
<p:row>
<p:column colspan="5" headerText="Adresses" />
<p:column colspan="5" headerText="Contacts" />
</p:row>
<p:row>
<p:column headerText="Num" style="width:2cm"/>
<p:column headerText="Rue/Avenue" style="width:3cm"/>
<p:column headerText="Code postal" style="width:2cm" />
<p:column headerText="Ville" style="width:2.5cm" />
<p:column headerText="Pays" style="width:2.5cm" />
<p:column headerText="Fixe" style="width:2cm"/>
<p:column headerText="Mobile" style="width:2cm"/>
<p:column headerText="Fax" style="width:2cm"/>
<p:column headerText="E-mail" style="width:3.7cm"/>
<p:column headerText=" " />
</p:row>
</p:columnGroup>
<p:ajax event="rowEdit" listener="#{CustomerCtrl.onEdit}" update=":form:messages" />
<p:ajax event="rowEditCancel" listener="#{CustomerCtrl.onCancel}" update=":form:messages" />
<p:column headerText="Num">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.number}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.number}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Rue/Avenue">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.street}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.street}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Code postal">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.zipcode}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.zipcode}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Ville">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.city.text}" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{cu.city.text}" style="width:100%">
<f:selectItems value="#{CustomerCtrl.cityList}" style="width:100%"
var="city"
itemLabel="#{city}"
itemValue="#{city}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Pays" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.country.text}" style="width:100%" />
</f:facet>
<f:facet name="input">
<h:selectOneMenu value="#{cu.country.text}" style="width:100%">
<f:selectItems value="#{CustomerCtrl.countryList}" style="width:100%"
var="color"
itemLabel="#{color}"
itemValue="#{color}" />
</h:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Fixe">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.phone}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.phone}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Mobile" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.mobile}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.mobile}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Fax" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.fax}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.fax}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="E-mail" >
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{cu.email}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{cu.email}" style="width:90%"/>
</f:facet>
</p:cellEditor>
</p:column>
<p:column style="width:6%">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:tab>
<p:tab title="Compte">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel value="Login" />
<p:inputText id="userLogin" value="#{CustomerCtrl.selectedCust.login}" />
<h:outputLabel value="Mot de passe" />
<p:password id="userpass" value="#{CustomerCtrl.selectedCust.password}" />
</h:panelGrid>
</p:tab>
<p:tab title="Applications">
<h:panelGrid columns="2" cellpadding="5">
</h:panelGrid>
</p:tab>
<p:tab title="Interventions">
<h:panelGrid columns="2" cellpadding="5">
</h:panelGrid>
</p:tab>
</p:tabView>
</p:panel>
<br/>
`
and here is my managedbean :`#ManagedBean(name = "CustomerCtrl")
#ViewScoped
public class CustomerController implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private int idSelected;
private Customer selectedCust ;
private Coordonnee selectedCoord = new Coordonnee();
private Coordonnee filteredCoord = new Coordonnee();
private List<Customer> filteredCusts;
private int cityId;
private int countryId;
private List<SelectItem> cityList = new ArrayList<SelectItem>();
private List<SelectItem> countryList = new ArrayList<SelectItem>();
private List<Customer> custmrs = new ArrayList<Customer>();
private List<Coordonnee> coordonnees = new ArrayList<Coordonnee>();
private Coordonnee selectedCustomerCoordonne;
#EJB
private SettingsBean settingBean;
public CustomerController() {
if (selectedCust != null) {
coordonnees = (List<Coordonnee>) settingBean.FindCoordonneeByCustomer(selectedCust.getId());
}
}
public void createCustomer() {
System.out.println("hello createCustomer");
System.out.println("selectedcust :"+selectedCust.getCompany());
System.out.println("selectedcustCoordonnee 1 :"+selectedCustomerCoordonne);
if(selectedCust==null){
System.out.println("entré");
selectedCust= new Customer();
System.out.println("nouvelle instance créé");
settingBean.createCustomer(selectedCust);
settingBean.createCoordonnee(selectedCustomerCoordonne);
System.out.println("Nouveau client " + selectedCust.getCompany() + " ajoutée");
}
else{
System.out.println("editer");
selectedCust.setCoordonnee(coordonnees);
settingBean.editCustomer(selectedCust);
System.out.println("client " + selectedCust.getCompany() + " édité");
}
}
public List<Customer> getCustmrs() {
custmrs = settingBean.findAllCustomers();
return custmrs;
}
public void setCustmrs(List<Customer> custmrs) {
this.custmrs = custmrs;
}
public void preRenderView() {
HttpSession session = (HttpSession) FacesContext.getCurrentInstance()
.getExternalContext().getSession(true);
}
public Customer getSelectedCust() {
if (selectedCust == null) {
selectedCust = (Customer) FacesContext.getCurrentInstance()
.getExternalContext().getSessionMap().get("selectedCust");
System.out.println("Par session");
if (selectedCust == null) {
selectedCust = new Customer();
selectedCust.setCoordonnee(new ArrayList<Coordonnee>());
} else
selectedCust.setCoordonnee(settingBean
.FindCoordonneeByCustomer(selectedCust.getId()));
}
return selectedCust;
}
public void setSelectedCust(Customer selectedCust) {
this.selectedCust = selectedCust;
}
public List<Customer> getFilteredCusts() {
return filteredCusts;
}
public void setFilteredCusts(List<Customer> filteredCusts) {
this.filteredCusts = filteredCusts;
}
public List<Coordonnee> getCoordonnees() {
if (selectedCust != null) {
coordonnees = (List<Coordonnee>) settingBean.FindCoordonneeByCustomer(selectedCust.getId());
}
return coordonnees;
}
public void setCoordonnees(List<Coordonnee> coordonnees) {
this.coordonnees = coordonnees;
}
public void setCustomerToEdit(Customer customerToEdit) {
}
public String removeCustomer() {
if (selectedCust != null) {
System.out.println("in delete");
String selected = selectedCust.getCompany();
System.out.println("supprimer " + selected + "");
custmrs.remove(selectedCust);
settingBean.removeCustomer(selectedCust);
System.out.println("client supprimé");
}
return "";
}
public String removeCustomercoordonnee() {
if (selectedCustomerCoordonne != null) {
System.out.println("coordonne in delete");
String selected = selectedCustomerCoordonne.getEmail();
System.out.println("supprimer " + selected + "");
settingBean.removeCustomerCoordonnee(selectedCustomerCoordonne);
System.out.println("coordonne supprimé");
}
return "";
}
public String editCustomer() {
if (selectedCust != null) {
FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().put("selectedCust", selectedCust);
System.out.println("selected "
+ FacesContext.getCurrentInstance().getExternalContext()
.getSessionMap().get("selectedCust"));
}
return "customeradd.xhtml?faces-redirect=true";
}
public int getCityId() {
return cityId;
}
public void setCityId(int cityId) {
this.cityId = cityId;
}
public int getCountryId() {
return countryId;
}
public void setCountryId(int countryId) {
this.countryId = countryId;
}
public List<SelectItem> getCityList() {
cityList = new ArrayList<SelectItem>();
List<City> Listcity = settingBean.findAllCity();
for (City c : Listcity) {
cityList.add(new SelectItem(c.getId(), c.getText()));
}
return cityList;
}
public void setCityList(List<SelectItem> cityList) {
this.cityList = cityList;
}
public List<SelectItem> getCountryList() {
cityList = new ArrayList<SelectItem>();
List<Country> Listcountry = settingBean.findAllCountry();
for (Country c : Listcountry) {
countryList.add(new SelectItem(c.getId(), c.getText()));
}
return countryList;
}
public void setCountryList(List<SelectItem> countryList) {
this.countryList = countryList;
}
public int getIdSelected() {
return idSelected;
}
public void setIdSelected(int idSelected) {
this.idSelected = idSelected;
}
public Coordonnee getSelectedCustomerCoordonne() {
return selectedCustomerCoordonne;
}
public void setSelectedCustomerCoordonne(
Coordonnee selectedCustomerCoordonne) {
this.selectedCustomerCoordonne = selectedCustomerCoordonne;
}
public Coordonnee getSelectedCoord() {
return selectedCoord;
}
public void setSelectedCoord(Coordonnee selectedCoord) {
this.selectedCoord = selectedCoord;
}
public Coordonnee getFilteredCoord() {
return filteredCoord;
}
public void setFilteredCoord(Coordonnee filteredCoord) {
this.filteredCoord = filteredCoord;
}
public void onEdit(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Cliquer sur enregistrer pour valider la modification", ((Coordonnee) event.getObject()).getCustomer().getCompany());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
public void onCancel(RowEditEvent event) {
FacesMessage msg = new FacesMessage("Modification annulée", ((Coordonnee) event.getObject()).getCustomer().getCompany());
FacesContext.getCurrentInstance().addMessage(null, msg);
}
}`
Pleaaase help me to save the both objects.

Resources