3 Replies Latest reply on Aug 6, 2009 11:54 PM by Steve Hunter

    Creating a scheduler using rich:calendar

    Riccardo Serafin Newbie

      Hello,


      we are trying to create a schedule application with a monthly view of appointments and we were thinking at using the calendar component. For this, we have created an appropriate data model and in the CalendarDataModelItem getData() method of each day we return an array of appointments (that are all JSON serializable).


      Everything works fine if we access the data in the xtml page using something like {data[0].title}. Our problem is that we need to display an unknown number of items for each day, so we'd like to be able to iterate over this collection and for each appointment define an xhtml snippet with this structure. We have tried to use the a4j:repeat for doing this but it doesn't work.


      Our guess is that rich:calendar is performing some kind of text substitution when it is parsing it's content (the custom facet) and that the data variable is not accessible as a normal element iterator (like the var in data table). The fact that we must not use #{} to access it but rather just {} was the clue.


      So, the question is how can we iterate over this array in the xhtml?


      Moreover, we were trying to use the a4j:support on element we create within the calendar, but it doesn't seem to work. Any idea why?


      More in general, has anyone ever used the calendar component to create a schedule application? If so, how did you do that?


      Moreover, thinking at a generic schedule application, the calendar component does not have a day or week view. If someone has developed a schedule application with richfaces, how did you do that? Which component have you used? (We are looking for something like the tomahawk schedule component, but that could be used with richfaces and easily ajaxed).


      Thanks a lot,
      Riccardo.


      PS: the following is the snippet of code we were trying to use:


      <rich:calendar id="calendar"
                  popup="false" showApplyButton="false" 
                  cellWidth="100px" cellHeight="100px" 
                  boundaryDatesMode="none" showWeeksBar="false" 
                  dataModel="#{calendarDataModel}" >
                  
                 <a4j:repeat value="{data}" var="app"/>
                  <a4j:outputPanel layout="block" id="cell"  style="height: 100%;">
                      <s:div>
                          <h:outputText value="#{app.time}" style="align:center"/>
                          <h:outputText value="#{app.title}"/>
                           <a4j:support event="onclick" action="#{calendarController.select(app)}" reRender="calendar"/>
                      </s:div>
                  </a4j:outputPanel>
                </a4j:repeat>
              </rich:calendar>
      




      While this is the snippet from the CalendarDataModelItem implementation:


      public Object getData() {
                  Appointment[] apps = new Appointment[] { new Appointment("16:00","Test"), new Appointment("18:00","Test2") };
                  return apps;
              }
      



      PPS: Apologies for cross-posting.

        • 1. Re: Creating a scheduler using rich:calendar
          wu haixing Newbie

          I found the items each day first,and then iterate itmes to create the item data.
          just like


          createDataModelItem(List<Item> itemsOnDate,Date currentDate)



          I compose what I want to display on the calendar view in the method.

          • 2. Re: Creating a scheduler using rich:calendar
            Mason Harding Newbie

            Did you ever find a solution to this problem?  I have tried having multiple CalendarDataModelItem's per day, but they would only show up 1 per calendar day.  Having something like...






                protected CalendarDataModelItem createDataModelItem(Date date) {
                    CalendarDataModelItemImpl item = new CalendarDataModelItemImpl();
                    ArrayList datas = new ArrayList();
                    Map data = new HashMap();
                    data.put("shortDescription", "Nothing planned1");
                    data.put("description", "1");
                    Map data2 = new HashMap();
                    data2.put("shortDescription", "Nothing planned2");
                    data2.put("description", "2");
                    datas.add(data);
                    datas.add(data2);
                    Calendar c = Calendar.getInstance();
                    c.setTime(date);
                    item.setDay(c.get(Calendar.DAY_OF_MONTH));
                    item.setEnabled(true);
                    item.setStyleClass("rel-hol");
                    item.setData(datas);
                    return item;
                }





            works if I access the items like...



                                        <h:outputText value="{data[0].shortDescription.escapeHTML()}"/>
                                        <h:outputText value="{data[0].description.escapeHTML()}"/>
                                        <h:outputText value="{data[1].shortDescription.escapeHTML()}"/>
                                        <h:outputText value="{data[1].description.escapeHTML()}"/>


            but not if I use a repeat, as {data[0]} is not EL, and seems to be interpreted by the rich:calendar. 


            How can one have multiple entires per day in a rich:calendar?


            • 3. Re: Creating a scheduler using rich:calendar
              Steve Hunter Newbie

              Bad news, doesn't look like you can iterate items in a Richfaces Calendars.


              See JBoss Richfaces Users forum entry


              JIRA RF-7245