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>
Related
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
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 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.
I am using JSF 2.0 with PrimeFaces 3.0 M3. When I set dynamic="false" on <p:tabView>, then it works fine. But when I set it to true, then only the currently active tab works. Other tabs does not run. In the 1st tab I have a command link in a data table, this is also not working.
Below is my tabletabview.xhtml:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
</h:head>
<h:body>
<f:view>
<h:form>
<p:growl id="growl" showDetail="true" />
<p:tabView cache="false" dynamic="true" activeIndex=0 >
<p:ajax event="tabChange" listener="ActivityController.onChange"/>
<p:tab title="Search Results 1">
<p:dataTable var="dataItem" value="#{ActivityController.dataList}">
<p:column>
<p:panel style="font-size:12px;width:600px">
<f:facet name="header">
<h:outputText value="#{dataItem.activityname}" />
</f:facet>
<div style="background-color: #DEB887;">
<h:outputText value="Location:" style="color:#FF0000;"></h:outputText>
<h:outputText value="#{dataItem.address}" />
<br></br>
</div>
<div style="background-color: #DEB887;">
<h:outputText value="Start Date:" style="color:#FF0000;"></h:outputText>
<h:outputText value="#{dataItem.startingdate}" />
<br></br>
</div>
<div style="background-color: #DEB887;">
<h:outputText value="Start Date:" style="color:#FF0000;"></h:outputText>
<h:outputText value="#{dataItem.endingdate}" />
</div>
<div style="background-color: #DEB887;">
<h:outputText value="Description:" style="color:#FF0000;"></h:outputText>
<h:outputText value="#{dataItem.description}" />
<br></br>
</div>
<p:commandLink action="#{ActivityController.editDataItem}">
<div style="display: none">
<h:outputText value="#{dataItem.activityname}" />
</div>
<h:outputText value="more....."></h:outputText>
<f:setPropertyActionListener target="#{ActivityController.dataItem}" value="#{dataItem}" />
</p:commandLink>
</p:panel>
</p:column>
</p:dataTable>
</p:tab>
<p:tab title="Search Results 2">
<p:panel style="width:600px;height:600px">
<p:schedule id="sche" value="#{searchController.eventModel}"
editable="true" draggable="false" resizable="false"
widgetVar="myschedule">
<p:ajax event="eventSelect"
listener="#{searchController.onEventSelect}" update="red"
process="#this" />
</p:schedule>
</p:panel>
</p:tab>
<p:tab id="gmap" title="Search Results 3">
<ui:include src="/locationpointers.xhtml"></ui:include>
</p:tab>
</p:tabView>
</h:form>
</f:view>
</h:body>
</html>
This is the relevant part of my ActivityController.java
public List<ActivityRegBean> getDataList() {
return dataList;
}
public void setDataList(List<ActivityRegBean> dataList){
this.dataList=dataList;
}
private ActivityRegBean dataItem;
private HtmlInputHidden dataItemId = new HtmlInputHidden() ;
public String editDataItem() throws IOException {
FacesContext context = FacesContext.getCurrentInstance();
System.out.println(dataItem.activityname);
dataItemId.setValue(dataItem.activityid);
System.out.println(dataItem.activityid);
retfromtable(dataItem.activityname);
return "edit"; // Navigation case.
}
public void onChange(TabChangeEvent event) {
System.out.println("tab id = " + event.getTab().getId());
}
The ActivityRegBean has a getter and setter.
How can I use dynamic="true" on the <p:tabView> without problems?
Can you try this instead of p:ajax
<p:tabView cache="false" dynamic="true" tabChangeListener="#{ActivityController.onChange}" onTabChangeUpdate="growl">
I have noticed that you are using xmlns:p="http://primefaces.prime.com.tr/ui" . It is for primefaces 2.2 and if you are indeed using primefaces 3, then it will complain about no taglibrary exists for that namespace. for PF3 you should be using xmlns:p="http://primefaces.org/ui" . may be you should clean your work directory.
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