1

I am using liferay-ui datepicker. When my page loads the date is current date in the datepicker and data of the current date is loaded on the page. What I want to do is allow the user to view data such that when user selects any other date, data of the selected date is dispayed. How should I go about this? SHould I refresh the entire page? how? Or should I use ajax? how should i go about? if ajax is to be used how should i pass the data?

EDIT:

I will explain my problem in detail. I am using liferay:ui:date . I want user to select a date from it. Once the user selects date, I want to pass the date to custom-sql. I am calling the finder function in the same jsp as follows:

 List<Object[]> ObjdisplayAttListName = AttendanceLocalServiceUtil.findAttendance(currentdate);

I want to pass the user selected date in the above function. Right now what I am doing is only passing the current date in the above line of code. Iwant to pass the user selected date.

Seeya K
  • 1,221
  • 6
  • 27
  • 43
  • Even after your edit, I'm not sure what your problem is. Is it about transferring the date to the controller and back to jsp(ajax or not), Or using the resource phase ? Have you been able to pass a date to the controller before ? – yannicuLar Jun 05 '13 at 06:38
  • @yannicuLar: I used Ajax for this purpose. I passed the data which is selected by user to the serveResource and now I am retrieving the json object in the jsp.. I have aonther problem though. Right now I am displaying the data using: success : function(jsonArray) { alert(jsonArray); $('#displayDate').html(jsonArray[0]); } Is there a way i can store the json object and use it in liferay search container? – Seeya K Jun 05 '13 at 08:39

2 Answers2

0

Personally, I prefer working with liferay-ui:input-date. Just make sure to keep a Date or Calendar object in your Controller Class

    <portlet:actionURL var="setDate" name="setDate" >
        <portlet:param name="jspPage" value="/html/yourPage.jsp" />
    </portlet:actionURL>

<aui:form  action="<%= setDate%>" method="post" enctype="multipart/form-data" >
            <%
            Date date  = (Date)renderRequest.getAttribute("_a_date");// Get your Date from the controller
            Calendar cal = CalendarFactoryUtil.getCalendar();
            cal.setTime(new Date()); // create with current date if this form is presented for the 1st time
            if(Validator.isNotNull(date)){
                cal.setTime(date); // else use the Date you want to display

            } 
            %>



            <liferay-ui:input-date
                        yearRangeStart="1970"
                        yearRangeEnd="2100"  
                        formName="pickedDate"
                        dayParam="dd" 
                        monthParam="mm" 
                        yearParam="yy"
                        dayValue="<%= cal.get(Calendar.DATE) %>"
                        monthValue="<%= cal.get(Calendar.MONTH) %>"
                        yearValue="<%= cal.get(Calendar.YEAR) %>"
                        />
             <aui:button name="setDateBtn" value="Submit that date" type="submit"/>
        </aui:form>

Back to the controller..

    public void setDate(ActionRequest actionRequest,
        ActionResponse actionResponse) throws IOException, PortletException {


    UploadPortletRequest queryRequest = PortalUtil.getUploadPortletRequest(actionRequest);

    int dd  =  ParamUtil.getInteger(queryRequest, "dd");
    int mm  =  ParamUtil.getInteger(queryRequest, "mm");
    int yy  =  ParamUtil.getInteger(queryRequest, "yy");
   String date_format       = "yyyy/MM/dd";
   SimpleDateFormat sdf     = new SimpleDateFormat(date_format);
   GregorianCalendar gc     = new GregorianCalendar(yy, mm, dd);
   Date date = gc.getTime(); // Keep this Date and reload the page sending this Date in an actionRequest param

        actionRequest.setAttribute("_a_date", date );    
yannicuLar
  • 3,083
  • 3
  • 32
  • 50
  • Yeah I am using liferay-ui:input-date. So when the user selects a date, should I transfer it to the controller using ajax and then perform the required actions? – Seeya K Jun 05 '13 at 03:52
  • I have explained my problem in the ques in the EDIT – Seeya K Jun 05 '13 at 04:32
  • Let's start by saying that you don't need to use the serveResource (and AJAX), but you can create an action url that will load back again the same page, but with different params. Using the GenericPortlet, I try to avoid the ajax and serveResource calls – yannicuLar Jun 05 '13 at 14:29
  • If i understand correctly, (correct me if I am wrong :) ), I allow the user to select date and then load the page again.. is it correct? For that I will need to submit the form with submit button.. or is there a way where i select the date and the page refreshes? for this purpose i can think of ajax..i mean i have implemented it that way, but I am intersted in knowing your approach for curiosity and some extra ideas :) – Seeya K Jun 05 '13 at 14:47
  • See my Edit, hope it helps – yannicuLar Jun 06 '13 at 06:53
0

I think you should go with AJAX. Make ajax call when you select date using date-picker and get that date in your serveResource method. Based on your selected date fetch data and pass that data to your presentation layer in required format i.e JSON.

Collect data and display it. Thats it :)

Let me know if you have problem !!

Laxman Rana
  • 2,904
  • 3
  • 25
  • 37
  • Thanks for the reply. Is it the same like : http://stackoverflow.com/questions/16811854/display-data-on-jsp-based-on-selected-date-from-liferay-datepicker/16829664?noredirect=1#16829664 – Seeya K Jun 05 '13 at 04:41
  • yes.pass parameter in resource url to differentiate it from rest ajax calls and check that parameter in serveResource method and do the need full – Laxman Rana Jun 05 '13 at 04:43