Calendrier paramétrable avec Richfaces/Spring et hibernate
Bonjour à tous ,
j'essaie de développer un calendrier paramétrable avec une architecture Richfaces 4.0 hibernate 3.2 et Spring 2.5.
En principe mon calendrier doit permettre de sélectionner toutes les dates sauf les WE, et les dates listées dans ma BD (celles ci sont grisées).
Mon problème est que les dates qui devraient êtres grisées ne le sont pas immédiatement au chargement du calendrier. je dois faire défiler 1 mois puis retourner en arrière pour les voir apparaitre. J'ai passé 1 journée à chercher sans trouver le problème help!
Mon code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
<!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:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">
<h:outputStylesheet>
.bdc {
background-color: gray;
}
.wdc {
font-weight: bold;
font-style: italic;
}
</h:outputStylesheet>
<h:form>
<rich:calendar mode="ajax" boundaryDatesMode="scroll" dataModel="#{calendarModel}" />
</h:form>
</ui:composition> |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
|
package com.partenor.web;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import javax.annotation.PostConstruct;
import org.richfaces.model.CalendarDataModel;
import org.richfaces.model.CalendarDataModelItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import com.partenor.model.Jours_non_ouvres;
import com.partenor.service.Jours_non_ouvresService;
@Component("calendarModel")
@Scope("session")
public class CalendarModel implements CalendarDataModel {
private static final String WEEKEND_DAY_CLASS = "wdc";
private static final String OFF_DAY_CLASS = "bdc";
private static final String BOUNDARY_DAY_CLASS = "rf-ca-boundary-dates";
@Autowired
private transient Jours_non_ouvresService jours_non_ouvresService;
private List<Date> jours_non_ouvres;
private Date currentDate;
private Calendar current;
private Calendar today;
@PostConstruct
public void init(){
jours_non_ouvres=jours_non_ouvresService.findAllDate();
}
private boolean checkOffDay(Calendar calendar) {
return jours_non_ouvres.contains(calendar.getTime());
}
private boolean checkWeekend(Calendar calendar) {
return (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY || calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY);
}
public CalendarDataModelItem[] getData(Date[] dateArray) {
CalendarDataModelItem[] modelItems = new CalendarModelItem[dateArray.length];
current = GregorianCalendar.getInstance();
today = GregorianCalendar.getInstance();
today.setTime(new Date());
for (int i = 0; i < dateArray.length; i++) {
current.setTime(dateArray[i]);
CalendarModelItem modelItem = new CalendarModelItem();
if (checkOffDay(current)) {
modelItem.setEnabled(false);
modelItem.setStyleClass(OFF_DAY_CLASS);
} else if (current.before(today)) {
modelItem.setEnabled(false);
modelItem.setStyleClass(BOUNDARY_DAY_CLASS);
} else if (checkWeekend(current)) {
modelItem.setEnabled(false);
modelItem.setStyleClass(WEEKEND_DAY_CLASS);
} else {
modelItem.setEnabled(true);
modelItem.setStyleClass("");
}
modelItems[i] = modelItem;
}
return modelItems;
}
public Object getToolTip(Date date) {
// TODO Auto-generated method stub
return null;
}
/**
* @param currentDate the currentDate to set
*/
public void setCurrentDate(Date currentDate) {
this.currentDate = currentDate;
}
/**
* @return the currentDate
*/
public Date getCurrentDate() {
return currentDate;
}
} |