Object not popule after click in yes in dialog - jsf

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>

Related

JSF Form Validation

I am trying to persist a form in JSF page with many inputs. in parallel I added client side validation to process before entering to the actionLisner method.
The issus is that if I make the commandbutton inside <h:form> and outside <p:panel> the validation is OK but the action does not do anything (if all the fiels are validated). If I make the commandbutton inside <p:panel> the opposite happens, the validation does not work anymore and even if some fiels are empty, the method in actionListner is called.
<?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:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:p="http://primefaces.org/ui">
<ui:composition template="/template.xhtml">
<ui:define name="title">
<h:outputText value="Entretien annuel - Personnel d'Agence">
</h:outputText>
</ui:define>
<ui:define name="body">
<div align="center">
<h:form id="CollaborateurViewForm">
<h:panelGroup id="display">
<p:panel header="Détails du Collaborateur">
<p:panelGrid columns="2" rendered="#{collaborateurController.selected !=
null}">
<h:outputText value="#{bundle.ViewCollaborateurLabel_idCollaborateur}"/>
<h:outputText value="#{collaborateurController.selected.idCollaborateur}"
title="#{bundle.ViewCollaborateurTitle_idCollaborateur}"/>
</p:panelGrid>
</p:panel>
</h:panelGroup>
</h:form>
</div>
<h:form id="testForm" >
<p:panel id="entretienFormPa" header="Entretien annuel - Personnel d'Agence">
<div align="center">
<p:panelGrid columns="2">
<p:panel header="Détails de l'entretien">
<p:outputLabel for="collaborateursItem" value="Entretien mené par :"/>
<p:selectManyMenu id="collaborateursItem" filter="true" filterMatchMode="contains"
showCheckbox="true"
value="#{entretienController.entretienMenePar}">
<p:ajax process="#this"/>
<f:selectItems id="entretienMenePar" value="#
{collaborateurController.itemsAvailableSelectMany}"
var="entretienMeneParItem"
itemValue="#{entretienMeneParItem}"/>
</p:selectManyMenu>
</p:panel>
</p:panelGrid>
<p:panel header="Saisie des notes de l'entretien">
<p:tabView>
<p:tab title="#{bundle.Personnel_Organisation_Commerciale}">
<h:panelGrid columns="2" cellpadding="10" cellspacing="10">
<p:outputLabel value="#
{bundle.Personnel_Organisation_Commerciale_Comprehension}" for="noteItem11"/>
<p:selectOneButton id="noteItem11" value="#
{entretienController.note11}"
required="true"
requiredMessage="#
{bundle.NoteEntretien_Requise}">
<f:selectItems value="#
{entretienController.listeNotesPossibles}"
var="noteItem"
itemValue="#{noteItem}"/>
<p:ajax process="#this"/>
</p:selectOneButton>
<p:outputLabel
value="#{bundle.Personnel_Organisation_Commerciale_Actions}" for="noteItem12"/>
<p:selectOneButton id="noteItem12" value="#
{entretienController.note12}"
required="true"
requiredMessage="#
{bundle.NoteEntretien_Requise}">
<f:selectItems value="#
{entretienController.listeNotesPossibles}"
var="noteItem"
itemValue="#{noteItem}"/>
<p:ajax process="#this"/>
</p:selectOneButton>
<p:outputLabel for="commentaireOrgaCom" value="Commentaire de suivi : " style="font-weight: bold"/>
<p:inputTextarea id="commentaireOrgaCom" value="#{entretienController.commentaireOrgaCom}"
rows="4" cols="50">
<p:ajax process="#this"/>
</p:inputTextarea>
</h:panelGrid>
</p:tab>
</p:tabView>
</p:panel>
<p:tabView>
<p:tab title="#{bundle.Da_Divers}">
<div align="center">
<p:outputLabel for="diagnosticItem" value="Diagnostic : " />
<p:inputTextarea id="diagnosticItem" value="#
{entretienController.diagItem}" rows="8" cols="67" required="true"
requiredMessage="#{bundle.Diagnostic_Requis}">
<p:ajax process="#this"/>
</p:inputTextarea>
</h:panelGrid>
</div>
</p:tab>
</p:tabView>
</div>
</p:panel>
<div align="right">
<p:commandButton id="saveEntretienButton" value="Enregistrer"
process="entretienFormPa" update="entretienFormPa" immediate="true"
actionListener="#
{noteEntretienController.saveEntretienActionPa(entretienController,
collaborateurController)}">
<p:confirm header="Confirmation" message="Etes-vous sûr de vouloir
enregistrer l'entretien ?" />
</p:commandButton>
<p:commandButton value="Retour" action="Details"
ajax="false" />
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:commandButton value="Oui" type="button" styleClass="ui-confirmdialog-yes" />
<p:commandButton value="Non" type="button" styleClass="ui-confirmdialog-no" />
</p:confirmDialog>
</div>
</h:form>
</ui:define>
</ui:composition>
</html>
I also tried to add validateClient="true" on the commandButton
Thank in advance !
UPDATE :
I resolved the issue without knowing what was the source. I go back to the initial example given on primefaces showcase, I added my fields one by one. Know all is good

Button not rendered after upload file

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>

Component SelectOneMenu primefaces does not work on a Dialog component

