Struts2 JSON FullCalendar Integration

Having trouble fetching data from JSON for my Fullcalendar Jquery function. I've gone through the documentation but the example provided isn't clear to me.

Here is a snippet of my code:

<script>
$(document).ready(function() {
    $('#calendar').fullCalendar({
        theme: true,
        header: {
            left: 'prev,next today',
            center: 'title',
            right: 'month,agendaWeek'
        },
        editable: true,
        events: 'jsone.action'

    });

});

In my action, I'm currently returning only 3 test values:

@ParentPackage("json-default")
@Action(value = "jsone", results = {
@Result(type = "json", name = "success"),})
 public String title;
public String start;
public String end;

public String execute() {
    title="Event";
    start="2014-01-12T10:30:00-05:00";
    end="2014-01-12T12:30:00-05:00";
    System.out.println("execute");
    return SUCCESS;
}
//setters getters

When I call the "jsone" action, I receive this response, which seems to be in the correct format. Even when loading the calendar, there are no error messages and the jsone action executes correctly:

{"end":"2014-01-12T12:30:00-05:00","start":"2014-01-12T10:30:00-05:00","title":"event"}

I have also referenced a post on Stack Overflow by someone facing a similar problem:

Answer №1

After mastering the correct way to fetch data, I am eager to share the solution. Let's start with a simple example using just one event.

First, in the action (using annotations)

@ParentPackage("json-default")
@Action(value = "jsone", results = {
@Result(type = "json", name = "success"),})

Next, inside the action (Java class)

public String title;
public String start;
public String end;

public String execute() {
    title="Event";
    start="2014-06-12T10:30:00-05:00";
    end="2014-06-12T12:30:00-05:00";
    return SUCCESS;
}
//GETTERS SETTERS

This is how your events should be displayed in your JSP

events: function(start, end, timezone, callback) {
            $.ajax({
                url: 'jsone.action',
                dataType: 'json',
                data: {
                    start: start.unix(),
                    end: end.unix()
                },
                success: function(doc) {
                    var events = [];
                    events.push({
                        title: doc.title,
                        start: doc.start,
                        end: doc.end
                    });
                    callback(events);
                }
            });
        }

Using the START and END parameters allows you to retrieve a specific number of events rather than the entire list. The CALLBACK parameter returns an array of events, and in the success function(doc), the doc parameter represents the event fetched from the Action, giving you easy access to your action attributes ('title', 'start', 'end' in this example). Make sure to note which version of fullcalendar you are using, as the new BETA version (2.x) utilizes moment instead of the traditional Date format used in version 1.x. Ensure your date format matches this style:

start="2014-06-12T10:30:00-05:00";
    end="2014-06-12T12:30:00-05:00";

IMPORTANT: This example relies on "Struts2 JSON-Plugin," so @ParentPackage("json-default") is necessary to use it. You can integrate it using Maven with the following dependency:

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-json-plugin</artifactId>
    <version>2.3.16.3</version>
</dependency>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can JavaScript/jQuery be used to update LocalStorage Objects when editing a form?

Having trouble pinpointing an issue with my code. Despite making modifications, the values in localStorage are not updating as expected. Any suggestions on what may be causing this problem? Note: Changing const idx to const i resulted in only the final va ...

Printing a modified div element that was created using jQuery on an ASP.NET MVC webpage after the initial page has finished loading

In my view, there is a div that holds multiple tables generated based on the model. Each row in these tables contains fields that can be edited using TextBoxFor. Through jQuery, rows can be moved between tables and new tables can be created dynamically wit ...

Retrieve information from an HTML webpage using Node.js

Currently, I am attempting to extract text from an HTML page using Node.js. Here is the URL. I am specifically looking to retrieve the string 0e783d248f0e27408d3a6c043f44f337c54235ce. Although I have tried a certain method, unfortunately, no data seems to ...

use jquery to dynamically switch CSS class on navigation with animated arrows

