Loading ...
Sorry, an error occurred while loading the content.

YUI Calendar : putting the selected date into the request

Expand Messages
  • thegridone
    Hello all ! I would like to use the YUI Calendar in a Struts / JSP - based webapp. I need to put the selected date into the request as parameters but can t
    Message 1 of 4 , May 6, 2007
    View Source
    • 0 Attachment
      Hello all !

      I would like to use the YUI Calendar in a Struts / JSP - based webapp.
      I need to put the selected date into the request as parameters but
      can't figure out how to achieve this. Any hints ?

      Regards,

      TheGridOne
    • alexshusta
      Hi TheGridOne, Assuming you ve got an HTML form element that you re trying to populate with the calendar s date values, you d want to call the calendar s
      Message 2 of 4 , May 7, 2007
      View Source
      • 0 Attachment
        Hi TheGridOne,

        Assuming you've got an HTML form element that you're trying to populate with the calendar's date values, you'd want to call the calendar's getSelectedDates()  method and push the returned values into your form before submitting it to the server. This can be done by using a form field that is populated by a function that listens for changes on your calendar.

        See the example at http://developer.yahoo.com/yui/examples/calendar/formtxt/1.html for a walkthrough of the process. Building on that example, on your server you'll need to look for the form element named "date1" when the page is submitted (or the values are passed via XHR). Sun has a good tutorial on JSP form handling at http://java.sun.com/products/jsp/html/jspbasics.fm2.html

        If you're using XHR you'll need to parse the values on the server and return something to the browser. I really enjoyed running through the examples in Foundations of AJAX  from Apress. Anyway, assuming a POST based form and a normal HttpServlet on the server you'd have something like:

        import java.io.*;
        import java.net.*;
        import javax.servlet.*;
        import javax.servlet.http.*;

        public class TheGridOneServlet extends HttpServlet {
            protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
                response.setContentType("text/xml");
                //Grab the date value as a string from the user's request
                String theDate = request.getParameter("date1");
                      
          //Any other processing you need to do on the string...

                //Build a response string
                String serverResponse = "Selected date: " + theDate + ".";
          
                //Write the response back to the browser
                PrintWriter out = response.getWriter();
                out.println(serverResponse);

                //Close the writer
                out.close();
            }
        }

        Hmmmm, I think that's all. Hope it's helpful,
        ~Alexander


        --- In ydn-javascript@yahoogroups.com, "thegridone" <thegridone@...> wrote:
        >
        > Hello all !
        >
        > I would like to use the YUI Calendar in a Struts / JSP - based webapp.
        > I need to put the selected date into the request as parameters but
        > can't figure out how to achieve this. Any hints ?
        >
        > Regards,
        >
        > TheGridOne
        >
      • thegridone
        ... Hello ! Yes, I guess that will be enough. And it looks easy too. Cheers ! TheGridOne
        Message 3 of 4 , May 7, 2007
        View Source
        • 0 Attachment
          > Hmmmm, I think that's all. Hope it's helpful,
          > ~Alexander
          >

          Hello !

          Yes, I guess that will be enough. And it looks easy too.

          Cheers !

          TheGridOne
        • thegridone
          Hello again ! OK, I did it. In fact, just populating a form field with the date and then sending it at the form submission was enough. I can (and actually) do
          Message 4 of 4 , May 9, 2007
          View Source
          • 0 Attachment
            Hello again !

            OK, I did it. In fact, just populating a form field with the date and
            then sending it at the form submission was enough.

            I can (and actually) do it like that, but in the beginning I tought,
            naivelly, that there should be a way to give my date as a request
            parameter for Struts to process it.

            But for my present need, it does not change anything.

            Thanks again !

            TheGridOne
          Your message has been successfully submitted and would be delivered to recipients shortly.