I am displaying error message after selecting more than one check box. As i click on edit button when i selecting more than one check box i am getting popup. Instead of popup i need to show error message.
this is my jsf 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:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form id="myForm">
<div id="page" class="box">
<div class="msg">
<h2>View Outbound Home Page</h2>
<hr />
<p:dialog header="Set Status:" widgetVar="assign" modal="true">
<h:panelGrid columns="2" style="width:400px; height:50px">
<p:outputLabel value="Status" />
<h:selectOneMenu id="status" value="#{leadEditBean.status}">
<f:selectItem itemLabel="--Select one Value--" />
<f:selectItems value="#{leadEditBean.typeOfStatus}" />
</h:selectOneMenu>
</h:panelGrid>
<h:commandButton value="Update"
actionListener="#{leadEditBean.changeStatus()}" />
</p:dialog>
<p:dialog header="Set Reminder Date and Time" widgetVar="setTime"
id="dialog1" resizable="true">
<h:panelGrid columns="2" cellpadding="10" cellspacing="10">
<h:outputText value="set remind time"></h:outputText>
<p:calendar showOn="button" pattern="yyyy-MM-dd hh:mm:ss"
value="#{leadEditBean.date}"></p:calendar>
<h:commandButton value="Set"
action="#{leadEditBean.setRemainderCall()}"></h:commandButton>
</h:panelGrid>
</p:dialog>
</div>
<p:messages for="outbondhome" style="text-align:center"
closable="true"></p:messages>
<div class="callbutton">
<h:panelGrid columns="4">
<p:commandButton id="statusbtn" value="Change Status"
class="button" onclick="PF('assign').show();" ajax="true"
update=":myForm:tbl" disabled="#{leadEditBean.disabled}" />
<p:commandButton id="settime" value="Set Remind Time"
class="button" onclick="PF('setTime').show();" ajax="true"
update=":myForm:tbl" disabled="#{leadEditBean.disabled}"></p:commandButton>
<h:commandButton value="Yesterday Calls"
action="#{leadEditBean.yesterdayCall}" class="button"
immediate="true" />
<h:commandButton value="Remainder Calls"
action="#{leadEditBean.reminderCallsByTime()}" class="button"
immediate="true" />
</h:panelGrid>
</div>
<br></br> <br></br>
<p:dataTable id="tbl" var="lead" value="#{leadEditBean.enquiryTOs}"
widgetVar="filteredlead" rowsPerPageTemplate="25,50,75,100,10000"
filteredValue="#{leadEditBean.filterednewLeadList}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rows="25" paginator="true" rowKey="#{lead.leadId}"
rowIndexVar="rowIndex" selection="#{leadEditBean.leadrTos}"
style="width:100%;">
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search " style="margin-left:840px;" />
<p:inputText id="globalFilter"
onkeyup="PF('filteredlead').filter()" style="width:150px"
placeholder="Enter Phone Number" maxlength="10" />
</p:outputPanel>
</f:facet>
<p:ajax event="rowSelectCheckbox"
listener="#{leadEditBean.onRowSelect}"
update=":myForm:settime :myForm:statusbtn " />
<p:ajax event="rowUnselectCheckbox"
listener="#{leadEditBean.onRowUnselect}"
update=":myForm:settime :myForm:statusbtn " />
<p:column headerText="" style="width:30px;" selectionMode="multiple">
</p:column>
<p:column headerText="Lead Id" style="width:120px;">
<h:outputText value="#{lead.leadId}" />
</p:column>
<p:column headerText="Lead Name">
<h:outputText value="#{lead.firstName}" />
</p:column>
<p:column headerText="Email">
<h:outputText value="#{lead.emailId}" />
</p:column>
<p:column headerText="Phone No" filterMatchMode="contains"
filterBy="#{lead.phoneNum}">
<h:outputText value="#{lead.phoneNum}" />
</p:column>
<p:column headerText="PinCode">
<h:outputText value="#{lead.area.pincode}" />
</p:column>
<p:column rendered="#{leadEditBean.hideColumn}">
<f:facet name="header">
<h:outputText value="Remainder Date" />
</f:facet>
#{lead.time}
</p:column>
<p:column headerText="Edit" style="width:40px;">
<p:commandButton icon="ui-icon ui-icon-pencil"
actionListener="#{leadEditBean.getLeadEnquiryEntityForEdit(lead)}"
oncomplete="PF('edit').show()" ajax="true"
update=":myForm:dialog2" />
</p:column>
</p:dataTable>
</div>
<p:dialog header="Update Lead" widgetVar="edit" id="dialog2"
resizable="true" modal="true">
<p:messages for="home"></p:messages>
<h:panelGrid columns="4" cellpadding="10" cellspacing="4">
<h:outputText value="LeadId" />
<h:outputText value="#{leadEditBean.leadList.leadId}" />
<h:outputText />
<h:outputText />
<h:outputText value="First Name" />
<h:inputText class="input"
value="#{leadEditBean.leadList.firstName}"></h:inputText>
<h:outputText value="Email" />
<h:inputText class="input" value="#{leadEditBean.leadList.emailId}"></h:inputText>
<h:outputText value="Mobile number" />
<h:inputText class="input" value="#{leadEditBean.leadList.phoneNum}"></h:inputText>
<h:outputText value="Pincode" />
<h:selectOneMenu class="input" value="#{leadEditBean.pincode}">
<f:selectItem itemValue="#{leadEditBean.pincode}" />
<f:selectItems value="#{applicationController.typeOfPincode}"></f:selectItems>
</h:selectOneMenu>
</h:panelGrid>
<h:panelGrid>
<p:commandButton id="enquiry" value="Send to Enquiry"
update=":myForm:tbl" onclick="PF('send').show();"
style="margin-left:250px" ajax="true"></p:commandButton>
</h:panelGrid>
<h:commandButton value="Update" ajax="true" update=":myForm:dialog" style="margin-left:265px"
actionListener="#{leadEditBean.updateLeadEnquiryEntity}" />
<h:commandButton value="Cancel" action="#{leadEditBean.cancel}" />
</p:dialog>
<div id="footer">
<p>copy right</p>
</div>
</h:form>
</h:body>
</html>
this is my bean
package com.model.acim.common.controller;
#Component
#ManagedBean
#RequestScoped
public class LeadEditBean extends BaseBean<T> {
#Autowired
#Qualifier("baseServiceImpl")
private BaseService<T> baseService;
private int leadID;
private String firstName;
private String lastName;
private String phoneNumber;
private String emailId;
private String address;
private String area;
private String city;
private String pincode;
private List<LeadEnquiryTO> enquiryTOs;
private AreaTO areaTO = new AreaTO();
private StateTO stateTO;
private CityTO cityTO;
private LeadEnquiryTO enquiryTO = new LeadEnquiryTO();
private LeadEnquiryTO leadList=new LeadEnquiryTO();
private LeadEnquiryTO LeadEnquiryTOUpdate=new LeadEnquiryTO();
private List<LeadEnquiryTO> newLeadList;
private List<LeadEnquiryTO> filterednewLeadList;
private List<LeadEnquiryTO> leadrTos;
List<LeadEnquiryTO> allLeads;
private Timestamp setTime;
private String branch;
private Date date;
private String status;
private List<LeadEnquiryTO> leadEnquiryToListAd = null;
HttpSession session = null;
int noOfSelctions=0;
private Boolean disabled = true;
private Boolean hideColumn = false;
private List<LeadEnquiryTO> leadEnquiryToList = null;
int emp_id;
int selectionForEdit=0;
public int getNoOfSelctions() {
return noOfSelctions;
}
public void setNoOfSelctions(int noOfSelctions) {
this.noOfSelctions = noOfSelctions;
}
public List<LeadEnquiryTO> getLeadEnquiryToList() {
return leadEnquiryToList;
}
public void setLeadEnquiryToList(List<LeadEnquiryTO> leadEnquiryToList) {
this.leadEnquiryToList = leadEnquiryToList;
}
public void getLeadEnquiryEntityForEdit(LeadEnquiryTO to){
int size = leadrTos.size();
if(size<=1){
this.setLeadID(to.getLeadId());
leadList = baseService.getLeadEnquiryEntityForEdit(to.getLeadId());
this.setLeadID(leadList.getLeadId());
this.setFirstName(leadList.getFirstName());
this.setLastName(leadList.getLastName());
this.setPhoneNumber(leadList.getPhoneNum());
this.setEmailId(leadList.getEmailId());
this.setAddress(leadList.getAddress());
String areaName = leadList.getArea().getAreaName();
this.setArea(areaName);
this.setPincode(leadList.getArea().getPincode());
this.setCity(leadList.getArea().getCity().getCityName());
}
else
{
FacesContext.getCurrentInstance().addMessage(
"home",
new FacesMessage("Please select only One Value or One Row"));
}
}
public void onRowSelect(SelectEvent event)
{
noOfSelctions = noOfSelctions+1;
#SuppressWarnings("unused")
LeadEnquiryTO sp = (LeadEnquiryTO) event.getObject();
disabled=false;
}
public void onRowUnselect(UnselectEvent event)
{
noOfSelctions=noOfSelctions-1;
#SuppressWarnings("unused")
LeadEnquiryTO sp = (LeadEnquiryTO) event.getObject();
if (noOfSelctions<=0) {
disabled=true;
} else {
disabled=false;
}
}
public void updateLeadEnquiryEntity(){
LeadEnquiryTOUpdate.setLeadId(leadList.getLeadId());
LeadEnquiryTOUpdate.setFirstName(leadList.getFirstName());
LeadEnquiryTOUpdate.setLastName(leadList.getLastName());
LeadEnquiryTOUpdate.setPhoneNum(leadList.getPhoneNum());
LeadEnquiryTOUpdate.setAddress(leadList.getAddress());
LeadEnquiryTOUpdate.setEmailId(leadList.getEmailId());
areaTO= getAreaTOByid();
LeadEnquiryTOUpdate.setArea(areaTO);
int result = baseService.updateLeadEnquiryEntity(LeadEnquiryTOUpdate);
if (result>0) {
FacesContext.getCurrentInstance().addMessage(
"leadhome",
new FacesMessage("Updated Successfully"));
} else {
FacesContext.getCurrentInstance().addMessage(
"leadhome",
new FacesMessage("Not Updated Successfully"));
}
enquiryTOs = baseService.getLeadEnquiryByEmployeeId(emp_id);
}
public void getLeadEnquiryByEmployeeId(){
session = (HttpSession) FacesContext
.getCurrentInstance().getExternalContext()
.getSession(false);
emp_id = (Integer) session.getAttribute("employeeId");
enquiryTOs = baseService.getLeadEnquiryByEmployeeId(emp_id);
}
//setters getter
}
You should consider to change your checkboxes to radio buttons. In principle this is the right metaphor for a single selection [Checkbox or radio button].
<p:column ... selectionMode="single">
Related
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;
}
}
hello everyone I'm trying to build a webpage with two oneMenu the second one depending on the second one. My XHTML file is below as well as my bean.
when I try to create a new "structureAttache" I have the following problem
TemplateStructureAttache.xhtml #40,139 value="#{structureBean.structureAttache.intituleStructure}": Target Unreachable, 'structureAttache' returned null
and when I use the method initStruc to create a new structureAttache then I call it in the listener of my first ajax, I succeed to create a structureAttache but when I do it for the second time, it seems like the value already exit in the DB and it refuses please help me to solve this issue
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.dresen.dresen.Beans;
import com.dresen.dresen.ServiceInterface.IArrondissementService;
import com.dresen.dresen.ServiceInterface.IStructureService;
import com.dresen.dresen.entities.Arrondissement;
import com.dresen.dresen.entities.StructureAttache;
import com.dresen.dresen.entities.CategorieStructure;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import com.dresen.dresen.ServiceInterface.ICategorieStructureService;
import com.dresen.dresen.ServiceInterface.IDepartementService;
import com.dresen.dresen.entities.Departement;
import java.io.Serializable;
import javax.annotation.PostConstruct;
import javax.faces.bean.ViewScoped;
/**
*
* #author Vivien Saa
*/
#ManagedBean
#ViewScoped
public class StructureBean implements Serializable{
#ManagedProperty(value = "#{IStructureService}")
private IStructureService iStructureService;
#ManagedProperty(value = "#{IArrondissementService}")
private IArrondissementService iArrondissementService;
#ManagedProperty(value = "#{ICategorieStructureService}")
private ICategorieStructureService iCategorieStructureService;
#ManagedProperty(value ="#{IDepartementService}")
private IDepartementService iDepartementService;
private long idDepartement;
private long idArrondissement;
private long idCategorieStructure;
private StructureAttache structureAttache;
private List<Arrondissement> listArrondissement;
private List<Departement> listDepartement;
private List<CategorieStructure> listCategorieStructure;
private Arrondissement arrondissement = new Arrondissement();
private CategorieStructure CategorieStructure = new CategorieStructure();
public StructureBean() {
structureAttache = new StructureAttache();
idDepartement = 0L;
idArrondissement = 0L;
idCategorieStructure = 0L;
}
public ICategorieStructureService getiCategorieStructureService() {
return iCategorieStructureService;
}
public void setiCategorieStructureService(ICategorieStructureService iCategorieStructureService) {
this.iCategorieStructureService = iCategorieStructureService;
}
public long getIdDepartement() {
return idDepartement;
}
public void setIdDepartement(long idDepartement) {
this.idDepartement = idDepartement;
}
public IDepartementService getiDepartementService() {
return iDepartementService;
}
public void setiDepartementService(IDepartementService iDepartementService) {
this.iDepartementService = iDepartementService;
}
public List<Departement> getListDepartement() {
return iDepartementService.findAllDepartement();
}
public void setListDepartement(List<Departement> listDepartement) {
this.listDepartement = listDepartement;
}
public long getIdCategorieStructure() {
return idCategorieStructure;
}
public void setIdCategorieStructure(long idCategorieStructure) {
this.idCategorieStructure = idCategorieStructure;
}
public List<CategorieStructure> getListCategorieStructure() {
return iCategorieStructureService.findAllCategorieStructure();
}
public void setListCategorieStructure(List<CategorieStructure> listCategorieStructure) {
this.listCategorieStructure = listCategorieStructure;
}
public IStructureService getiStructureService() {
return iStructureService;
}
public void setiStructureService(IStructureService iStructureService) {
this.iStructureService = iStructureService;
}
public IArrondissementService getiArrondissementService() {
return iArrondissementService;
}
public void setiArrondissementService(IArrondissementService iArrondissementService) {
this.iArrondissementService = iArrondissementService;
}
public long getIdArrondissement() {
return idArrondissement;
}
public void setIdArrondissement(long idArrondissement) {
this.idArrondissement = idArrondissement;
}
public StructureAttache getStructureAttache() {
return structureAttache;
}
public void setStructureAttache(StructureAttache structureAttache) {
this.structureAttache = structureAttache;
}
public List<Arrondissement> getListArrondissement() {
return iArrondissementService.findArrondissementByIdDepart(idDepartement);
}
public void setListArrondissement(List<Arrondissement> listArrondissement) {
this.listArrondissement = listArrondissement;
}
public Arrondissement getArrondissement() {
return arrondissement;
}
public void setArrondissement(Arrondissement arrondissement) {
this.arrondissement = arrondissement;
}
public CategorieStructure getCategorieStructure() {
return CategorieStructure;
}
public void setCategorieStructure(CategorieStructure CategorieStructure) {
this.CategorieStructure = CategorieStructure;
}
public void initStruc() {
structureAttache = new StructureAttache();
}
public StructureAttache createStructure(){
System.out.println("vvsssssssssvsssssssssssssssssssssssvv why don't you work");
arrondissement = iArrondissementService.findArrondissementById(idArrondissement);
CategorieStructure = iCategorieStructureService.findCategorieStructureById(idCategorieStructure);
structureAttache.setCategorieStructure(CategorieStructure);
structureAttache.setArrondissement(arrondissement);
return iStructureService.createStructureAttache(structureAttache);
}
public StructureAttache findStructureById(){
return iStructureService.findStructureAttacheById(structureAttache.getId());
}
public StructureAttache updateStructure(){
arrondissement = iArrondissementService.findArrondissementById(idArrondissement);
CategorieStructure = iCategorieStructureService.findCategorieStructureById(idCategorieStructure);
structureAttache.setCategorieStructure(CategorieStructure);
structureAttache.setArrondissement(arrondissement);
return iStructureService.updateStructureAttache(structureAttache);
}
public List<StructureAttache> findAllStructure(){
return iStructureService.findAllStructureAttache();
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<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"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>Application de gestion du personnel des services déconcentrés du MINESEC EXTREME NORD</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</h:head>
<h:body>
<div id="menu">
<ui:include src="Menu.xhtml"/>
</div>
<f:view>
<p:dialog widgetVar="dlg" header=" Enregistrer une nouvel nouvelle Structure d'attache " hideEffect="explode" showEffect="explode" modal="true">
<h:form id="formAjouter" >
<p:panelGrid id="panelAjouter" columns="2">
<p:outputLabel value="Département:" />
<p:selectOneMenu id="depart" value="#{structureBean.idDepartement}" label="programme" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<p:ajax event="change" update="arrond" />
<f:selectItem itemLabel="Selectioner le département" itemValue="" noSelectionOption="true" />
<f:selectItems var="custe1" value="#{structureBean.listDepartement}" itemLabel="#{custe1.intituleDepartement}" itemValue="#{custe1.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Arrondissement:" />
<p:selectOneMenu id="arrond" value="#{structureBean.idArrondissement}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe2" value="#{structureBean.listArrondissement}" itemLabel="#{custe2.intituleArrondissement}" itemValue="#{custe2.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Categorie de Structure:" />
<p:selectOneMenu value="#{structureBean.idCategorieStructure}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe3" value="#{structureBean.listCategorieStructure}" itemLabel="#{custe3.intituleCategorieStructure}" itemValue="#{custe3.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Intitule :" for="intitule" />
<p:inputText id="intitule" value="#{structureBean.structureAttache.intituleStructure}" title="intitulé" />
<p:outputLabel value="Code/Abréviation :" for="abrev" />
<p:inputText id="abrev" value="#{structureBean.structureAttache.codeStructure}" title="abrev"/>
<p:commandButton value="Enregistrer" action="#{structureBean.createStructure()}" oncomplete="PF('dlg').hide()" update=":tableForm:table" id="bout1" ajax="false" />
</p:panelGrid>
</h:form>
</p:dialog>
<p:dialog widgetVar="dl" header=" Modifier une structure d'attache" hideEffect="fold" showEffect="explode" resizable="true">
<h:form id="formModifier" enctype="multipart/form-data">
<p:panelGrid id="panelGModifier" columns="2">
<p:outputLabel value="Département:" />
<p:selectOneMenu id="depart" value="#{structureBean.idDepartement}" label="programme" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<p:ajax event="change" update="arrond" />
<f:selectItem itemLabel="Selectioner le département" itemValue="" noSelectionOption="true" />
<f:selectItems var="custe1" value="#{structureBean.listDepartement}" itemLabel="#{custe1.intituleDepartement}" itemValue="#{custe1.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Arrondissement:" />
<p:selectOneMenu id="arrond" value="#{structureBean.idArrondissement}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe2" value="#{structureBean.listArrondissement}" itemLabel="#{custe2.intituleArrondissement}" itemValue="#{custe2.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Categorie de Structure:" />
<p:selectOneMenu value="#{structureBean.idCategorieStructure}" filter="true" filterMatchMode="startsWith" panelStyle="width:220px">
<f:selectItems var="custe3" value="#{structureBean.listCategorieStructure}" itemLabel="#{custe3.intituleCategorieStructure}" itemValue="#{custe3.id}" itemLabelEscaped="true" />
</p:selectOneMenu>
<p:outputLabel value="Intitule :" for="intitule" />
<p:inputText id="intitule" value="#{structureBean.structureAttache.intituleStructure}" title="intitulé" />
<p:outputLabel value="Code/Abréviation :" for="abrev" />
<p:inputText id="abrev" value="#{structureBean.structureAttache.codeStructure}" title="abrev"/>
<h:inputHidden id="number" value="#{structureBean.structureAttache.id}" />
<p:commandButton value="Modifier" action="#{structureBean.updateStructure()}" oncomplete="PF('dl').hide()" update=":tableForm:table" id="bout1" ajax="false" />
</p:panelGrid>
</h:form>
</p:dialog>
</f:view>
<f:view>
<h:form id='tableForm'>
<p:dataTable value="#{structureBean.findAllStructure()}" var="item" paginator="true" rows="10" paginatorTemplate=" {CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown} " id="table" rowsPerPageTemplate="5,10,15" selectionMode="single" selection="#{structureBean.structureAttache}" rowKey="#{item.id}">
<f:facet name="header">
La liste des Structures d'attache
</f:facet>
<p:column>
<f:facet name="header">
<h:outputText value="Structure"/>
</f:facet>
<h:outputText value="#{item.intituleStructure}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Code/Abréviation Structure"/>
</f:facet>
<h:outputText value="#{item.codeStructure}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Arrondissement"/>
</f:facet>
<h:outputText value="#{item.arrondissement.intituleArrondissement}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Département"/>
</f:facet>
<h:outputText value="#{item.arrondissement.departement.intituleDepartement}"/>
</p:column>
</p:dataTable>
<p:toolbar>
<f:facet name="left">
<p:commandButton type="push" onclick="PF('dlg').show();" value="Nouvelle Structure" icon="ui-icon-disk">
<p:ajax update=":formAjouter:panelAjouter" resetValues="true" />
</p:commandButton>
<p:commandButton onclick="PF('dl').show()" value="Modifier Structure" update=":formModifier:panelGModifier" icon="ui-icon-arrowrefresh-1-w"/>
<span class="ui-separator">
<span class="ui-icon ui-icon-grip-dotted-vertical" />
</span>
<p:commandButton type="push" title="Save" image="ui-icon-disk" />
<p:commandButton type="push" title="Update" icon="ui-icon-arrowrefresh-1-w"/>
<p:commandButton type="push" title="Print" image="ui-icon-print"/>
</f:facet>
</p:toolbar>
</h:form>
</f:view>
</h:body>
</html>
You can use a method to initialize your attributes as you would like to, then through an AJAX or and actionListener, you call the method that will do the job before you try to use the attribute.
I have a little project, reading/searching data from database include pictures. I have added primefaces-5.3.jar to my project , And my problem is that, When I change users photo to another it does not shows me that change Immediately, whereas I can see other changes(updates) in users record And only when I refresh the web page I am able to see another picture. Please help me with this
here is my piece of code:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
//....
<h:form id="searchform">
<!--1 Form for searching -->
<br/>
<br/>
<h:form id="searchform">
<p:outputLabel value="type the key"/>
<p:inputText value="#{personBean.searchinperson.searchAllUsingLikeOpSTRING}" required="true" requiredMessage="Please Enter the key"/>
<br/>
<p:commandButton value="Search by key" icon="ui-icon-search" action="#{personBean.displaySearchedPeopleList()}" update="searchform"/>
<p:dataTable id="searchdatatable_id" value="#{personBean.listofSeachedPeople}" var="person">
<p:column headerText="PersonId">
<p:outputLabel value="#{person.personid}"/>
</p:column>
<p:column headerText="FirstName">
<p:outputLabel value="#{person.firstname}"/>
</p:column>
<p:column headerText="LastName">
<p:outputLabel value="#{person.lastname}"/>
</p:column>
<p:column headerText="Age">
<p:outputLabel value="#{person.age}"/>
</p:column>
<p:column headerText="UserName">
<p:outputLabel value="#{person.username}"/>
</p:column>
<p:column headerText="Password" >
<p:outputLabel value="#{person.password}"/>
</p:column>
<p:column headerText="DataAddTime" >
<p:outputLabel value="#{person.dataaddtime}"/>
</p:column>
<p:column headerText="Person Photo">
<p:graphicImage value="#{personBeanApp.imageDisplay}" alt="no image" height="150" width="150">
<f:param value="#{person.personid}" name="image_id"/>
</p:graphicImage>
</p:column>
<p:column headerText="Modification">
<p:commandLink value="Modify" actionListener="#{personBean.readPersonID(person)}" oncomplete="PF('wdlgData').show();" update=":dlgDataform" />
</p:column>
<p:column headerText="Delete" style=" color: red;">
<p:commandLink value="Delete Person" actionListener="#{personBean.readPersonID(person)}" oncomplete="PF('wdlgconfirmation').show();" update=":dlgconfdelform" />
</p:column>
</p:dataTable>
</h:form>
<!-- Dialog for Modification column -->
<h:form id="dlgDataform">
<p:dialog header="Data" widgetVar="wdlgData" >
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="modifyDlgPersonid_id" value="PersonID"/>
<p:inputText id="modifyDlgPersonid_id" value="#{personBean.person.personid}" required="true" />
<p:outputLabel for="modifyDlgFirstname_id" value="FirstName"/>
<p:inputText id="modifyDlgFirstname_id" value="#{personBean.person.firstname}" required="true" />
<p:outputLabel for="modifyDlgLastname_id" value="LastName"/>
<p:inputText id="modifyDlgLastname_id" value="#{personBean.person.lastname}" required="true"/>
<p:outputLabel for="modifyDlgAge_id" value="Age"/>
<p:inputText id="modifyDlgAge_id" value="#{personBean.person.age}" required="true"/>
<p:outputLabel for="modifyDlgUsername_id" value="UserName"/>
<p:inputText id="modifyDlgUsername_id" value="#{personBean.person.username}" required="true"/>
<p:outputLabel for="modifyDlgPassword_id" value="Password"/>
<p:inputText id="modifyDlgPassword_id" value="#{personBean.person.password}" required="true"/>
</h:panelGrid>
<p:outputLabel value="add/alter Picture"/>
<p:fileUpload fileUploadListener="#{personBean.handleFileUploadForAdminModifyDlg}" mode="advanced" dragDropSupport="false"
update="adminModifyDlgUpload_msgs" sizeLimit="1000000" fileLimit="1" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" />
<p:messages id="adminModifyDlgUpload_msgs" for="adminModifyDlgPicUpload" showDetail="true" autoUpdate="true" closable="true" />
<br/>
<br/>
<p:separator />
<p:messages for="dialogModAdmin" showDetail="true" autoUpdate="true" closable="true" />
<br/>
<p:commandButton value="Modify" actionListener="#{personBean.modificatePersonData()}" update=":searchform:searchdatatable_id" />
<h:outputText value=" " />
<p:commandButton value="Cancel/Close" immediate="true" oncomplete="PF('wdlgData').hide();"/>
</p:dialog>
</h:form>
PersonBean.java:
#ManagedBean
#SessionScoped
public class PersonBean {
private List<Person> listofSeachedPeople;
public List<Person> getListofSeachedPeople() {
return listofSeachedPeople;
}
public void setListofSeachedPeople(List<Person> listofSeachedPeople) {
this.listofSeachedPeople = listofSeachedPeople;
}
public void displaySearchedPeopleList() throws Exception
{
PersonDAO dao;
try{
dao=new PersonDAO();
listofSeachedPeople=dao.searchByAll(searchinperson);
}
catch(Exception ex){throw ex;}
}
public void readPersonID(Person per) throws Exception{
PersonDAO dao;
Person temp;
try{
dao=new PersonDAO();
temp=dao.readID(per);
if(temp!=null){ persId=temp.getPersonid();persPass=temp.getPassword();this.person=temp; }
}
catch(Exception ex){throw ex;}
}
public void modificatePersonData() throws Exception{
PersonDAO dao;
try{
dao=new PersonDAO();
if("personIdFree".equals(dao.IsPersonIdFreeExceptThis(person)) && "passwordFree".equals(dao.IsPasswordFreeExceptThis(person))){dao.modificate(person);FacesContext.getCurrentInstance().addMessage("dialogModAdmin", new FacesMessage(FacesMessage.SEVERITY_INFO, "Info", "The Data has been modified"));}
else {FacesContext.getCurrentInstance().addMessage("dialogModAdmin", new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error!", "PersonID or Password is already in use"));}
this.displaySearchedPeopleList();
}
catch(Exception ex){throw ex;}
}
public void handleFileUploadForAdminModifyDlg(FileUploadEvent event) throws Exception {
try{
if(event.getFile()!=null){
uplf.setUploadedFile(event.getFile());
person.setPersonimage(IOUtils.toByteArray(uplf.getUploadedFile().getInputstream()));
FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage("adminModifyDlgPicUpload", message);}
}
catch(Exception ex){throw ex;}
}
PersonDAO.java :
public void modificate(Person per) throws Exception {
PreparedStatement pst;
Date date = new Date();
DateFormat df = new SimpleDateFormat("dd/MM/YYYY - hh:mm:ss");
try {
this.connectDB();
pst = this.getConn().prepareStatement("UPDATE person SET personid=?,firstname=?, lastname=?, age=?, username=?, password=?,dataaddtime=?,personimage=? WHERE personid=? ");
pst.setInt(1, per.getPersonid());
pst.setString(2, per.getFirstname());
pst.setString(3, per.getLastname());
pst.setInt(4, per.getAge());
pst.setString(5, per.getUsername());
pst.setString(6, per.getPassword());
pst.setString(7, df.format(date));
pst.setBytes(8,per.getPersonimage());
pst.setInt(9,PersonBean.getPersId());
pst.executeUpdate();
} catch (Exception ex) {
throw ex;
} finally {
this.toClose();
}
}
public byte[] chosenPictureInBytes(int id) throws Exception{
PreparedStatement pst;
ResultSet rs;
byte[] byteArr =new byte[1048576];
try{
this.connectDB();
pst = this.getConn().prepareStatement("SELECT personimage FROM person WHERE personid=? ");
pst.setInt(1,id);
rs = pst.executeQuery();
while(rs.next()){
// byteArr=rs.getBytes("personimage");
Blob blobPic = rs.getBlob("personimage");
byteArr=blobPic.getBytes(1,(int) blobPic.length());
}
}
catch(Exception ex){throw ex;}
finally{this.toClose();}
return byteArr;
}
PersonBeanApp.java:
#ManagedBean
#ApplicationScoped
public class PersonBeanApp {
public StreamedContent getImageDisplay() throws Exception{
PersonDAO dao;
try{
dao=new PersonDAO();
FacesContext fc=FacesContext.getCurrentInstance();
String id=fc.getExternalContext().getRequestParameterMap().get("image_id");
if(fc.getCurrentPhaseId()==PhaseId.RENDER_RESPONSE){ return new DefaultStreamedContent(); }
byte[] imageInByteArray=dao.chosenPictureInBytes(Integer.parseInt(id));
return new DefaultStreamedContent(new ByteArrayInputStream(imageInByteArray));
}
catch(Exception ex){throw ex;}
}
}
Please help me...
In my case, i had to have an img tag in modal dialog and i updated #form on user clicking the submit button on the dialog.
<p:dialog widgetVar="dlg7" id="showImage" closable="true" modal="true" header="Edit Email Image" closeOnEscape="true" draggable="true" dynamic="true" >
<p:ajax event="close" listener="#{emailConfigurationEditAction.handleCloseEditImage}" update=":emailConfiguration" />
<h:form id="editImage">
<div id="editImageDiv" align="center">
<p:messages globalOnly="false" autoUpdate="true" id="messages"
rendered="true" closable="true">
<p:effect id="idar760" type="bounce" event="load" delay="500" />
</p:messages>
<h:panelGrid columns="2" width="500px;" id="editImageGrid" columnClasses="emailTemplatePadding,row1-padding">
<p:outputLabel value="#{msg.EMAIL_INLINE_IMAGE_NAME}" for="imageNameText" id="imageNameLable" />
<h:outputText value="#{emailConfigurationEditAction.editEmbeddedImage.cidname}" converter="upperCaseConverter" id="imageNameText" style="width:300px;" maxlength="20" validatorMessage="#{msg.EMAIL_INLINE_IMAGES_CIDNAME_VLDMSG}"/>
<p:outputLabel value="#{msg.EMAIL_INLINE_IMAGE_MIMETYPE}" for="imageMimeType" id="imagemimeLabel"/>
<p:selectOneMenu id="imageMimeType" value="#{emailConfigurationEditAction.editEmbeddedImage.mimeType}" style="width:310px">
<f:selectItem itemLabel="#{msg.DROP_SELECTONE }" itemValue="#{null}" />
<f:selectItems value="#{emailConfigurationEditAction.mimeTypeOptions}"/>
</p:selectOneMenu>
<p:outputLabel value="Uploaded Image:" id="imageUploadedLabel"/>
<img width="100" height="100" border="0" id="imageUploaded" src="data:image/jpg;base64,#{imageUtility.getImageAsString(emailConfigurationEditAction.editEmbeddedImage.imageByteArray)}" />
<!-- p:graphicImage value="#{emailImages.image}" id="imageUploaded" height="100px" width="100px" >
<f:param name="cidName" value="#{emailConfigurationEditAction.editEmbeddedImage.cidname}"/>
</p:graphicImage-->
<p:outputLabel value="#{msg.EMAIL_INLINE_IMAGE_UPLOAD}" for="imageUploader" id="imageUploaderLabel"/>
<p:fileUpload id="imageUploader" mode="advanced" dragDropSupport="true" fileLimit="1" update=":editImage" style="width:310px" label="#{msg.EMAIL_INLINE_UPLAOD_IMAGE}"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/" fileUploadListener="#{emailConfigurationEditAction.imageEditListener}" fileLimitMessage="#{msg.EMAIL_INLINE_IMAGES_FILELIMIT_VLDMSG}"/>
</h:panelGrid>
<p:commandButton value="#{msg.BTN_SUBMIT}" id="submitNewImage" action="#{emailConfigurationEditAction.updateEmbeddedImage}" process=":editImage" ajax="true" update="#form"/>
<p:commandButton value="#{msg.BTN_CANCEL}" id="cancelEditImage" action="#{emailConfigurationEditAction.cancel}" immediate="true" ajax="true" process="#this"/>
</div>
</h:form>
</p:dialog>
And my datatable looked as follows:
<p:dataTable var="image" value="#{emailConfigurationEditAction.searchedImages}" id="dataTableImages" rendered="#{emailConfigurationEditAction.searchedImages!=null}"
paginator="true" rows="10" paginatorPosition="top"
rowStyleClass="#{index%2==0?'row1Data':'row2Data'}" style="width:600px;"
styleClass="ui-citi-datatable-paginator"
rowClasses="row1Data,row2Data"
paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
currentPageReportTemplate="{currentPage} #{msg.LBL_OF} {totalPages}"
emptyMessage="#{msg.INFO_SEARCH_RESULT_EMPTY}" >
<p:column id="col1" headerText="#{msg.EMAIL_INLINE_IMAGES_COLHDR_NAME}" styleClass="centered" style="width:175px;">
#{image.cidname}
</p:column>
<p:column id="col2" headerText="#{msg.EMAIL_INLINE_IMAGES_COLHDR_MIMETYPE}" styleClass="centered" style="width:120px;">
#{image.mimeType}
</p:column>
<p:column id="col3" headerText="#{msg.EMAIL_INLINE_IMAGES_COLHDR_IMAGE}" styleClass="centered" style="width:120px;">
<img width="100" height="100" border="0" id="graphicImage3"
src="data:image/jpg;base64,#{imageUtility.getImageAsString(image.imageByteArray)}" />
<!--p:graphicImage value="#{emailImages.image}" id="graphicImage3" height="100px" width="100px;">
<f:param name="cidName" value="#{image.cidname}"/>
</p:graphicImage-->
</p:column>
<p:column id="col4" headerText="" styleClass="centered" style="width:60px;">
<!-- h:commandButton image="/global/images/Delete_But_small.png" title="#{msg.LBL_EVENTEMAILMAPPING_DELETE_BUTTON}" immediate="true" value="#{msg.BTN_DELETE}" id="imgDelete"/>
<pe:tooltip for="imgDelete" value="#{msg.LBL_EVENTEMAILMAPPING_DELETE_BUTTON}" myPosition="left" atPosition="right"
showEffect="slideToggle" hideEffect="slideToggle" id="tooltip_delimg"/-->
<h:commandButton image="/global/images/Edit_But_small.png" title="#{msg.LBL_EVENTEMAILMAPPING_EDIT_BUTTON}" value="#{msg.BTN_EDIT}" id="imgEdit" action="#{emailConfigurationEditAction.editImage(image)}">
<p:ajax update=":editImage" oncomplete="PF('dlg7').show()" process="dataTableImages"/>
</h:commandButton>
<pe:tooltip for="imgEdit" value="#{msg.LBL_EVENTEMAILMAPPING_EDIT_BUTTON}" myPosition="left" atPosition="right"
showEffect="slideToggle" hideEffect="slideToggle" id="tooltip_edim"/>
</p:column>
</p:dataTable>
When i used grpahicImage instead, i understood that it will not work due to the way it is designed
My problem is simple and difficult at the same time.
I want to display some information in my p:dialog inside it. So I use my panel grid to do it. But it doesn't display the information and I don't know why. So here is the code of my page and my bean ;)
(I am using PrimeFaces 4.0, Mojara 2.1.6)
MessageBean
package ma.corporate.bean;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import ma.corporate.facade.MessageFacade;
import ma.corporate.model.Message;
#ManagedBean(name = "messageBean")
#SessionScoped
public class MessageBean implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private MessageFacade messageFacade;
private List<Message> messages;
private Message message;
private static int cpt=0;
//private Message message2;
public MessageBean() {
// messageFacade = new MessageFacade();
// messages = messageFacade.Lister();
/*
* if(messages==null) System.out.println("null"); else
* System.out.println(messages.get(0).getTextMessage());
*/
//message2=new Message();
message = new Message();
cpt++;
}
public List<Message> getMessages() {
// messages = messageFacade.Lister();
messageFacade = new MessageFacade();
messages = messageFacade.Lister();
return messages;
}
public void setMessages(List<Message> messages) {
this.messages = messages;
}
public Message getMessage() {
return message;
}
public void setMessage(Message message) {
this.message = message;
}
public void save() {
messageFacade.enregistrer(message);
}
public void Supprimer(Message message) {
messageFacade.supprimer(message);
messages = messageFacade.Lister();
}
public void init(Message message) {
//this.message.setEmail("aaaaaaaaaaaaaa");
//this.message.setNomComplet("bbbbbbbbbbbbbbbb");
//this.message.setTelephone("343232");
this.message = message;
System.out.println(this.message.getNomComplet());
System.out.println(cpt);
}
}
I wasn't able to make the code of my html page because of an error when I want to publish it.
<!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://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">
<h:head></h:head>
<h:body>
<h:form id="form1">
<p:growl id="messages" showDetail="true" />
<p:dataTable var="message" value="#{messageBean.messages}" id="table">
<p:column headerText="Nom Complet" style="width:200px">
<h:outputText value="#{message.nomComplet}" />
</p:column>
<p:column headerText="Telephone" style="width:200px">
<h:outputText value="#{message.telephone}" />
</p:column>
<p:column headerText="Email" style="width:200px">
<h:outputText value="#{message.email}" />
</p:column>
<p:column headerText="Objet" style="width:200px">
<h:outputText value="#{message.objet}" />
</p:column>
<p:column headerText="Options" style="width:200px">
<p:commandLink onclick="PF('dlg3').show();" process="#this"
actionListener="#{messageBean.init(message)}">
<h:graphicImage value="/Administration/img/afficher2.jpg"
style="width:60px;height:60px;" />
</p:commandLink>
<p:commandLink>
<h:graphicImage value="/Administration/img/reply.png"
style="width:60px;height:60px;" />
</p:commandLink>
<p:commandLink actionListener="#{messageBean.Supprimer(message)}"
ajax="true" update=":form1:table" process=":form1:table">
<p:graphicImage value="/Administration/img/spprimer.png"
style="width:60px;height:60px;" />
<p:confirm header="Confirmation" message="êtes vous sur?"
icon="ui-icon-alert" />
</p:commandLink>
<p:confirmDialog global="true" showEffect="fade"
hideEffect="explode">
<p:commandButton value="Yes" type="button"
styleClass="ui-confirmdialog-yes" icon="ui-icon-check"
update="table" />
<p:commandButton value="No" type="button"
styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
</p:confirmDialog>
</p:column>
</p:dataTable>
<!-- the problem is the dialog below -->
<p:dialog header="Message" widgetVar="dlg3" showEffect="explode"
hideEffect="bounce" resizable="true" >
<h:form>
<p:panelGrid columns="2">
<h:outputLabel value="Nom Complet: " />
<h:inputTextarea id="firstname" value="#{messageBean.message.nomComplet}" />
<h:outputLabel value="Telephone :" />
<h:outputLabel id="Telephone"
value="#{messageBean.message.telephone}" />
<h:outputLabel value="Email :" />
<p:outputLabel id="Email" value="#{messageBean.message.email}" />
<h:outputLabel value="Objet :" />
<h:outputLabel id="Objet" value="#{messageBean.message.objet}" />
<h:outputLabel value="TextMessage :" />
<h:outputLabel id="TextMessage"
value="#{messageBean.message.textMessage}" />
</p:panelGrid>
</h:form>
</p:dialog>
</h:form>
<ui:remove>
<!--<p:dialog widgetVar="dlg2" global="true" showEffect="fade"
hideEffect="explode">
<h:panelGrid columns="1">
<h:outputText value="êtes vous sur?" />
<p:separator />
<h:panelGrid columns="2">
<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" />
</h:panelGrid>
</h:panelGrid>
</p:dialog> -->
</ui:remove>
Look like an update issue. The bean get the value from xhtml page ? If he get it try to replace this two line:
<p:commandLink onclick="PF('dlg3').show();" process="#this" actionListener="#{messageBean.init(message)}">
<p:dialog header="Message" widgetVar="dlg3" showEffect="explode" hideEffect="bounce" resizable="true">
by :
<p:commandLink onclick="PF('dlg3').show();" update=":form1:dlg3" process="#this" actionListener="#{messageBean.init(message)}">
<p:dialog header="Message" id="dlg3" widgetVar="dlg3" showEffect="explode" hideEffect="bounce" resizable="true">
I have trouble displaying my property details on the dialog, after generating the table. Results are shown, but the selected row is not shown on dialog. I have taken over the example from primefaces show case.
<!DOCTYPE html>
<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"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>TODO supply a title</title>
<h:outputStylesheet library="css" name="styles.css" />
</h:head>
<h:body>
Dear customer!
<li>#{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}
</li>
<li>#{userDataManager.displayPaxChoice(userDataManager.pax)}
</li>
<li>You have chosen to check in : #{userDataManager.displayCheckinDate(userDataManager.checkinDate)}
</li>
<li>You have chosen to check out : #{userDataManager.displayCheckoutDate(userDataManager.checkoutDate)}
</li>
<li>Total Days of Stay : #{userDataManager.countNightsBetween(userDataManager.checkinDate,userDataManager.checkoutDate)}
</li>
<li>Total Nights of Stay : #{userDataManager.nights}
</li>
<br>
</br>
<h:form id="form">
<p:dataTable id="hotels" var="room" value="#{propertyDataTable.searchByHotelType
(userDataManager.hotelChoice, userDataManager.pax)}"
rowKey="#{room.propertyID}"
selection="#{propertyDataTable.selectedProperty}"
selectionMode="single"
resizableColumns="true">
<f:facet name="header">
#{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}<br></br>
Please select only one choice
</f:facet>
<p:column headerText="Property ID" >
#{room.propertyID}
</p:column>
<p:column headerText="Accommodation" >
#{room.accommodation}
</p:column>
<p:column headerText="Pax" >
#{room.pax}
</p:column>
<p:column headerText="Stars" >
#{room.stars}
</p:column>
<p:column headerText="Type" >
#{room.type}
</p:column>
<f:facet name="footer">
In total there are #{propertyDataTable.listSize(propertyDataTable.
searchByHotelType(userDataManager.hotelChoice,
userDataManager.pax))} hotels.
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":form:display" oncomplete="hotelDialog.show()">
</p:commandButton>
</f:facet>
</p:dataTable>
<p:dialog id="dialog" header="Hotel Detail" widgetVar="hotelDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<!--<p:graphicImage value="/resources/images/#{propertyDataTable.selectedProperty.type}.jpg"/>-->
<p:graphicImage value="/resources/images/Grand.jpg"/>
</f:facet>
<h:outputText value="Accommodation:" />
<h:outputText value="#{propertyDataTable.selectedProperty.accommodation }" />
<h:outputText value="Feature:" />
<h:outputText value="#{propertyDataTable.selectedProperty.feature}" />
<h:outputText value="Stars:" />
<h:outputText value="#{propertyDataTable.selectedProperty.stars}" />
</h:panelGrid>
</p:dialog>
</h:form>
<br></br>
<br></br>
<h:commandButton value="Book"
action="#{navigationController.showPage()}" >
<f:param name="page" value="book" />
</h:commandButton>
<br></br>
<h:commandButton value="HOME"
action="#{navigationController.showPage()}" >
<f:param name="page" value="home" />
</h:commandButton>
</h:body>
</html>
package dataTable;
import irms.entity.accommodation.Property;
import irms.entity.accommodation.Room;
import irms.session.accommodation.PropertySession;
import irms.session.accommodation.ReservationSession;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
/**
*
* #author Lawrence
*/
#ManagedBean(name = "propertyDataTable")
#ViewScoped
public class PropertyDataTable implements Serializable{
#EJB
private ReservationSession reservationSession;
#EJB
private PropertySession propertySession;
private List<Property> propertyList;
private int choice;
private Property selectedProperty;
private List<Room> list = new ArrayList();
public PropertyDataTable() {
}
public List<Property> getAllRooms() {
return reservationSession.getAllRooms();
}
public List<Property> searchByHotelType(String hotelType, Integer pax) {
this.propertyList = propertySession.searchByHotelType(hotelType, pax);
return propertyList;
}
public int listSize(List<Property> list){
return list.size();
}
public Room getRoom(String propertyID, Integer roomID) {
return propertySession.findRoom(propertyID, roomID);
}
public List<Room> getRoomList(String propertyID){
return propertySession.getRoomList(propertyID);
}
public ReservationSession getReservationSession() {
return reservationSession;
}
public void setReservationSession(ReservationSession reservationSession) {
this.reservationSession = reservationSession;
}
public PropertySession getPropertySession() {
return propertySession;
}
public void setPropertySession(PropertySession propertySession) {
this.propertySession = propertySession;
}
public List<Property> getPropertyList() {
return propertyList;
}
public void setPropertyList(List<Property> propertyList) {
this.propertyList = propertyList;
}
public int getChoice() {
return choice;
}
public void setChoice(int choice) {
this.choice = choice;
}
public Property getSelectedProperty() {
return selectedProperty;
}
public void setSelectedProperty(Property selectedProperty) {
this.selectedProperty = selectedProperty;
}
public List<Room> getList() {
return list;
}
public void setList(List<Room> list) {
this.list = list;
}
}
You Must add ActionListener in your viewButton commandButton
change your xhtml page like this:
<!DOCTYPE html>
<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"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title>TODO supply a title</title>
<h:outputStylesheet library="css" name="styles.css" />
</h:head>
<h:body>
Dear customer!
<li>#{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}
</li>
<li>#{userDataManager.displayPaxChoice(userDataManager.pax)}
</li>
<li>You have chosen to check in : #{userDataManager.displayCheckinDate(userDataManager.checkinDate)}
</li>
<li>You have chosen to check out : #{userDataManager.displayCheckoutDate(userDataManager.checkoutDate)}
</li>
<li>Total Days of Stay : #{userDataManager.countNightsBetween(userDataManager.checkinDate,userDataManager.checkoutDate)}
</li>
<li>Total Nights of Stay : #{userDataManager.nights}
</li>
<br>
</br>
<h:form id="form">
<p:dataTable id="hotels" var="room" value="#{propertyDataTable.searchByHotelType
(userDataManager.hotelChoice, userDataManager.pax)}"
rowKey="#{room.propertyID}"
resizableColumns="true">
<f:facet name="header">
#{userDataManager.displayHotelTypeChoice(userDataManager.hotelChoice)}<br></br>
Please select only one choice
</f:facet>
<p:column headerText="Property ID" >
#{room.propertyID}
</p:column>
<p:column headerText="Accommodation" >
#{room.accommodation}
</p:column>
<p:column headerText="Pax" >
#{room.pax}
</p:column>
<p:column headerText="Stars" >
#{room.stars}
</p:column>
<p:column headerText="Type" >
#{room.type}
</p:column>
<f:facet name="footer">
In total there are #{propertyDataTable.listSize(propertyDataTable.
searchByHotelType(userDataManager.hotelChoice,
userDataManager.pax))} hotels.
<p:commandButton id="viewButton" value="View" icon="ui-icon-search"
update=":form:display" oncomplete="hotelDialog.show()">
<f:setPropertyActionListener value="#{room}" target="#{propertyDataTable.selectedProperty}" />
</p:commandButton>
</f:facet>
</p:dataTable>
<p:dialog id="dialog" header="Hotel Detail" widgetVar="hotelDialog" resizable="false"
width="200" showEffect="clip" hideEffect="fold">
<h:panelGrid id="display" columns="2" cellpadding="4">
<f:facet name="header">
<!--<p:graphicImage value="/resources/images/#{propertyDataTable.selectedProperty.type}.jpg"/>-->
<p:graphicImage value="/resources/images/Grand.jpg"/>
</f:facet>
<h:outputText value="Accommodation:" />
<h:outputText value="#{propertyDataTable.selectedProperty.accommodation }" />
<h:outputText value="Feature:" />
<h:outputText value="#{propertyDataTable.selectedProperty.feature}" />
<h:outputText value="Stars:" />
<h:outputText value="#{propertyDataTable.selectedProperty.stars}" />
</h:panelGrid>
</p:dialog>
</h:form>
<br></br>
<br></br>
<h:commandButton value="Book"
action="#{navigationController.showPage()}" >
<f:param name="page" value="book" />
</h:commandButton>
<br></br>
<h:commandButton value="HOME"
action="#{navigationController.showPage()}" >
<f:param name="page" value="home" />
</h:commandButton>
</h:body>
</html>