The p:selectOneMenu of PrimeFaces does not work within a p:dialog. His appearance is unconfigured. By removing the component, the others work correctly.
I have already appendToBody="true" in the dialog and it still does not work. If someone has already experienced this or has an idea of ​​this behavior, please leave your comment or response.
Button that calls the dialog
<button id="btnNovoContatoID"
class="btn btn-flat btn-info"
onclick="PF('dlgNovoContato').show(); return false;"
jsf:update="modalNovoContato"
>Novo Contato
</button>
Include Dialog
<ui:define name="popups">
<ui:include src="teste.xhtml"/>
</ui:define>
Complete form
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
xmlns:o="http://omnifaces.org/ui"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:sgr="http://www.sgr.com.br/jsf"
template="/WEB-INF/facelets/templates/layout.xhtml">
<ui:param name="form_id" value="formCadPessoa"/>
<ui:param name="titlePage" value="Pessoa"/>
<ui:param name="subTitlePage" value="Cadastrado de Pessoas"/>
<f:metadata>
<f:viewAction action="#{pessoaBean.inicializarFormParaEdicao(param.pessoaId)}"/>
</f:metadata>
<ui:define name="panelCadastro">
<p:panelGrid columns="2" layout="grid" columnClasses="ui-grid-col-2, ui-grid-col-7" styleClass="ui-panelgrid-blank">
<p:outputLabel value="Nome:"/>
<p:inputText id="inptNome" value="#{pessoaBean.pessoa.nome}"/>
</p:panelGrid>
<p:panelGrid columns="2" layout="grid" columnClasses="ui-grid-col-2, ui-grid-col-3" styleClass="ui-panelgrid-blank">
<p:outputLabel value="Tipo Pessoa:"/>
<p:selectOneMenu id="iptTipPessoa" value="#{pessoaBean.pessoa.tipoPessoa}" converter="tipoPessoaConverter" >
<p:ajax event="change" update="lblCpf"/>
<f:selectItems value="#{pessoaBean.tiposPessoa}"/>
</p:selectOneMenu>
<p:outputLabel id="lblCpf" value="#{pessoaBean.pessoa.tipoPessoa eq 'FISICA' ? 'CPF' : 'CNPJ'}:"/>
<p:inputText value="#{pessoaBean.pessoa.cpfCnpj}" maxlength="14"/>
<p:outputLabel value="Nascimento:"/>
<p:calendar value="#{pessoaBean.pessoa.dataNascimento}" pattern="dd/MM/yyyy" />
</p:panelGrid>
<p:panelGrid columns="1" layout="grid" columnClasses="ui-grid-col-12" styleClass="ui-panelgrid-blank">
<div class="box-title pull-right">
<button id="btnNovoContatoID"
class="btn btn-flat btn-info"
onclick="PF('dlgNovoContato').show(); return false;"
jsf:update="modalNovoContato"
>Novo Contato
</button>
</div>
</p:panelGrid>
<p:dataTable id="dtContatos" var="obj" value="#{pessoaBean.pessoa.contatos}">
<f:facet name="header">
Contatos Cadastrados
</f:facet>
<p:column headerText="Tipo" width="20%">
<h:outputText value="#{obj.tipoContato}"/>
</p:column>
<p:column headerText="Descrição" width="80%">
<h:outputText value="#{obj.descricao}"/>
</p:column>
</p:dataTable>
</ui:define>
<ui:define name="footerBoxButton">
<button id="btnSalvarID"
type="submit"
jsf:update="messages,formCadPessoa"
jsf:process="#form"
class="btn btn-flat btn-success"
jsf:action="#{pessoaBean.salvar}">Salvar
</button>
<p:spacer width="10"/>
Voltar
</ui:define>
<ui:define name="popups">
<ui:include src="teste.xhtml"/>
</ui:define>
</ui:composition>
Dialog Page
<p:dialog xmlns="http://www.w3.org/1999/xhtml"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:jsf="http://xmlns.jcp.org/jsf"
xmlns:sgr="http://www.sgr.com.br/jsf"
id="modalNovoContato"
header="Novo Contato"
widgetVar="dlgNovoContato"
minHeight="200"
width="650"
resizable="false"
closeOnEscape="true">
<p:panelGrid columns="2" layout="grid" columnClasses="ui-grid-col-3, ui-grid-col-9" styleClass="ui-panelgrid-blank">
<h:outputLabel value="Tipo Contato:" />
<p:selectOneMenu value="#{pessoaBean.contato.tipoContato}" converter="tipoContatoConverter" >
<f:selectItems value="#{pessoaBean.tiposContato}"/>
</p:selectOneMenu>
<h:outputLabel value="Descrição:"/>
<p:inputText label="inputDescricao" style="width: 300px">
<sgr:upperCase/>
</p:inputText>
</p:panelGrid>
<f:facet name="footer">
<button id="btnSalvarContatoID"
type="submit"
jsf:update="messages"
jsf:process="#form"
jsf:action="#{pessoaBean.salvar}"
class="btn btn-flat btn-success">Adicionar
</button>
</f:facet>
</p:dialog>
Wrong dialog image

Init method gets called twice in #Viewscoped bean

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.

function called many times for no reason

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

Resources