making a Calendar object a String so it can be passed to javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • basm101
    New Member
    • Sep 2007
    • 12

    #1

    making a Calendar object a String so it can be passed to javascript

    Hi,

    I have a java Calendar object, observationDate .

    Code:
    java.util.Calendar observationDate=subsequentSub.getObservationDate();
    I want to trigger a javascript function upon clicking a radio button
    on a form that checks if the calendar data is in January or February
    and triggers a popup if it is.

    How can I make the java object into a String so I can pass it (in my jsp)
    to javascript ? Or even better, see if my Calendar is the right month
    range using java and pass a yes or no value to the javascript accordingly ?

    I am fairly new to java and am quickly finding that java and javascript do not
    always mix together very well...

    thanks
    basm101
  • BigDaddyLH
    Recognized Expert Top Contributor
    • Dec 2007
    • 1216

    #2
    First of all, I agree strongly with the idea of keeping the logic in Java and just passing true or false to an ECMAScript function. Or only call the function at all when you want the window to pop up. Why? This will make it easier to do unit testing on your code because it's easier to test in Java. (Er, you are doing unit testing, right?)

    As for Calendar methods to do what you want, it sounds like you haven't been looking very hard in the API: http://java.sun.com/javase/6/docs/ap.../Calendar.html

    Comment

    Working...