Looking to update arrows to display a right arrow when the parent list item has the .active class. Here is the jQuery code: jQuery(function(){ initAccordion(); }); function initAccordion() { jQuery('.accordion').slideAccordion({ opener ...

Having a problem with the glitch effect in Javascript - the text is oversized. Any tips on how to resize

I found some interesting code on the internet that creates a glitch text effect. However, when I implement it, the text appears too large for my webpage. I'm struggling to adjust the size. Here is the current display of the text: too big This is how ...

I'm having trouble getting my jsonp to function properly. Can anyone help me troubleshoot?

I've been working on my website for the past two weeks, learning HTML, CSS, and a bit of JavaScript. However, I'm facing an issue with the following code that I can't seem to resolve: <head> <script src="http://ajax.googleapis.com/ ...

What is the process for encrypting and decrypting image files over the internet?

I'm currently developing a web application that requires loading images into a canvas object, followed by extensive manipulation. My goal is to conceal the original source image file (a jpeg) in such a way that users on the client side cannot access i ...

The GAS web application is experiencing issues with sorting dates correctly on the Javascript table

I have a food consumption log in a table that I need to sort. When I attempt to sort by the date column, I notice an issue with how it groups numbers together. For example, the sorting places all dates starting with 10 between 1 and 2, then all dates star ...

The hyperlink tag within the overlay div is unresponsive

I'm facing an issue with my overlay div (rb-overlay) that pops up when users click on a page option. The overlay takes up the entire page and includes a close button in the top right corner. However, I've noticed that the link at the end of the t ...

Comparing two JSON arrays with missing keys

I am working with two JsonArrays that contain data from an API. API 1 [ { "id":1, "value":270 }, { "id":2, "value":1432493 }, { "id":3, "value":63 }, { "id":5, "value":412 }, { ...

What are the steps to integrate dynamic data into chartjs?

Can you assist me in understanding how to dynamically populate Chartjs with data from a json file? Specifically, I am looking to dynamically fill the labels and data fields. Sample JSON File <<< [ { "EFICAZ_TAB_ITEM_ID":1, " ...

The functionality of a jQuery click event may cease to work once a loader has been incorporated into a

Since implementing a loading feature in my Vue template, I have encountered issues with jQuery not functioning properly: var element = document.getElementById('vue-project') if (element !== null) { var getData = await axios.get('./dat ...

AJAX request: No values are being returned by $_GET

After spending hours trying to figure this out... I've been working on using AJAX to grab values from a jQuery slider within an <input> tag. The AJAX request is not failing (see code below), and when I use console.log to check the variable I&ap ...

Struggling with Implementing jQuery for Triggering Multiple Functions on a Single Change Event?

I am currently developing jQuery functions that create dependencies between the css classes of different inputs in a web form. For example, when a specific input has a certain value, the "hide" class is removed from another input. One working example of t ...

Exploring the magic of Hover effects using CSS and JQuery

I am exploring ways to enhance the display of an element when hovering over it. I have implemented a button and my objective is for the first click to activate the hover effect, while the second click will reset it. However, I am facing an issue where the ...

What is the best way in jQuery to show each element of an array one at a time with a space in an input field?

I have a large array filled with strings that I want to display one by one in a text field, automatically concatenated with a space bar. Below is my code: <script> x = 0; function abc() { for (i = 0; i < words[x].length; i++) { ...

What is the best way to keep an image fixed at the bottom, but only when it's out of view in the section

There are two buttons (images with anchors) on the page: "Download from Google Play" and "Download from App Store". The request is to have them stick to the bottom, but once the footer is reached they should return to their original position. Here are two ...

Updating a property value within a JSON object: Adjusting attributes in a JSON data format

How can I modify a specific key's value in a JSON array like the following example: input = [{"201708":10,"201709": 12, "metric":"attritionManaged"},{"201708":10,"201709": 12, "metric":"attritionUnManaged"},{"201708":10,"201709": 12, "metric":"EHC"}] ...

What is the best way to generate a "JSON diff" that can be displayed in the JavaScript console?

When working on my Angular project, I frequently encounter the need to compare JSONs in my Karma/Jasmine tests. It would be incredibly useful to have a console output showing what has been added and removed when comparing two structures. For example, ident ...

The operation of 'val' is not supported by HTMLInputElement

While working with a table row, I am iterating through each cell. Inside every cell lies a text box containing some value that I need to store in an array. function dothing() { var tds = $('#'+selected+' td'); var submi ...