jquery calendar event integrate with java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • najmi
    New Member
    • Sep 2007
    • 46

    jquery calendar event integrate with java

    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

    Code:
    <?php
    
    	$year = date('Y');
    	$month = date('m');
    
    	echo json_encode(array(
    	
    		array(
    			'id' => 111,
    			'title' => "Event1",
    			'start' => "$year-$month-10",
    			'url' => "http://yahoo.com/"
    		)
    	
    	));
    
    ?>
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    Use SimpleDateForma tter and GregorianCalend ar class in your JSP file to convert the date you got from javascript into your database format.

    Comment

    • najmi
      New Member
      • Sep 2007
      • 46

      #3
      jquery calendar event integrate with java

      thank you for your time..my problem actually is to load the event from the database to the jquery calendar..my database is mysql

      Comment

      • chaarmann
        Recognized Expert Contributor
        • Nov 2007
        • 785

        #4
        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 GregorianCalend er and SimpleDateForma tter, 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 SimpledateForma tter) --> GregorianCalend ar Object --> (via SimpleDateForma tter) --> String

        (Remark:As an equivalent to the PHP-code above you could also use the Date object instead of GregorianCalend ar, but that's deprecated.)

        Comment

        • najmi
          New Member
          • Sep 2007
          • 46

          #5
          thank chaarmann for your explaination..m y 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(arr ay(
          #
          # array(
          # 'id' => 111,
          # 'title' => "Event1",
          # 'start' => "$year-$month-10",
          # 'url' => "http://yahoo.com/"
          # )
          #
          # ));

          Comment

          • chaarmann
            Recognized Expert Contributor
            • Nov 2007
            • 785

            #6
            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.or g/wiki/JSON"
            and there is written in the middle of the page as an example:
            Code:
            {
                 "firstName": "John",
                 "lastName": "Smith",
                 "address": {
                     "streetAddress": "21 2nd Street",
                     "city": "New York",
                     "state": "NY",
                     "postalCode": 10021
                 },
            ...
            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
            Code:
            array(
             'id' => 111,
             'title' => "Event1",
            ...
            into
            Code:
            {
             "id" : 111,
             "title" : "Event1",
            ...
            That means you must put that into a String and pass it to javascript:
            Code:
            String json="{\"id\":111, \"title\":\"Event1\", ...";
            To fill in the values from database for "$year" and "$month", just use the SimpledateForma tter 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.

            Comment

            • najmi
              New Member
              • Sep 2007
              • 46

              #7
              thank you very much..i feel better right now

              Comment

              Working...