Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Calendar DataSource binding

    Hi Folks,

    If any one has a working calendar with datasource attached can you please post the source code here ?

    I am using this class which extends RestDataSource to set the datasource for calendar but the event is not displaying on the calendar.

    The below line calls UserActivityXmlDs class(pasted below)
    UserActivityXmlDS usrActivityDs = UserActivityXmlDS.getInstance();
    Calendar calendar = new Calendar();
    calendar.setDataSource(usrActivityDs);

    UserActivityXmlDs class

    DataSource eventDs = new DataSource();
    DataSourceSequenceField eventIdField = new DataSourceSequenceField("eventId");
    eventIdField.setPrimaryKey(true);
    DataSourceTextField eventName = new DataSourceTextField("eventname", "Name");
    eventName.setRequired(true);
    DataSourceTextField jid = new DataSourceTextField("jid", "JID");
    jid.setPrimaryKey(true);
    jid.setRequired(true);

    DataSourceDateTimeField from = new DataSourceDateTimeField("startevent", "From");


    from.setPrimaryKey(true);
    from.setRequired(true);
    DataSourceDateTimeField to = new DataSourceDateTimeField("endevent", "To");
    to.setPrimaryKey(true);
    to.setRequired(true);
    DataSourceTextField description = new DataSourceTextField("description", "Description");
    description.setRequired(true);
    DataSourceTextField activityType = new DataSourceTextField("activitytype", "Activity Type");
    activityType.setRequired(true);

    eventDs.setFields(eventIdField,eventName,jid,from,to,description, activityType);
    eventDs.setClientOnly(true);

    OperationBinding fetch = new OperationBinding();
    fetch.setOperationType(DSOperationType.FETCH);
    fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
    setFetchDataURL("/test/controller/Activity");
    OperationBinding add = new OperationBinding();
    add.setOperationType(DSOperationType.ADD);
    add.setDataProtocol(DSProtocol.POSTMESSAGE);
    setAddDataURL("/test/controller/Activity/add");
    eventDs.setOperationBindings(fetch,add);

    I am able to see the HQL call and the Response on the above fetch URL, but the event is not visible on the Calendar, can someone point out if i am missing anything ?

    #2
    We've moved this to a new thread - please don't post in unrelated threads.

    The first troubleshooting steps are to look in the RPC tab of the Developer Console to see what data is actually arriving at the browser, and to manually call DataSource.fetchData() and inspect the returned records to see if they contain the expected field values.

    Comment


      #3
      log in developer console

      Originally posted by Isomorphic View Post
      We've moved this to a new thread - please don't post in unrelated threads.

      The first troubleshooting steps are to look in the RPC tab of the Developer Console to see what data is actually arriving at the browser, and to manually call DataSource.fetchData() and inspect the returned records to see if they contain the expected field values.
      Sorry for the inconvenience. Am a novice just started here.
      I was able to enable developer console and in the RPC i am able to see the request response. It is actually fetching the record from the preferred table.
      Should i create an addCalendarEvent for it to be displayed on the calendar ?
      Or just setting the dataSource(setDataSource) would/should work ?

      Comment


        #4
        The field-names your example uses are wrong - or rather, they are not the default expected field-names. Either correct them in the datasource or use the setters on Calendar to change what it expects them to be (setName/Description/StartDateField(), for instance)

        Comment


          #5
          Originally posted by Isomorphic View Post
          The field-names your example uses are wrong - or rather, they are not the default expected field-names. Either correct them in the datasource or use the setters on Calendar to change what it expects them to be (setName/Description/StartDateField(), for instance)
          I am sorry i couldn't comprehend. In the above example i am reading it from a table so,
          DataSourceTextField eventName = new DataSourceTextField("eventname", "Name");
          DataSourceDateTimeField from = new DataSourceDateTimeField("starttime", "From");
          means the column name is eventname, starttime. So i guess i can't change here right ?

          If i have to change at the place where i am setting the datasource for Calendar how do i do it ?
          What does the calendar expect to show them as events ?

          Comment


            #6
            So, again - use the setters on Calendar to change what it expects the field-names in the Data to be - events have a set of standard fields that your datasource is expected to provide - the default names for these are in the docs - in your case, you need to alter them to suit your datasource, so something like

            Code:
            calendar.setNameField("eventname");
            calendar.setStartDateField("startevent");
            calendar.setEndDateField("endevent");

            Comment


              #7
              Originally posted by Isomorphic View Post
              So, again - use the setters on Calendar to change what it expects the field-names in the Data to be - events have a set of standard fields that your datasource is expected to provide - the default names for these are in the docs - in your case, you need to alter them to suit your datasource, so something like

              Code:
              calendar.setNameField("eventname");
              calendar.setStartDateField("startevent");
              calendar.setEndDateField("endevent");
              I did as per your recommendation. Now i get a Object 2013-02-19T01:13:24+05:30 has no method 'getTime' error in chrome(latest 25.0.1364.97 m) in the developer console and in IE 9 developer console i get 12:14:41.165:TMR4:WARN:Log:Error:
              'Object doesn't support property or method 'getTime''
              in http://localhost:8080/test/com.mad.test.Test/sc/modules/ISC_Calendar.js
              at line 61

              My method to draw the calendar with events.
              public void drawActTracker(){

              UserActivityXmlDS usrActivityDs = UserActivityXmlDS.getInstance();

              DataSource eventDS = new DataSource();
              DataSourceSequenceField eventIdField = new DataSourceSequenceField("eventId");
              eventIdField.setPrimaryKey(true);

              DataSourceTextField nameField = new DataSourceTextField("name");
              DataSourceTextField descField = new DataSourceTextField("description");
              DataSourceDateTimeField startDateField = new DataSourceDateTimeField("startDate");
              DataSourceDateTimeField endDateField = new DataSourceDateTimeField("endDate");

              eventDS.setFields(eventIdField, nameField, descField, startDateField, endDateField);
              eventDS.setClientOnly(true);

              //specify the last field from the default fields so that subsequent fields come after the default fields

              TextItem descItem = new TextItem("description");

              SelectItem selItem = new SelectItem("selItem","Activity");
              selItem.setWidth(170);
              selItem.setValueMap("Case Management", "Problem Replication", "Analysis", "Installation", "Defect Creation", "Class Room Training - Provided", "Class Room Training-Atteneded", "OOH", "Customer Call", "Meeting with Product Team");
              TextItem caseId = new TextItem("caseid","Case Id");

              Calendar calendar = new Calendar();
              calendar.setDataSource(usrActivityDs);
              calendar.setAutoFetchData(true);

              calendar.setNameField("eventname");
              calendar.setStartDateField("starttime");
              calendar.setEndDateField("endtime");
              calendar.setDescriptionField("description");
              calendar.setNameField("caseid");
              calendar.setNameField("eventId");
              calendar.setNameField("selItem");

              calendar.setEventEditorFields(descItem, selItem, caseId);

              calendar.setTop(100);
              calendar.setHeight(600);
              calendar.setWidth(800);
              RootPanel.get().clear();
              RootPanel.get().add(calendar);

              SC.showConsole();

              }

              The constructor for datasource
              public UserActivityXmlDS(String activity) {

              setID(activity);
              setTitleField("Events");
              setDataFormat(DSDataFormat.XML);

              DataSource eventDs = new DataSource();
              DataSourceSequenceField eventIdField = new DataSourceSequenceField("eventId");
              eventIdField.setPrimaryKey(true);
              DataSourceTextField eventName = new DataSourceTextField("eventname", "Name");
              eventName.setRequired(true);
              DataSourceTextField jid = new DataSourceTextField("jid", "JID");
              jid.setPrimaryKey(true);
              jid.setRequired(true);

              DataSourceDateTimeField from = new DataSourceDateTimeField("starttime", "From");

              from.setPrimaryKey(true);
              from.setRequired(true);
              DataSourceDateTimeField to = new DataSourceDateTimeField("endtime", "To");
              to.setPrimaryKey(true);
              to.setRequired(true);
              DataSourceTextField description = new DataSourceTextField("description", "Description");
              description.setRequired(true);
              DataSourceTextField activityType = new DataSourceTextField("activitytype", "Activity Type");
              activityType.setRequired(true);

              eventDs.setFields(eventIdField,eventName,jid,from,to,description, activityType);
              eventDs.setClientOnly(true);

              OperationBinding fetch = new OperationBinding();
              fetch.setOperationType(DSOperationType.FETCH);
              fetch.setDataProtocol(DSProtocol.POSTMESSAGE);
              setFetchDataURL("/test/controller/Activity");
              OperationBinding add = new OperationBinding();
              add.setOperationType(DSOperationType.ADD);
              add.setDataProtocol(DSProtocol.POSTMESSAGE);
              setAddDataURL("/test/controller/Activity/add");
              eventDs.setOperationBindings(fetch,add);

              //UPDATE and REMOVE to be added
              }
              The RPC response i am getting from table
              <?xml version="1.0" encoding="UTF-8" standalone="yes"?><response>
              <data>
              <record>
              <activitytype>Case Management</activitytype><caseid>1011897</caseid>
              <description>Replicated case 1011897</description><endtime>2013-02-19T02:13:24+05:30</endtime><eventname>Test</eventname><jid>j1011089</jid><starttime>2013-02-19T01:13:24+05:30</starttime>
              </record></data></response>

              After drawing the calendar it keeps refreshing in chorme and hangs in IE.
              Am i missing anything ?

              Comment


                #8
                Hi Admin,

                Any update on this ?

                Comment


                  #9
                  This code is now quite confused - reading the CalendarEvent docs would clear a lot of this up for you.

                  You've introduced a second DataSource, for some reason - get rid of that one - you're also calling setNameField() no less than four times - it should only be called once, for whichever field in your DataSource actually represent the "name" field for your events.

                  After that, your DataSource specifies a primaryKey field, "eventId", but your RPC response does not include that value - that's required

                  Comment


                    #10
                    Hi Admin,

                    I had not created the column eventId. Thanks for that. I now have created it and able to see in the response.
                    I also changed the datasource names to default names like below, caseid, activitytype are custom fields which i want when i click edit event.

                    DataSource eventDs = new DataSource();
                    DataSourceSequenceField eventIdField = new DataSourceSequenceField("eventId");
                    eventIdField.setPrimaryKey(true);
                    DataSourceTextField eventName = new DataSourceTextField("name", "Name");
                    //eventName.setRequired(true);
                    DataSourceTextField jid = new DataSourceTextField("jid", "JID");
                    DataSourceDateTimeField from = new DataSourceDateTimeField("startDate", "From");
                    DataSourceDateTimeField to = new DataSourceDateTimeField("endDate", "To");
                    DataSourceTextField description = new DataSourceTextField("description", "Description");
                    DataSourceTextField activityType = new DataSourceTextField("activitytype", "Activity Type");

                    RPC response
                    <response>
                    <data>
                    <record>
                    <activitytype>Analysis</activitytype>
                    <caseid>1098709</caseid>
                    <description>Testing</description>
                    <endDate>2013-03-04T01:13:24+05:30</endDate>
                    <eventId>1</eventId>
                    <jid>j1011089</jid>
                    <name>Test</name>
                    <startDate>2013-03-04T01:13:24+05:30</startDate>
                    </record>
                    </data>
                    </response>

                    It reads the startDate value and gives the following error in developer console chrome(Version 25.0.1364.97 m)
                    15:54:20.239:XRP5:WARN:Log:TypeError: Object 2013-03-04T01:13:24+05:30 has no method 'getTime'
                    Stack from error.stack:
                    Calendar._getEventsInRange() @ com.mad.test.Test/sc/modules/ISC_Calendar.js:61:1766
                    DaySchedule.refreshEvents() @ com.mad.test.Test/sc/modules/ISC_Calendar.js:166:11
                    Calendar.refreshSelectedView() @ com.mad.test.Test/sc/modules/ISC_Calendar.js:35:647

                    In IE 9
                    15:55:20.711:TMR1:WARN:Log:Error:
                    'Object doesn't support property or method 'getTime''
                    in http://localhost:8080/test/com.mad.test.Test/sc/modules/ISC_Calendar.js
                    at line 61

                    Comment


                      #11
                      I use MySql as database. And the date looks like 2/28/2013 1:13:24 AM in Toad for me.
                      Is it related to date format ?

                      Comment


                        #12
                        Hi Admin,

                        I am still getting the Object has no method getTime error.

                        The source where DataSource is getting created.
                        DataSource eventDs = new DataSource();
                        DataSourceSequenceField eventIdField = new DataSourceSequenceField("eventId");
                        eventIdField.setPrimaryKey(true);
                        DataSourceTextField eventName = new DataSourceTextField("name", "Name");
                        eventName.setRequired(true);
                        DataSourceTextField jid = new DataSourceTextField("jid", "JID");
                        DataSourceDateTimeField from = new DataSourceDateTimeField("startDate", "From");
                        DataSourceDateTimeField to = new DataSourceDateTimeField("endDate", "To");
                        DataSourceTextField description = new DataSourceTextField("description", "Description");
                        DataSourceTextField activityType = new DataSourceTextField("activitytype", "Activity Type");

                        eventDs.setFields(eventIdField,eventName,jid,from,to,description,activityType);
                        eventDs.setClientOnly(true);

                        At the client side

                        Calendar calendar = new Calendar();
                        calendar.setDataSource(usrActivityDs);
                        calendar.setAutoFetchData(true);

                        The error in developer console

                        16:49:39.482:XRP6:WARN:Log:TypeError: Object 2013-03-11 01:13:24 has no method 'getTime'
                        Stack from error.stack:
                        Calendar._getEventsInRange() @ com.mad.test.Test/sc/modules/ISC_Calendar.js:61:1766
                        DaySchedule.refreshEvents() @ com.mad.test.Test/sc/modules/ISC_Calendar.js:166:11
                        Calendar.refreshSelectedView() @ com.mad.test.Test/sc/modules/ISC_Calendar.js:35:647
                        Calendar.dataChanged() @ com.mad.test.Test/sc/modules/ISC_Calendar.js:35:272
                        eval() @ eval at <anonymous> (http://localhost:8080/test/com.mad.test.Test/sc/modules/ISC_Core.js:35:76), <anonymous>:2:270
                        ResultSet._doneChangingData() @ com.mad.test.Test/sc/modules/ISC_DataBinding.js:1618:29
                        ResultSet._handleNewData() @ com.mad.test.Test/sc/modules/ISC_DataBinding.js:1545:6
                        isc.B.push.isc.A.fetchRemoteDataReply() @ com.mad.test.Test/sc/modules/ISC_DataBinding.js:1531:76
                        [c]Class.fireCallback() @ com.mad.test.Test/sc/modules/ISC_Core.js:228:49
                        [c]Class.fireCallback() @ com.mad.test.Test/sc/modules/ISC_Core.js:283:302

                        Comment


                          #13
                          Hi Admin,

                          Any update on this ?

                          Comment

                          Working...
                          X