I'm trying to display objects from a map with a dataList. These objetcs are editable. I have some issues I can't understand. Can someone explain me why it does not work as expected?
Code: Select all
<h:panelGroup id="dateEffetPanel">
<div id="dateEffet" class="#{empty peuplementCenterLayoutMB.reglesAvecDateEffet ? 'displayNone' : ''} dateEffetDiv">
<p:dataList var="entry" value="#{peuplementCenterLayoutMB.reglesAvecDateEffetAsEntryList}" styleClass="periodeEdit" rowIndexVar="indexStatus">
<p:dataTable value="#{entry.value}" id="periodeDatatable" var="value" emptyMessage="Pas de périodes" editable="true" rowStyleClass="#{rowStyleFromRowStateMB.getStyleFromState(value)}">
<p:ajax event="rowEdit" listener="#{peuplementCenterLayoutMB.onRowEdit(value)}" />
<f:facet name="header">
<h:outputText value="Période du : " style="margin-left: 5px;"/>
<p:calendar id="calendarStart${indexStatus}" value="#{entry.key.dateDebut}" disabled="#{!entry.key.hasDateDebut}" binding="#{startDateComponent}" locale="fr" pattern="dd/MM/yyyy" mode="popup" navigator="true" pages="3" required="#{entry.key.hasDateDebut}" requiredMessage="La date de début ne peut pas être nulle" >
<f:validator validatorId="periodeValidator" />
<f:attribute name="endDateComponent" value="#{endDateComponent}" />
<f:attribute name="codePeriode" value="#{entry.key.code}" />
<f:attribute name="mapDateEffet" value="#{peuplementCenterLayoutMB.reglesAvecDateEffet}" />
</p:calendar>
<h:outputText value=" au " />
<p:calendar id="calendarEnd${lol}" value="#{entry.key.dateFin}" disabled="#{!entry.key.hasDateFin}" binding="#{endDateComponent}" locale="fr" pattern="dd/MM/yyyy" mode="popup" navigator="true" pages="3" required="#{entry.key.hasDateFin}" requiredMessage="La date de fin ne peut pas être nulle">
<f:validator validatorId="periodeValidator" />
<f:attribute name="startDateComponent" value="#{startDateComponent}" />
<f:attribute name="codePeriode" value="#{entry.key.code}" />
<f:attribute name="mapDateEffet" value="#{peuplementCenterLayoutMB.reglesAvecDateEffet}" />
</p:calendar>
<p:selectBooleanButton value="#{entry.key.active}" onLabel="Active" offLabel="Inactive" onIcon="ui-icon-check" offIcon="ui-icon-close" style="width:100px; margin-left: 20px;" />
<p:selectBooleanButton value="#{entry.key.hasDateDebut}" onLabel="Avec date de debut" offLabel="Sans date de début" onIcon="ui-icon-check" offIcon="ui-icon-close" style="width:150px; margin-left: 20px;" >
<p:ajax update="calendarStart"/>
</p:selectBooleanButton>
<p:selectBooleanButton value="#{entry.key.hasDateFin}" onLabel="Avec date de fin" offLabel="Sans date de fin" onIcon="ui-icon-check" offIcon="ui-icon-close" style="width:150px; margin-left: 20px;" >
<p:ajax update="calendarEnd"/>
</p:selectBooleanButton>
</f:facet>
<p:column>
<f:facet name="header">
<p:commandButton icon="ui-icon-circle-plus" process="@this" title="Ajouter" styleClass="headerAddButton" actionListener="#{peuplementCenterLayoutMB.addRow(entry.key)}" update=":formCenterEdit:dateEffetPanel"/>
</f:facet>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{value.property.code}" />
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{value.property}" style="width:100%" converter="structureProprieteConverter">
<f:selectItems value="#{peuplementCenterLayoutMB.getCodes()}" var="#{structureReglePropriete}" itemLabel="#{structureReglePropriete.code}" itemValue="#{structureReglePropriete.model}" />
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column headerText="Valeur">
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{value.valeur}" />
</f:facet>
<f:facet name="input">
<h:inputText value="#{value.valeur}" required="true" requiredMessage="Veuillez indiquer une valeur" />
</f:facet>
</p:cellEditor>
</p:column>
<p:column width="40">
<p:rowEditor />
</p:column>
</p:dataTable>
</p:dataList>
PeuplementCenterLayoutMB.java
Code: Select all
...
private HashMap<PeriodeValiditeModel, List<RegleProprieteViewBean>> reglesAvecDateEffet = new HashMap<>();
...
public List<Entry<PeriodeValiditeModel, List<RegleProprieteViewBean>>> getReglesAvecDateEffetAsEntryList() {
if (reglesAvecDateEffet == null) {
reglesAvecDateEffet = new HashMap<>();
}
Set<Entry<PeriodeValiditeModel, List<RegleProprieteViewBean>>> entrySet = reglesAvecDateEffet.entrySet();
ArrayList<Entry<PeriodeValiditeModel, List<RegleProprieteViewBean>>> arrayList = new ArrayList<Entry<PeriodeValiditeModel, List<RegleProprieteViewBean>>>(entrySet);
return arrayList;
}
public void addRow(PeriodeValiditeModel p) {
RegleProprieteViewBean regleVB = new RegleProprieteViewBean();
regleVB.setModeUpdate(AbstractViewbean.MODE_INSERT);
reglesAvecDateEffet.get(p).add(regleVB);
}
Code: Select all
package com.almerys.pr2m.business.model;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
public class PeriodeValiditeModel implements Serializable {
private static final long serialVersionUID = 1L;
/** Identifiant BBD */
private long key = 0;
private long code;
/** Periode active ou non */
private boolean active = true;
/** Date de début de la période de validité */
private Date dateDebut;
/** Date de fin de la période de validité */
private Date dateFin;
/** boolean indiquant si la période possède une date de debut */
private boolean hasDateDebut;
/** boolean indiquant si la période possède une date de fin */
private boolean hasDateFin;
public long getKey() {
return key;
}
public void setKey(long key) {
this.key = key;
}
public Date getDateDebut() {
return dateDebut;
}
public void setDateDebut(Date dateDebut) {
this.dateDebut = dateDebut;
}
public Date getDateFin() {
return dateFin;
}
public void setDateFin(Date dateFin) {
this.dateFin = dateFin;
}
@Override
public String toString() {
SimpleDateFormat formater = new SimpleDateFormat("dd-MM-yy");
return "Periode du " + (dateDebut == null ? " - " : formater.format(dateDebut)) + " au " + (dateFin == null ? " - " : formater.format(dateFin)) + " code : " + code;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
PeriodeValiditeModel other = (PeriodeValiditeModel) obj;
if (other.code == code)
return true;
else
return false;
}
@Override
public int hashCode() {
int result = 7;
int multiplier = 17;
result = (int) (multiplier * result + code);
return result;
}
public long getCode() {
return code;
}
public void setCode(long code) {
this.code = code;
}
public boolean isActive() {
return active;
}
public void setActive(boolean active) {
this.active = active;
}
public boolean getHasDateDebut() {
return hasDateDebut;
}
public void setHasDateDebut(boolean hasDateDebut) {
this.hasDateDebut = hasDateDebut;
}
public boolean getHasDateFin() {
return hasDateFin;
}
public void setHasDateFin(boolean hasDateFin) {
this.hasDateFin = hasDateFin;
}
}
this is when I open the view :
this is when I add new rows in dataList :
The new row should normally have empty dates...
Many thanks
PS: I also tried to replace dataList with f:forEach, and ui:repeat... But it's worse.
JSF 2.1 (Mojarra) PF 4.0 JBoss 7.1