can I put something else then strings into the calendarDataM
mario.balaban Nov 3, 2008 5:28 AMI'm developing an agenda using the rich:calendar. In each day cell I'd like to put a selectable and modifiable list of events of the day (similar to google calendar or the one in the teamwork project). I'm trying to put a instance of the ListaDataModel (containing objects with name property) into the HashMap used by the dataModel attribute of the calendar. Here is the code:
<rich:calendar id="calendarAttivita" datePattern="dd/MM/yyyy" enableManualInput="false" popup="false" mode="ajax" styleClass="fontMedium" cellWidth="50px" dataModel="#{myDataModel}"> <!-- Customization with usage of facets and accessible elements --> <f:facet name="weekDay"> <h:panelGroup style="width:60px; overflow:hidden;" layout="block"> <h:outputText value="{weekDayLabelShort}" /> </h:panelGroup> </f:facet> <f:facet name="weekNumber"> <h:panelGroup> <h:outputText value="{weekNumber}" style="color:red" /> </h:panelGroup> </f:facet> <f:facet name="footer"> <h:panelGrid columns="3" width="100%" columnClasses="fake, width100 talign"> <h:outputText value="{previousMonthControl}" style="font-weight:bold;" /> <h:outputText value="{currentMonthControl}" style="font-weight:bold;" /> <h:outputText value="{nextMonthControl}" style="font-weight:bold;" /> </h:panelGrid> </f:facet> <h:panelGrid> <f:facet name="header"> <h:outputText value="{day}" /> </f:facet> </h:panelGrid> <rich:dataList var="record" value="{data.eachDayDataList}"> <h:outputText value="#{record.name}"></h:outputText> </rich:dataList> </rich:calendar>
And this is the CalendarDataModel used by the attibute dataModel="#{myDataModel}"> in the calendar tag:
public class myDataModel implements CalendarDataModel { @Override public CalendarDataModelItem[] getData(Date[] arg0) { if (arg0 == null) { throw new IllegalArgumentException( "Null date array argument for getData."); } CalendarDataModelItem[] items = new CalendarDataModelItem[arg0.length]; for (int i = 0; i < arg0.length; i++) { items = createDataModelItem(arg0 ); } return items; } private CalendarDataModelItem createDataModelItem(Date date) { CalendarDataModelItemImpl item = new CalendarDataModelItemImpl(); HashMap<String, Object> data = new HashMap<String, Object>(); FacesContext facesContext = FacesContext.getCurrentInstance(); ExternalContext externalContext = facesContext.getExternalContext(); DefinitionManager definitionManager = (DefinitionManager) externalContext .getSessionMap().get("definitionManager"); ListDataModel listDataModel = definitionManager.getScheduledJobList(date); // Here I'm retrieving the list for each day item.setEnabled(true); data.put("eachDayDataList", listDataModel); item.setData(data); return item; } @Override public Object getToolTip(Date arg0) { // TODO Auto-generated method stub return null; } public LavoriSchedulatiDataModel() { // TODO Auto-generated constructor stub } }
the last class involved :
public class CalendarDataModelItemImpl implements CalendarDataModelItem { HashMap<String, Object> data; int day; boolean enabled; Object toolTip; private String style; public Object getData() { // TODO Auto-generated method stub // return "9:00 Riunione<br/>10:00 Incontro Magistrato<br/>"; return data; } /** * Returns: day of the month on which data must be shown. */ public int getDay() { // TODO Auto-generated method stub return day; } public String getStyleClass() { return style; } public Object getToolTip() { return toolTip; } public boolean hasToolTip() { return toolTip != null; } public boolean isEnabled() { return enabled; } /** * * @param data * HashMap containing mappings like listaLavori ListaDataModel * containing the jobs */ public void setData(HashMap<String, Object> data) { this.data = data; } public void setDay(int day) { this.day = day; } public void setEnabled(boolean enabled) { this.enabled = enabled; } public void setToolTip(Object toolTip) { this.toolTip = toolTip; } public void setStyleClass(String style) { this.style = style; } }
But when I use the datamodel in this manner I get :java.lang.NoSuchMethodException: Property 'volatility' has no getter method.
So my question is:
can I put something else then strings (collections for example) into the HashMap used by the CalendarDataModel and the use them for uicomponents inside each day cell of the calendar ?