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
Related
I am having trouble retrieving the values filled in the form when clicking the yes button in the dialog, the data does not appear filled in the respective objects.
What is going on? Didn't I correctly update the button?
Class PostionInformation
public class PostionInformation{
private Box box;
private Position position;
public PostitionInformation(){
box = new Box();
position = new Position();
}
}
Bean
public void savwPostionFinish() {
Box box = new Box();
if(this.positionInformation.getBox() != null) {
box = this.positionInformation.getBox();
}
List<Position> list= dao.searchBox(box);
changeInformation(positions);
}
public void chanceInformation(List<Position> postions) {
//List empyty
}
form.xhtml
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
template="/WEB-INF/template.xhtml">
<h:form id="formMain">
<p:messages id="messages" showDetail="true">
<p:autoUpdate />
</p:messages>
<div class="ui-g ui-fluid">
<div class="ui-g-12">
<div class="card card-w-title">
<p:panelGrid columns="2" layout="grid" styleClass="ui-panelgrid-blank form-group" id="formBox">
<p:selectOneMenu id="cbboxBox" value="#{positionMng.positionInformation.box}"
converter="#{boxConverter}" required="true"
immediate="true">
<f:selectItem itemLabel="#{msg.optionBox}"/>
<f:selectItems value="#{positionMng.listaBoxes}" var="box"
itemValue="#{box}" itemLabel="#{box.name}"/>
</p:selectOneMenu>
</p:panelGrid>
<p:panelGrid columns="2" layout="grid" styleClass="ui-panelgrid-blank form-group" id="formSituation">
<h:panelGroup>
<p:outputLabel for="radioSituation" value="#{msg.labelSituation}" />
<p:selectOneRadio layout="responsive" columns="3" id="radioSituation" value="#{positionMng.changeInformation.position.situation}"
converter="positionSituationConverter" required="true"
immediate="true">
<f:selectItems value="#{positionMng.listSituation}" var="position"
itemValue="#{position}" itemLabel="#{position.name}"/>
</p:selectOneRadio>
</h:panelGroup>
</p:panelGrid>
<p:panelGrid columns="2" layout="grid" styleClass="ui-panelgrid-blank form-group">
<p:commandButton icon="ui-icon-save"
value="#{msg.save}" oncomplete="PF('confirmFinish').show()"
process="#this" update=":formMain:finishDialog"
title="#{msg.salvar}"/>
<p:commandButton icon=" ui-icon-closethick" action="#{positionMng.cancel()}"
value="#{msg.cancel}" immediate="true"
title="#{msg.cancel}"/>
</p:panelGrid>
</div>
</div>
</div>
<p:confirmDialog header="#{msg.messageFinish}"
message="#{msg.messageFinishAlteracaoPosicaoLote} #{msg.mensagemContinue}"
widgetVar="confirmFinish" id="finishDialog">
<p:commandButton value="#{msg.yes}" oncomplete="PF('confirmFinish').hide();"
action="#{positionMng.savePositionFinish()}" process="#this"
update=":formMain:formSituation :formMain:formDadosBox" id="yesButton" />
<p:button value="#{msg.no}" onclick="PF('confirmFinish').hide(); return false;" />
</p:confirmDialog>
</h:form>
</ui:define>
</ui:composition>
I want to render a button after upload a file, I have selectOneMenuto chose options, when I upload the file with the first option, the button didn't rendered but it rendered after I chose the second option.
ManagedBean.java
private boolean viewImport;
public boolean isViewImport() {
return viewImport;
}
public void setViewImport(boolean viewImport) {
this.viewImport = viewImport;
}
public void processFiless(FileUploadEvent event) {
setViewImport(true);
}
import.xhtml
<ui:composition template="./../../../../template.xhtml">
<ui:define name="content">
<h:form id="form1" prependId="false">
<p:growl id="messages"/>
<h1><h:outputText value="#{customerData.importBatchTitle}" /></h1>
<div class="formSection">
<p:panel header="#{app['import.fileSelectionForm']}" id="importFile" toggleable="true" toggleSpeed="300">
<h:graphicImage styleClass="formimg" url="/images/orange/fleche2.gif"/><h:outputText value="#{app['import.contract.parameter.primal']}" />
<h:selectOneMenu value="#{customerData.parameterType}">
<f:selectItems value="#{customerData.parameterTypeItems}" />
<p:ajax actionListener="#{customerData.selectionParameterType}" event="change" update="form1"/>
</h:selectOneMenu>
<br/>
<br/>
<h:panelGroup rendered="#{customerData.viewUpload}">
<p:fileUpload update="form1" fileUploadListener="#{customerData.processFiless}" >
<p:ajaxStatus>
<f:facet name="start">
<h:graphicImage value="/images/ajaxloading.gif" />
</f:facet>
<f:facet name="complete" >
<h:outputText value="" />
</f:facet>
</p:ajaxStatus>
</p:fileUpload>
</h:panelGroup>
</p:panel>
<br/>
<f:subview id="modifyCustt" rendered="#{customerData.viewImport}">
<p:commandButton value="ok"></p:commandButton>
</f:subview>
</div>
</h:form>
</ui:define>
</ui:composition>
I have a fileUploader which disappears after partial site refresh
Here is my xhtml file
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="/WEB-INF/templates/traleerdf-template.xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns="http://www.w3.org/1999/xhtml">
<ui:define name="content">
<f:metadata>
<f:event type="preRenderView"
listener="#{registration.loadRegistrationDetails()}" ></f:event>
</f:metadata>
<p:ajaxStatus onstart="PF('statusDialog').show();" onsuccess="PF('statusDialog').hide();"/>
<p:dialog modal="true" widgetVar="statusDialog" header="Saving"
draggable="false" closable="false">
<p:graphicImage value="/images/ajax-loader.gif"/>
</p:dialog>
<h:form id="form" enctype="multipart/form-data">
<p:panelGrid id="detail" columns="1" >
<p:dataTable var="reg" id="datatable" value="#{registration.registrationDTOs}" rows="12">
<p:column headerText="Name" style="width:5%">
<p:outputLabel value="#{reg.sourceName}"/>
</p:column>
<p:column headerText="Path Prefix" style="width:5%">
<p:outputLabel value="#{reg.pathPrefix}"/>
</p:column>
<p:column headerText="Template File" style="width:30%">
<p:commandButton id="templateButton" value="Get Template" oncomplete="tempDlg.show();" process="#this" title="Template File"
update=":topForm:form:growl :topForm:form:tempId">
<f:setPropertyActionListener value="#{reg}" target="#{registration.registrationDTO}" />
</p:commandButton>
</p:column>
<p:column style="width:2%" headerText="Update">
<p:commandButton id="selectButton" update=":topForm:form:growl :topForm:form:display" process="#this" oncomplete="regDialog.show()" icon="ui-icon-search" title="Edit">
<f:setPropertyActionListener value="#{reg}" target="#{registration.registrationDTO}" />
</p:commandButton>
</p:column>
</p:dataTable>
<p:dialog header="Registration Detail" widgetVar="regDialog" resizable="false" id="regDlg" showEffect="fade" hideEffect="explode" modal="true">
<p:panelGrid id="display" columns="2" style="margin:0 auto;" >
<p:outputLabel id="lblEndpoint" for="txtEndpoint" value="#{msg['Registration.Endpoint']}"/>
<h:outputText id="txtEndpoint" value="#{registration.registrationDTO.endpoint}"/>
<p:outputLabel id="lblSourceName" for="txtSourceName" value="#{msg['Registration.sourceName']}"/>
<p:inputText required="true" id="txtSourceName" value="#{registration.registrationDTO.sourceName}" requiredMessage="Source name not entered"/>
<p:outputLabel id="lblPathPrefix" for="txtPathPrefix" value="#{msg['Registration.pathPrefix']}"/>
<p:inputText disabled="true" required="true" id="txtPathPrefix" size="20" value="#{registration.registrationDTO.pathPrefix}" requiredMessage="Path prefix is required"/>
<p:outputLabel id="lblTemplateFile" for="txtTemplateFile" value="#{msg['Registration.templateFile']}"/>
<p:fileUpload required="true" id="txtTemplateFile" fileUploadListener="#{registration.uploadTemplateFile}" requiredMessage="Template File required"
mode="advanced" widgetVar="txtTemplateFile" value="#{registration.registrationDTO.templateFile}" update=":topForm:form:growl">
</p:fileUpload>
<h:panelGroup>
<p:commandButton icon="ui-icon-disk" id="btnUpdte" update=":topForm:form:growl :topForm:form:panel" ajax="true" action="#{registration.updateRegistration()}" style="margin-right:20px;"
value="Update" >
</p:commandButton>
</h:panelGroup>
</p:panelGrid>
</p:dialog>
<p:dialog header="Template Dialog" widgetVar="tempDlg" modal="true" height="100" showEffect="fade" hideEffect="explode">
<p:panelGrid id="tempId" style="margin:0 auto;" columns="2">
<p:outputLabel id="TemplateFileLbl" for="TemplateFile" value="#{msg['Registration.templateFile']}"/>
<h:outputText value="#{registration.registrationDTO.templateFile}" id="TemplateFile"/>
</p:panelGrid>
</p:dialog>
</p:panelGrid>
</p:panel>
</h:form>
</ui:define>
</ui:composition>
The upload button will open a new dialog which allows the user to edit the fields and can upload a new template file.
My Problem is every time the upload button in the dialog is clicked, f:event method method is invoked which is expected as it is of type prerender but is there anyway to avoid this event call for the fileupload because it is overwriting the template file name I uploaded. (prerender method is making a call to db to get the list of details which in the case overriding the template file.)
From the namespaces you're using, I presume you're using JSF 2.2. In this version, you can have
<f:viewAction action="#{registration.loadRegistrationDetails()}"/>
The viewAction tag is not executed on postback by default.
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 am using schedule component of Primefaces. I am filling it with values from database and when the user selects sth from the selectonemenu an ajax event is triggered (I tried to put just the related code, if there is sth missing pls remind me):
xhtml:
<h:outputText value="Scope :" />
<h:selectOneMenu id="scope" value="#{scheduleView.scope}">
<f:selectItems value="#{lookup.scopeCombo}"/>
<p:ajax process="scope" update="schedule, scheduleForm, scheduleFormPG" listener="#{scheduleView.changeScopeType()}"/>
</h:selectOneMenu>
<p:schedule id="schedule" value="#{scheduleView.model}" editable="true"/>
Backing bean:
#ManagedBean
#ViewScoped
public class ScheduleView implements Serializable {
#PostConstruct
public void init() {
System.out.println("Init ");
scopeChange();
}
public void scopeChange(String scope){
System.out.println("scopeChange ");
model.clear();
events = (List<Event>) commonServis.bringEverythingByCriteria(Event.class, "scope" , scope);
for(int i= 0; i<events.size();i++){
model.addEvent(new DefaultScheduleEvent(events.get(i).getAd(), events.get(i).getStartDate(),events.get(i).getEndDate()));
}
public void changeScopeType() {
System.out.println("changeScopeType ");
scopeChange (scope);
}
The output of the above code is:
Init
scopeChange
When the user changes the value in the selectonemenu:
changeScopeType
Init
scopeChange
It is supposed to go into init method just once. But after the changeScopeType function is triggered it gets into the init method and fills the schedule with unrelated data. I thought it might be related to #Postconstruct annotation but I couldn't find any related explanation. Can anyone understand the reason and offer a solution?
Here is the full page:
<?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.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://prime.primefaces.org/ui"
template="templates/layout.xhtml"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<ui:define name="title">#{labels.schedule}</ui:define>
<ui:define name="content">
<h:form id="scheduleForm">
<h:panelGrid id="scheduleFormPG">
<p:growl id="msgs" />
<p:dialog modal="true" widgetVar="statusDialog" header="Status" draggable="false">
<h:graphicImage value="resources/images/ajax-loader.gif" />
</p:dialog>
<p:dialog showEffect="explode" hideEffect="explode" resizable="false"
header="warning" widgetVar="confirmationErase" appendToBody="true" modal="true">
<h:outputText value="Are you sure?"/>
<br/>
<p:commandButton value="Yes" actionListener="#{scheduleView.deleteEvent(AE)}"
update="msgs, scheduleFormPG, schedule, wrapperPanel"
onstart="statusDialog.show(),confirmationErase.hide()"
oncomplete="statusDialog.hide(), eventDialog.hide()" process="#parent, scope" />
<p:commandButton value="No" onclick="confirmationErase.hide()" type="button" />
</p:dialog>
<h:outputText value="scope :" />
<h:selectOneMenu id="scope" value="#{scheduleView.scope}">
<f:selectItems value="#{lookup.scopeTypeCombo}"/>
<p:ajax process="scope" update="schedule, scheduleForm, scheduleFormPG" listener="#{scheduleView.changeScopeType()}"/>
</h:selectOneMenu>
</h:panelGrid>
<p:schedule onDateSelectUpdate="wrapperPanel"
onEventSelectUpdate="wrapperPanel" onEventSelectComplete="eventDialog.show()" eventSelectListener="#{scheduleView.onEventSelect}"
onDateSelectComplete="eventDialog.show();" dateSelectListener="#{scheduleView.onDateSelect}" id="schedule" value="#{scheduleView.model}" editable="true"/>
<p:dialog id="dialog111" widgetVar="eventDialog" header="Event Information" showEffect="clip" hideEffect="clip">
<p:panel id="wrapperPanel">
<h:panelGrid id="eventDetails" columns="2">
<h:outputLabel for="eventName" value="Event Name *: " />
<p:inputText id="eventName" value="#{scheduleView.event.title}" required="true"/>
<h:outputLabel value="Start Date:" />
<p:calendar id="sKalender" value="#{scheduleView.event.startDate}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</p:calendar>
<h:outputLabel value="End Date:" />
<p:calendar id="eKalender" value="#{scheduleView.event.endDate}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</p:calendar>
<h:outputLabel value="All Day:" />
<h:selectBooleanCheckbox id="allDay" value="#{scheduleView.event.allDay}" />
<h:outputLabel value="scope: " />
<h:selectOneMenu id="scopeChoice" value="#{scheduleView.event.scope}">
<f:selectItems value="#{lookup.scopeTypeCombo}"/>
</h:selectOneMenu>
<p:commandButton onclick="confirmationErase.show()" oncomplete="eventDialog.hide()" update="wrapperPanel, msgs, schedule" type="reset" value="Delete" />
<p:commandButton value="Save" actionListener="#{scheduleView.addEvent(AE)}" process="#parent, scope" update="schedule wrapperPanel msgs scheduleForm" oncomplete="eventDialog.hide();"/>
</h:panelGrid>
</p:panel>
</p:dialog>
</h:form>
</ui:define>
</ui:composition>
The problem was this line of code:
<p:ajax process="scope" update="schedule, scheduleForm, scheduleFormPG" listener="#{scheduleView.changeScopeType()}"/>
update was refreshing the whole page, instead it should've only update schedule. When I change it to:
update="schedule"
the problem solved.
Thanks everyone for their effort.