0
  <script type="text/javascript">
        $(function() {

            var date = new Date();
            var d = date.getDate(),
            m = date.getMonth(),
            y = date.getFullYear();
            $('#calendar').fullCalendar({
                header: {
                   left: 'prev,next today',
                   center: 'title',
                   right: 'month,agendaWeek,agendaDay'
                },
                defaultDate: '2014-09-12',
                editable: true,
                eventLimit: true, 
                events: '/myCal'  
            });
        });
    </script>


         my json feed : 
            {             
                "allDay":"false",
                "end":"2014-09-03",
                "id":"1",
                "start":"2014-09-02",
                "title":"EventXYZ" 
            }



           <script>                  
                events: 
                [
                   {
                      "allDay":"false",
                      "end":"2014-09-03",
                      "id":"1",
                      "start":"2014-09-02",
                      "title":"EventXYZ"
                   }
               ]
         </script>

if i use the above code then it shows me on my calendar page.

i am working with struts2 and an action is returning json feed which I want to display in my calendar.

calendar action class has following content with getter and setter.

public CalendarAction() {
}
    public String title;
    public String start;
    public String end;
    public String id;
    public String allDay;

public String execute() {
     title = "EventXYZ";
     start = "2014-09-02";
     end = "2014-09-03";
     id = "1";
     allDay = "false";
     return SUCCESS;
}

I am able to generate json format. but unable to add json data in calendar plugin. confused that how to pass action in script or any url or ajax call.

Ganesh Gaxy
  • 657
  • 5
  • 11
lax
  • 11
  • 6
  • If you want to return JSON from your Action, you need to use and study [Struts2 JSON plugin](http://stackoverflow.com/a/17149414/1654265); then return a `json` or a `stream` result. P.S: Remember to avoid public Action attributes, make them private and use Getters / Setters; – Andrea Ligios Sep 02 '14 at 09:06
  • Everything was correct except this struts.xml – lax Sep 02 '14 at 09:20

1 Answers1

0

Everything was correct except this struts.xml i was returning a list and the name of list was getting appended to the json ... hence a json array was not visible for parsing

I made following changes :

      <script type="text/javascript">

        $(function() { 

            var date = new Date();

            var d = date.getDate(),

                    m = date.getMonth(),

                    y = date.getFullYear();
                    $('#calendar').fullCalendar({
                     header: {
                     left: 'prev,next today',
                     center: 'title',
                     right: 'month,agendaWeek,agendaDay'
                },
                     defaultDate: '2014-09-12',
                     editable: true,
                     eventLimit: true, // allow "more" link when too many events


             events:"/HMSPro/myCal"
});

        });
    </script>

struts.xml file :

      <action name="myCal" class="pack1.CalendarAction"> 
      <result name="success" type="json">
      <param name="contentType">application/json</param>
      <param name="root">
            calList 
        </param>

       </result>
      </action>

calList is the name of bean-List that was returning its attributes : like start , end , time , allevents etc.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
lax
  • 11
  • 6