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>
Related
If I have a Liferay page which includes a Liferay Web Content Display with a form tag and then a PrimeFaces portlet with p:droppable and p:draggable, the Drag & Drop functionality does not work.
My XHTML:
<?xml version="1.0"?>
<f:view xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head />
<h:body>
<h:form id="carForm">
<p:fieldset id="availableCarsField" legend="AvailableCars">
<p:dataGrid id="availableCars" var="car" value="#{dndCarsView.cars}" columns="3">
<p:panel id="pnl" header="#{car.id}" style="text-align:center">
<h:panelGrid columns="1" style="width:100%">
<h:outputText value="#{car.id}" />
</h:panelGrid>
</p:panel>
<p:draggable for="pnl" revert="true" handle=".ui-panel-titlebar" stack=".ui-panel" />
</p:dataGrid>
</p:fieldset>
<p:fieldset id="selectedCars" legend="Selected Cars" style="margin-top:20px">
<p:outputPanel id="dropArea">
<h:outputText value="!!!Drop here!!!" rendered="#{empty dndCarsView.droppedCars}" style="font-size:24px;" />
<p:dataTable id="selectedCarsTable" var="car" value="#{dndCarsView.droppedCars}"
rendered="#{not empty dndCarsView.droppedCars}">
<p:column headerText="Id">
<h:outputText value="#{car.id}" />
</p:column>
<p:column headerText="Year">
<h:outputText value="#{car.year}" />
</p:column>
<p:column headerText="Brand">
<h:outputText value="#{car.brand}" />
</p:column>
<p:column headerText="Color">
<h:outputText value="#{car.color}" />
</p:column>
<p:column style="width:32px">
<p:commandButton update=":carForm:display" oncomplete="PF('carDialog').show()" icon="ui-icon-search">
<f:setPropertyActionListener value="#{car}" target="#{dndCarsView.selectedCar}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:outputPanel>
</p:fieldset>
<p:droppable for="selectedCars" tolerance="touch" activeStyleClass="ui-state-highlight" datasource="availableCars"
onDrop="handleDrop">
<p:ajax listener="#{dndCarsView.onCarDrop}" update="dropArea availableCars" />
</p:droppable>
<p:dialog header="Car Detail" widgetVar="carDialog" resizable="false" draggable="false" showEffect="fade"
hideEffect="fade" modal="true">
<p:outputPanel id="display">
<h:panelGrid columns="2" cellpadding="5" rendered="#{not empty dndCarsView.selectedCar}">
<f:facet name="header">
<p:graphicImage name="/demo/images/car/#{dndCarsView.selectedCar.brand}.gif" />
</f:facet>
<h:outputText value="Id" />
<h:outputText value="#{dndCarsView.selectedCar.id}" style="font-weight:bold" />
<h:outputText value="Year:" />
<h:outputText value="#{dndCarsView.selectedCar.year}" style="font-weight:bold" />
<h:outputText value="Brand" />
<h:outputText value="#{dndCarsView.selectedCar.brand}" style="font-weight:bold" />
<h:outputText value="Color:" />
<h:outputText value="#{dndCarsView.selectedCar.color}" style="font-weight:bold" />
</h:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</h:body>
</f:view>
My Bean:
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.ViewScoped;
import org.primefaces.event.DragDropEvent;
#ManagedBean(name = "dndCarsView")
#ViewScoped
public class DNDCarsView implements Serializable {
private List<Car> cars;
private List<Car> droppedCars;
private Car selectedCar;
#PostConstruct
public void init() {
cars = new ArrayList<Car>();
cars.add(new Car(1, 2001, "toyota", "black"));
cars.add(new Car(2, 2002, "honda", "yello"));
cars.add(new Car(3, 2003, "ferrari", "white"));
cars.add(new Car(4, 2004, "bmw", "green"));
cars.add(new Car(5, 2005, "suzuki", "blue"));
cars.add(new Car(6, 2006, "mazda", "brown"));
cars.add(new Car(7, 2007, "audi", "halfwhie"));
cars.add(new Car(8, 2008, "aqua", "neroon"));
droppedCars = new ArrayList<Car>();
}
public void onCarDrop(DragDropEvent ddEvent) {
Car car = ((Car) ddEvent.getData());
droppedCars.add(car);
cars.remove(car);
}
public List<Car> getCars() {
return cars;
}
public List<Car> getDroppedCars() {
return droppedCars;
}
public Car getSelectedCar() {
return selectedCar;
}
public void setSelectedCar(Car selectedCar) {
this.selectedCar = selectedCar;
}
}
You are running into PrimeFaces Issue #3265: PrimeFaces Draggable/Droppable submits Ajax requests via the wrong form. A simple workaround is to explicitly declare the form that you wish to use for Draggable/Droppable Ajax requests (using h:form's binding and p:ajax's form attributes):
<h:form id="carForm" binding="#{carForm}">
<!-- Your code here.... -->
<p:droppable for="selectedCars" tolerance="touch"
activeStyleClass="ui-state-highlight" datasource="availableCars"
onDrop="handleDrop">
<p:ajax listener="#{dndCarsView.onCarDrop}"
update="dropArea availableCars" form="#{carForm.clientId}" />
</p:droppable>
</h:form>
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">
I'm trying to open a dialog from the backing bean, but I got this: Uncaught TypeError: Can not read property 'show' of undefined
this is my code to call the dialog from the bean:
RequestContext.getCurrentInstance().update("someForm:confirmDialog");
context.execute("PF('confirmDialog').show()");
This is part if my backing bean:
#SuppressWarnings("serial")
#ManagedBean
#ViewScoped
public class SomeBean implements Serializable{
private String something = "";
private ObjectCast newDefault = null;
private List<SomeObject> list = null;
public void onEdit(RowEditEvent event) {
newDefault = (ObjectCast)event.getObject();
if( newDefault.getDefault().equals("X") ){
RequestContext context = RequestContext.getCurrentInstance();
RequestContext.getCurrentInstance().update("someForm:confirmDialog");
context.execute("PF('confirmDialog').show()");
}
public void updateNewDefault(){
... do something...
}
.... getters and setters ...
}
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="/commonTemplate.xhtml">
<ui:define name="content">
<h:form id="someForm">
<p:growl id="msg" showDetail="true" life="3000" autoUpdate="true"/>
<p:panelGrid width="100%">
<p:row>
<p:column colspan="4">
<p:dataTable id="search" var="result" value="#{someBean.list}" editable="true">
<!-- ajax -->
<p:ajax event="rowEdit" listener="#{someBean.onEdit}" update=":someForm:msg" />
<p:ajax event="rowEditCancel" listener="#{someBean.onCancel}" update=":someForm:msg" />
<p:column headerText="title" sortBy="#{result.somePropertie}">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{result.somePropertie}" />
</f:facet>
<f:facet name="input">
<p:inputText value="#{result.somePropertie}" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Edit" style="width:50px;" >
<p:rowEditor />
</p:column>
</p:dataTable>
</p:column>
</p:row>
<p:row>
<p:column colspan="4"> </p:column>
</p:row>
<p:confirmDialog id="confirmDialog"
widgetVar="confirmDialog"
message="Message ......................"
header="Warning"
severity="alert"
closeOnEscape="true"
width="600"
showEffect="slide"
hideEffect="fold"
closable="true">
<p:commandButton id="btnYes"
value="Yes"
process="#this"
oncomplete="PF('confirmDialog').hide()"
actionListener="#{someBean.updateNewDefault}"
/>
<p:commandButton id="btnNo"
value="No"
onclick="PF('confirmDialog').hide()"
type="button" />
</p:confirmDialog>
</p:panelGrid>
</h:form>
</ui:define>
</ui:composition>
I have a barChart where I use extend to modify datapoint, when I put that and the following js code, my dialog stops working ... why ??
<!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>Chart</title>
<link rel="stylesheet" type="text/css" href="#{request.contextPath}/css/default.css"/>
<script type="text/javascript">
function chartExtender() {
this.cfg.seriesDefaults = {
renderer:$.jqplot.BarRenderer,
pointLabels: { show: true }
};
this.cfg.highlighter = { show: false };
}
</script>
</h:head>
<h:body style="background-color: #E1E1E1;">
<p:panelGrid columns="1" columnClasses="left" style="width:100%">
<p:barChart id="basic" value="#{someBean.categoryModel}" legendPosition="ne"
title="some Title" min="0" max="#{someBean.max}" style="height:400px"
shadow="true" barPadding="60" animate="true" extender="chartExtender"
/>
</p:panelGrid>
</h:body>
</html>
Thanks!!
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">
When I click on the button New <p:commandButton actionListener="#{ecritureCtrl.newLine}" value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()" ajax="true"/>, a new row is added to my dataTable on only the first click and the page is refreshed. Several cliques except the first were not refreshes the dataTable. So to see my newly added rows, I use the F5 key to refresh my page. Certainly my update="dataTableSaisiePiece" not work or only works rather the first click.
Here is my page home.xhtml :
<?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:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<script type="text/javascript">
function addRowOnComplete() {
jQuery('#supercoolnewrow').trigger('click');
}
</script>
<ui:composition template="/resources/template/all.xhtml">
<ui:define name="titre">Saisie</ui:define>
<ui:define name="content">
<p:tabView id="ViewPlan">
<p:tab id="tab2" title="Saisie 1">
<h:outputScript library="js" name="frenchLocale.js" />
<h:form id="formPiece">
<p:panel id="panelSaisie" header="Saisir" style="color: brown;font-size: 15px">
<h:panelGrid columns="3" >
<p:outputLabel for="description" value="Description:" ></p:outputLabel>
<p:inputText id="description" value="#{ecritureCtrl.description}" required="true" label="Description" maxlength="100" size="75">
<f:validateLength maximum="100" />
</p:inputText>
<p:message for="description" />
<p:outputLabel for="date" value="Date:" ></p:outputLabel>
<p:calendar locale="fr" id="date" required="true" label="Date" value="#{ecritureCtrl.date}" />
<p:message for="date" />
<p:outputLabel for="code" value="Code Avant" ></p:outputLabel>
<p:inputText id="code" value="#{ecritureCtrl.code}" required="true" >
</p:inputText>
<p:message for="code" />
</h:panelGrid>
<br/>
<p:dataTable var="line" value="#{ecritureCtrl.lignes}" id="dataTableSaisiePiece" >
<p:column headerText="First Name" style="width:150px">
<p:inputText value="#{line.intituleCompte}" style="width:100%"/>
</p:column>
<p:column headerText="Last Name" style="width:150px">
<p:inputText value="#{line.code}" style="width:100%"/>
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton actionListener="#{ecritureCtrl.newLine}" value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()" ajax="true"/>
</h:form>
</p:tab>
<p:tab id="tab3" title="Saisie 2">
</p:tab>
</p:tabView>
</ui:define>
</ui:composition>
</html>
My ManagedBean:
#ManagedBean (name = "ecritureCtrl")
#SessionScoped
public class EcritureCtrl {
private List<Avant> lignes = new ArrayList<Avant>();
Avant unUser;
private String description;
private Date date;
private String code;
public EcritureCtrl() {
lignes.add(new Avant());
}
public void newLine(ActionEvent actionEvent){
lignes.add(new Avant());
}
}
Could you please help me ?
Thanks in advance.
this seems to work for me
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.event.ActionEvent;
#ManagedBean
#SessionScoped
public class EcritureCtrl implements Serializable {
private static final long serialVersionUID = 1L;
private String code;
private Date date;
private String description;
private List<Avant> lignes = new ArrayList<Avant>();
private Avant unUser;
public String getCode() {
return this.code;
}
public Date getDate() {
return this.date;
}
public String getDescription() {
return this.description;
}
public List<Avant> getLignes() {
return this.lignes;
}
public Avant getUnUser() {
return this.unUser;
}
#PostConstruct
private void init(){
this.lignes.add(new Avant());
}
public void newLine(ActionEvent actionEvent) {
this.lignes.add(new Avant());
}
public void setCode(String code) {
this.code = code;
}
public void setDate(Date date) {
this.date = date;
}
public void setDescription(String description) {
this.description = description;
}
public void setLignes(List<Avant> lignes) {
this.lignes = lignes;
}
public void setUnUser(Avant unUser) {
this.unUser = unUser;
}
}
and
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Sorry</title>
</h:head>
<h:body>
<script type="text/javascript">
function addRowOnComplete() {
alert();
}
</script>
<h:form id="formPiece">
<p:messages id="messages" showDetail="true" autoUpdate="true"
closable="true" />
<p:tabView id="ViewPlan">
<p:tab id="tab2" title="Saisie 1">
<p:panel id="panelSaisie" header="Saisir"
style="color: brown;font-size: 15px">
<h:panelGrid columns="3">
<p:outputLabel for="description" value="Description:"></p:outputLabel>
<p:inputText id="description" value="#{ecritureCtrl.description}"
required="true" label="Description" maxlength="100" size="75">
<f:validateLength maximum="100" />
</p:inputText>
<p:message for="description" />
<p:outputLabel for="date" value="Date:"></p:outputLabel>
<p:calendar locale="fr" id="date" required="true" label="Date"
value="#{ecritureCtrl.date}" />
<p:message for="date" />
<p:outputLabel for="code" value="Code Avant"></p:outputLabel>
<p:inputText id="code" value="#{ecritureCtrl.code}"
required="true">
</p:inputText>
<p:message for="code" />
</h:panelGrid>
<br />
<p:dataTable var="line" value="#{ecritureCtrl.lignes}"
id="dataTableSaisiePiece">
<p:column headerText="First Name" style="width:150px">
<p:inputText value="#{line.intituleCompte}" style="width:100%" />
</p:column>
<p:column headerText="Last Name" style="width:150px">
<p:inputText value="#{line.code}" style="width:100%" />
</p:column>
</p:dataTable>
</p:panel>
<p:commandButton actionListener="#{ecritureCtrl.newLine}"
value="New" update="dataTableSaisiePiece" oncomplete="addRowOnComplete()"
ajax="true" />
</p:tab>
<p:tab id="tab3" title="Saisie 2">
</p:tab>
</p:tabView>
</h:form>
</h:body>
</html>