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">
Related
This question already has answers here:
commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated
(12 answers)
How to use <h:form> in JSF page? Single form? Multiple forms? Nested forms?
(2 answers)
How to show details of current row from p:dataTable in a p:dialog and update after save
(1 answer)
Closed 8 months ago.
I try to create a page on which I can edit delete and create users.
I can't get the website to function correctly.
Apparently, I run into the problem that my user doesn't get set by the PropertyActionListener.
If I delete the createUserDialog it all functions perfectly. I don't get what I am missing.
Why is the second dialog interfering with the first.
Anyone an idea what is going on ?
Any help is much appreciated.
XHTML FILE:
<?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">
<ui:composition xmlns="http://www.w3c.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:ng="http://xmlns.jcp.org/jsf/passthrough"
xmlns:p="http://primefaces.org/ui" xmlns:o="http://omnifaces.org/ui"
template="/WEB-INF/templates/main2.xhtml">
<ui:define name="content">
<div class="wrapper" style="display:flex; flex-flow: row; height: 100%; justify-content: center; align-items: center;">
<p:card style="width: 80%; margin-bottom: 2em; box-shadow: 5px 10px 25px rgba(0, 0, 0, 0.45); border-radius: 10px 10px 10px 10px;">
<h:form id="userForm">
<p:dataTable id="usersTable" var="user" value="#{userListController.users}">
<p:column headerText="Username">
<h:outputText value="#{user.username}"/>
</p:column>
<p:column headerText="First Name">
<h:outputText value="#{user.firstName}"/>
</p:column>
<p:column headerText="Last Name">
<h:outputText value="#{user.lastName}"/>
</p:column>
<p:column headerText="Roles">
<h:outputText value="#{user.roles}" />
</p:column>
<p:column headerText="Enabled">
<h:selectBooleanCheckbox value="#{user.enabled}" disabled="true"/>
</p:column>
<p:column style="width:100px;text-align: center">
<p:commandButton update=":userForm:userEditDialog" oncomplete="PF('userEditDialog').show()" icon="pi pi-user-edit" title="Edit">
<f:setPropertyActionListener target="#{userDetailController.user()}" value="#{user}"/>
</p:commandButton>
<p:commandButton action="#{userDetailController.doDeleteUser}" icon="pi pi-trash" title="Delete" update=":userForm:usersTable">
<f:setPropertyActionListener value="#{user}" target="#{userDetailController.user()}" />
<p:confirm header="Confirmation" message="Are you sure that you want to delete this user? You cannot undo this operation." icon="ui-icon-alert" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Edit User" id="userEditDialog" widgetVar="userEditDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="userData" rendered="#{not empty userDetailController.user}">
<h:panelGrid columns="2">
<p:outputLabel for="username" value="Username: " />
<p:inputText id="username" value="#{userDetailController.user.username}" disabled="true"/>
<p:outputLabel for="password" value="Password: " />
<p:password id="password" value="#{userDetailController.user.password}" disabled="true"/>
</h:panelGrid>
<p:separator />
<h:panelGrid columns="2">
<p:outputLabel for="firstName" value="First Name: " />
<p:inputText id="firstName" value="#{userDetailController.user.firstName}"/>
<p:outputLabel for="firstName" value="Last Name: " />
<p:inputText id="lastName" value="#{userDetailController.user.lastName}"/>
<p:outputLabel for="email" value="E-Mail: " />
<p:inputText id="email" value="#{userDetailController.user.email}"/>
<p:outputLabel for="phone" value="Phone: " />
<p:inputMask id="phone" value="#{userDetailController.user.phone}" mask="+99? 999 9999999"/>
</h:panelGrid>
<p:separator />
<p:separator />
<h:panelGrid columns="2">
<p:outputLabel for="enabled" value="Enabled: " />
<p:selectBooleanCheckbox id="enabled" value="#{userDetailController.user.enabled}"/>
</h:panelGrid>
<p:separator />
<h:panelGrid columns="3">
<p:commandButton value="Save" action="#{userDetailController.doSaveUser}" oncomplete="PF('userEditDialog').hide()" update=":userForm:usersTable"/>
<p:commandButton value="Reload" action="#{userDetailController.doReloadUser}" update=":userForm:userData"/>
<p:commandButton value="Abort" onclick="PF('userEditDialog').hide()"/>
</h:panelGrid>
</p:outputPanel>
</p:dialog>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade" width="300">
<p:commandButton value="Yes" type="button" styleClass="ui-confirmdialog-yes" icon="pi pi-check" />
<p:commandButton value="No" type="button" styleClass="ui-confirmdialog-no" icon="pi pi-times" />
</p:confirmDialog>
<p:commandButton update=":userForm:userCreateDialog" oncomplete="PF('userCreateDialog').show()" icon="pi pi-user-edit" title="Create">
</p:commandButton>
<p:dialog header="Create New User" id="userCreateDialog" widgetVar="userCreateDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
<p:outputPanel id="newUserData">
<h:panelGrid columns="2">
<p:outputLabel for="newUsername" value="Username: " />
<p:inputText id="newUsername" value="#{userDetailController.newUser.username}" required="true"/>
<p:outputLabel for="newPassword" value="Password: " />
<p:password id="newPassword" value="#{userDetailController.newUser.password}" required="true"/>
</h:panelGrid>
<p:separator />
<h:panelGrid columns="2">
<p:outputLabel for="newFirstName" value="First Name: " />
<p:inputText id="newFirstName" value="#{userDetailController.newUser.firstName}"/>
<p:outputLabel for="newLastName" value="Last Name: " />
<p:inputText id="newLastName" value="#{userDetailController.newUser.lastName}"/>
<p:outputLabel for="NewEmail" value="Email: "/>
<p:inputText id="NewEmail" value="#{userDetailController.newUser.email}"/>
<p:outputLabel for="newPhone" value="Phone: " />
<p:inputMask id="newPhone" value="#{userDetailController.newUser.phone}" mask="+99? 999 9999999"/>
</h:panelGrid>
<p:separator />
<div class="wrapper1" style="margin-bottom: 30px;">
<h:panelGrid columns="2" cellpadding="5">
<p:outputLabel for="d" value="Working Room:"/>
<p:selectOneMenu id="d" value="#{userDetailController.newUser.workingRoom}" style="width:200px">
<f:selectItems value="#{userDetailController.allRooms}" var="aRoom" itemLabel="#{aRoom.roomName}" itemValue="#{aRoom}" />
</p:selectOneMenu>
</h:panelGrid>
</div>
<p:separator />
<h:panelGrid columns="3">
<p:commandButton type="submit" value="Save" action="#{userDetailController.doCreateNewUser()}" oncomplete="PF('userCreateDialog').hide()" update=":userForm:usersTable"/>
<p:commandButton value="Cancel" type="reset" resetValues="true" onclick="PF('userCreateDialog').hide()"/>
</h:panelGrid>
</p:outputPanel>
</p:dialog>
</h:form>
</p:card>
</div>
</ui:define>
</ui:composition>
JAVA FILE:
package at.qe.skeleton.ui.controllers;
import at.qe.skeleton.model.Room;
import at.qe.skeleton.model.User;
import at.qe.skeleton.model.UserRole;
import at.qe.skeleton.services.RoomService;
import at.qe.skeleton.services.UserService;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
/**
* Controller for the user detail view.
*
* This class is part of the skeleton project provided for students of the
* courses "Software Architecture" and "Software Engineering" offered by the
* University of Innsbruck.
*/
#Component
#Scope("view")
public class UserDetailController implements Serializable {
#Autowired
transient private UserService userService;
#Autowired
private RoomService roomService;
/**
* Attribute to cache the currently displayed user
*/
transient private User user;
transient private User newUser = new User();
transient private List<Room> allRooms;
transient private UserRole role;
#PostConstruct
public void setup() {
allRooms = new ArrayList<>( roomService.getAllRooms());
}
/**
* Sets the currently displayed user and reloads it form db. This user is
* targeted by any further calls of
* {#link #doReloadUser()}, {#link #doSaveUser()} and
* {#link #doDeleteUser()}.
*
* #param user
*/
public void setUser(User user) {
System.out.println("trying to set User" );
this.user = user;
}
/**
* Returns the currently displayed user.
*
* #return
*/
public User getUser() {
return user;
}
public User getNewUser() {
return newUser;
}
public void setNewUser(User newUser) {
this.newUser = newUser;
}
public List<Room> getAllRooms() {
return allRooms;
}
public UserRole getRole() {
return role;
}
public void setRole(UserRole role) {
this.role = role;
}
/**
* Action to force a reload of the currently displayed user.
*/
public void doReloadUser() {
user = userService.loadUser(user.getUsername());
}
public void doCreateNewUser(){
System.out.println("create the hell out");
newUser.setEnabled(true);
newUser.setRoles(new HashSet<UserRole>(){{
add(UserRole.EMPLOYEE);}});
this.userService.saveUser(newUser);
newUser = new User();
}
/**
* Action to save the currently displayed user.
*/
public void doSaveUser() {
System.out.println("Successfully saved user: " +user.getUsername() );
user = this.userService.saveUser(user);
}
/**
* Action to delete the currently displayed user.
*/
public void doDeleteUser() {
this.userService.deleteUser(user);
user = null;
}
}
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 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
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>
i have an init() function that returns a list of Domaines needed to populate a datatable, each row of this datatable have two commandlinks one for edit and another for delete, so when i press the edit command link a dialog window apear showing the Domaine information whith the possibility of editing (there is another dialog for adding new domaines), so the problem is when i press edit the init function is called 8 times then the attributes of the adding dialog are setted (even if there is no relation between the thee edit command link and the adding dialog window) after the init function is called again 4 times. i don't understand wh.
here my page code:
<?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:p="http://primefaces.prime.com.tr/ui"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core">
<h:head>
<title>Facelet Title</title>
</h:head>
<h:body>
<ui:composition template="gpsiTemplate.xhtml">
<ui:define name="left-menu">
<ui:include src="admin-menuGauche.xhtml" />
</ui:define>
<ui:define name="top">
<ui:include src="menu-top.xhtml" />
</ui:define>
<ui:define name="content-top">
<center>
<f:view>
<h:form id="topacteurs">
<h:panelGrid columns="14" styleClass="adminTopTable" >
<h5 class="calendar">Direction :</h5>
<p:selectOneMenu id="typeacteurs" value="#{domaine.choixDirection}" style="width: 180px">
<f:selectItem itemLabel="Direction..." itemValue="" />
<f:selectItems value="#{direction.initcomb()}" var="ta" itemValue="#{ta.codeDirection}" itemLabel="#{ta.libelleDirection}" />
<p:ajax update=":mainform:domainlist" process="topacteurs" event="change" />
</p:selectOneMenu>
<p:spacer width="20" height="0" />
<p:commandButton title="Ajouter un domaine" image="ui-icon ui-icon-disk" value="Ajouter un domaine" oncomplete="ajoutDomaine.show()"/>
</h:panelGrid>
</h:form>
</f:view>
</center>
</ui:define>
<ui:define name="content-content">
<h:form id="modifform">
<p:dialog header="Modifier un domaine" widgetVar="editDomaine" modal="true" width="400" height="200" showEffect="clip" hideEffect="clip">
<p:outputPanel id="editDomaineDetails" style="text-align:center;" layout="block">
<center>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel value="Intitulé :"/>
<p:inputText value="#{domaine.currentDomaine.libelleDomaine}" style="width: 180px"/>
<h:outputLabel value="Respensable :"/>
<p:inputText value="#{domaine.currentDomaine.nomDirecteur}" style="width: 180px"/>
<h:outputLabel value="Direction :"/>
<p:selectOneMenu id="editchoidirection" value="#{domaine.codeDirection}" style="width: 180px">
<f:selectItem itemLabel="Direction..." itemValue="" />
<f:selectItems value="#{direction.initcomb()}" var="ta" itemValue="#{ta.codeDirection}" itemLabel="#{ta.libelleDirection}" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="2" cellpadding="5">
<p:commandButton value="Modifier" update="messages editDomaineDetails :mainform:domainlist" actionListener="#{domaine.update()}" oncomplete="editDomaine.hide()"/>
<p:commandButton value="Annuler" oncomplete="editDomaine.hide()"/>
</h:panelGrid>
</center>
</p:outputPanel>
</p:dialog>
</h:form>
<h:form id="mainform">
<p:growl id="messages" showDetail="true"/>
<p:confirmDialog message="Etes-vous sure?" width="200"
showEffect="clip" hideEffect="clip"
header="Confirmation" severity="alert" widgetVar="confirmation">
<p:commandButton value="Oui sure" update="messages :mainform:domainlist" actionListener="#{domaine.delete()}" oncomplete="confirmation.hide()"/>
<p:commandButton value="Non" onclick="confirmation.hide()" type="button" />
</p:confirmDialog>
<p:dialog header="Ajouter un domaine" widgetVar="ajoutDomaine" modal="true" width="400" height="200" showEffect="clip" hideEffect="clip">
<p:outputPanel id="ajoutDomaineDetails" style="text-align:center;" layout="block">
<center>
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel value="Intitulé :"/>
<p:inputText value="#{domaine.nomDomaine}" style="width: 180px"/>
<h:outputLabel value="Respensable :"/>
<p:inputText value="#{domaine.nomDirecteur}" style="width: 180px"/>
<h:outputLabel value="Direction :"/>
<p:selectOneMenu id="ajoutchoidirection" value="#{domaine.codeDirection}" style="width: 180px">
<f:selectItem itemLabel="Direction..." itemValue="" />
<f:selectItems value="#{direction.initcomb()}" var="ta" itemValue="#{ta.codeDirection}" itemLabel="#{ta.libelleDirection}" />
</p:selectOneMenu>
</h:panelGrid>
<h:panelGrid columns="2" cellpadding="5">
<p:commandButton value="Ajouter" update="messages ajoutDomaineDetails :mainform:domainlist" actionListener="#{domaine.save()}" oncomplete="ajoutDomaine.hide()"/>
<p:commandButton value="Annuler" oncomplete="ajoutDomaine.hide()"/>
</h:panelGrid>
</center>
</p:outputPanel>
</p:dialog>
<p:dataTable id="domainlist" var="e" value="#{domaine.init()}">
<p:column headerText="Intitulé" filterBy="#{e.libelleDomaine}">
<h:outputText value="#{e.libelleDomaine}" />
</p:column>
<p:column headerText="Directeur" filterBy="#{e.nomDirecteur}">
<h:outputText value="#{e.nomDirecteur}" />
</p:column>
<p:column headerText="Direction" filterBy="#{e.directions.libelleDirection}">
<h:outputText value="#{e.directions.libelleDirection}" />
</p:column>
<p:column>
<h:panelGrid columns="3" style="border-color: #ffffff">
<p:commandLink update=":modifform:editDomaineDetails" title="Editer" oncomplete="editDomaine.show()">
<p:graphicImage value="resources/images/edit.png"/>
<f:setPropertyActionListener value="#{e}" target="#{domaine.currentDomaine}" />
</p:commandLink>
<p:commandLink title="Supprimer" oncomplete="confirmation.show()">
<p:graphicImage value="resources/images/delete.png"/>
<f:setPropertyActionListener value="#{e}" target="#{domaine.currentDomaine}" />
</p:commandLink>
</h:panelGrid>
</p:column>
</p:dataTable>
<p:stack icon="resources/images/stack/stck.png">
<p:menuitem value="Photo" icon="resources/images/stack/photo.png" url="http://localhost:8084/Gpsi/faces/profile-Photo.xhtml"/>
<p:menuitem value="Profile" icon="resources/images/stack/profile.png" url="http://localhost:8084/Gpsi/faces/profile.xhtml"/>
<p:menuitem value="Administration" icon="resources/images/stack/administration.png" url="http://localhost:8084/Gpsi/faces/admin.xhtml"/>
</p:stack>
</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>
here the same code on Pastebin but it's a bit messed up: http://pastebin.com/W0XGa0d2
and here is my back up bean:
......
public List<Domaines> initComb()
{
.....
}
public List<Domaines> init()
{
if(choixDirection==0)
{
domaines=domainesService.getAllDomaines();
}
else
{
Directions direction=directionsService.getDirections(choixDirection);
domaines=domainesService.getDirDomaines(direction);
}
return domaines;
}
public void save()
{
......
}
public void delete()
{
......
}
public void update()
{
......
}
////////////////////////////////////////////////////////// setters & getters \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
......
public void setCodeDirection(Integer codeDirection)
{
this.codeDirection=codeDirection;
}
public Integer getCodeDirection()
{
return codeDirection;
}
public void setNomDomaine(String nomDomaine)
{
this.nomDomaine=nomDomaine;
}
public String getNomDomaine()
{
return nomDomaine;
}
public void setNomDirecteur(String nomDirecteur)
{
this.nomDirecteur=nomDirecteur;
}
public String getNomDirecteur()
{
return nomDirecteur;
}
......
}
i posted long codes cause don't where the problem is coming from.
Your mistake is that you're doing business action in a getter method instead of an action method which is called only once. You should not do business actions in getters. JSF EL uses getters to access bean properties. EL does not cache them when they're ever called once. Getters should solely return bean properties (or at highest do some lazy loading or quick and non-intensive calculation, e.g. a simple sum like return foo + bar;), but definitely not access the database or something.
Move that job to the constructor or #PostConstruct method or any event method of the bean. In this particular case, you likely want to use #PostConstruct to preload the list with help of an #EJB and let the ajax action listener point to the same method as well. In a #ViewScoped bean, this way it's called only once during first request of the view and also called only once when you change the selection.
#PostConstruct
public void init() {
if (choixDirection == 0) {
domaines = domainesService.getAllDomaines();
} else {
Directions direction = directionsService.getDirections(choixDirection);
domaines = domainesService.getDirDomaines(direction);
}
}
public List<Domaines> getDomaines() {
return domaines;
}
and fix the view accordingly
<p:ajax process="topacteurs" listener="#{domaine.init}" update=":mainform:domainlist" />
...
<p:dataTable id="domainlist" var="e" value="#{domaine.domaines}">
See also:
Why JSF calls getters multiple times