473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

jquery calendar event integrate with java

46
hai..

i have used jquery fullcalendar for my application and i have one problem that is how to display the event from the database.i have found the sample given in php but i want it in jsp.can anyone help me to translate this short code to jsp or java.here is the code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.     $year = date('Y');
  4.     $month = date('m');
  5.  
  6.     echo json_encode(array(
  7.  
  8.         array(
  9.             'id' => 111,
  10.             'title' => "Event1",
  11.             'start' => "$year-$month-10",
  12.             'url' => "http://yahoo.com/"
  13.         )
  14.  
  15.     ));
  16.  
  17. ?>
Dec 16 '09 #1

✓ answered by chaarmann

It seems your major problem is that you don't understand the JSON format.
I didn't understand, too.
But I googled "JSON" and one of the top links is "http://en.wikipedia.org/wiki/JSON"
and there is written in the middle of the page as an example:
Expand|Select|Wrap|Line Numbers
  1. {
  2.      "firstName": "John",
  3.      "lastName": "Smith",
  4.      "address": {
  5.          "streetAddress": "21 2nd Street",
  6.          "city": "New York",
  7.          "state": "NY",
  8.          "postalCode": 10021
  9.      },
  10. ...
  11.  
So looking at that it seems pretty easy:
Array is a curly bracket "{" instead of "array(" in PHP,
keys and values are separated by ":" instead of "=>".

So you must convert your code
Expand|Select|Wrap|Line Numbers
  1. array(
  2.  'id' => 111,
  3.  'title' => "Event1",
  4. ...
  5.  
into
Expand|Select|Wrap|Line Numbers
  1. {
  2.  "id" : 111,
  3.  "title" : "Event1",
  4. ...
  5.  
That means you must put that into a String and pass it to javascript:
Expand|Select|Wrap|Line Numbers
  1. String json="{\"id\":111, \"title\":\"Event1\", ...";
  2.  
To fill in the values from database for "$year" and "$month", just use the SimpledateFormatter as I described before. I hope you understand now better that it's just a simple string to string conversion, from one format to another.

6 4734
chaarmann
785 Expert 512MB
Use SimpleDateFormatter and GregorianCalendar class in your JSP file to convert the date you got from javascript into your database format.
Dec 18 '09 #2
najmi
46
thank you for your time..my problem actually is to load the event from the database to the jquery calendar..my database is mysql
Dec 21 '09 #3
chaarmann
785 Expert 512MB
It's the same way. It's just the problem of converting one string into another.
Whether from database to calender format or from calender to database format, it doesn't matter.

When you got your date from the database via jdbc-SQL, it has a special format (by default yyyy-mm-dd in mySql, unless you have saved it in some other format or converted it by SQL directly). Your task is to convert this String into an another String that your javascript calender needs (json format).

You could do it manually with string manipulations, like splitting at delimiters and home-made parsing. But this would lead to a complicated and error-prone function. So use GregorianCalender and SimpleDateFormatter, they are your friends and will ease this job a lot.

So instead of converting
String --> (via home-made function) --> String,
you convert
String -->(via SimpledateFormatter) --> GregorianCalendar Object --> (via SimpleDateFormatter) --> String

(Remark:As an equivalent to the PHP-code above you could also use the Date object instead of GregorianCalendar, but that's deprecated.)
Dec 21 '09 #4
najmi
46
thank chaarmann for your explaination..my problem is not how to convert the date but how to encode json in java especially in jsp..as you can see in the code example,it encode the json in php..my major problem is here

# echo json_encode(array(
#
# array(
# 'id' => 111,
# 'title' => "Event1",
# 'start' => "$year-$month-10",
# 'url' => "http://yahoo.com/"
# )
#
# ));
Dec 21 '09 #5
chaarmann
785 Expert 512MB
It seems your major problem is that you don't understand the JSON format.
I didn't understand, too.
But I googled "JSON" and one of the top links is "http://en.wikipedia.org/wiki/JSON"
and there is written in the middle of the page as an example:
Expand|Select|Wrap|Line Numbers
  1. {
  2.      "firstName": "John",
  3.      "lastName": "Smith",
  4.      "address": {
  5.          "streetAddress": "21 2nd Street",
  6.          "city": "New York",
  7.          "state": "NY",
  8.          "postalCode": 10021
  9.      },
  10. ...
  11.  
So looking at that it seems pretty easy:
Array is a curly bracket "{" instead of "array(" in PHP,
keys and values are separated by ":" instead of "=>".

So you must convert your code
Expand|Select|Wrap|Line Numbers
  1. array(
  2.  'id' => 111,
  3.  'title' => "Event1",
  4. ...
  5.  
into
Expand|Select|Wrap|Line Numbers
  1. {
  2.  "id" : 111,
  3.  "title" : "Event1",
  4. ...
  5.  
That means you must put that into a String and pass it to javascript:
Expand|Select|Wrap|Line Numbers
  1. String json="{\"id\":111, \"title\":\"Event1\", ...";
  2.  
To fill in the values from database for "$year" and "$month", just use the SimpledateFormatter as I described before. I hope you understand now better that it's just a simple string to string conversion, from one format to another.
Dec 21 '09 #6
najmi
46
thank you very much..i feel better right now
Dec 22 '09 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

19
by: skyblue | last post by:
//can somebody help me with this please. i need to create a //calendar on the frame. i got the frame but the calendar is not //woking. import jpb.*; import java.awt.*; import...
0
by: shapper | last post by:
Hello, I want to use JQuery on my ASP.NET projects. Consider the first example on the following page: http://p.sohei.org/stuff/jquery/tablehover/demo/demo.html I am trying to create a...
1
by: ITistic | last post by:
I am in the planning stages of a new web application. One of the requirements for this application is to provide a Google Calendar type interface to show important events which will be pulled from...
1
by: DaNieL | last post by:
Hi there! I'm in needing to use GCaledar in one web-application that i've created: 1. Users should set many calendars as they would; 2. The calendars are shown in the pages by the iframe (the...
1
by: mikeh3275 | last post by:
I'm new to developing in jQuery, so I'm probably doing this wrong. I'm loading a form into a modal dialog box and I'm trying to assign a click event to the button in the form, but I can't seem to...
83
by: liketofindoutwhy | last post by:
I am learning more and more Prototype and Script.aculo.us and got the Bungee book... and wonder if I should get some books on jQuery (jQuery in Action, and Learning jQuery) and start learning about...
3
by: NetWave | last post by:
Hi, For my next project I'm going to need Ajax, so I'm in about to read some books on ASP.NET Ajax. While reading Rick Strahl's blog I stumbled upon jQuery. I've been to the website and seen...
2
by: maheswaran | last post by:
Hi all, pls see the urls http://capdigisoft.net/testscript/index1.php http://capdigisoft.net/testscript/index2.php for the above url i have used prototype.js (for index1.php) and Jquery...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.