Forums

Home » Alloy UI » English

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
MANOVINAYAK AYYAPPAN
Date Picker
June 28, 2011 8:46 PM
Answer

MANOVINAYAK AYYAPPAN

Rank: Regular Member

Posts: 132

Join Date: June 13, 2011

Recent Posts

Hi All,

I am new to Liferay. And I am currently working on implementing a Date Picker for my project.

I tried 2 ways, they are as follows:
First Method:
In JSP Page:
<%
Enewsletter enewsletter = (Enewsletter) request.getAttribute("enewsletter");
if (enewsletter == null) {
enewsletter = new EnewsletterImpl();
Calendar now = CalendarFactoryUtil.getCalendar();
now.set(2011, 1, 1);
enewsletter.setPublishDate(now.getTime());
enewsletter.setUnPublishDate(now.getTime());
}
%>

<% Calendar unpubDate = CalendarFactoryUtil.getCalendar();
unpubDate.setTime(enewsletter.getUnPublishDate());
%>
<p> <aui:input model="<%=Enewsletter.class %>" bean="<%=enewsletter %>" label="UnPublish Date" name="unPublishDate" value="<%=unpubDate %>"></aui:input> </p>

In the Portlet Class:

int unPublishDateMonth = ParamUtil.getInteger(actionRequest,"unPublishDateMonth");
int unPublishDateDay = ParamUtil.getInteger(actionRequest,"unPublishDateDay");
int unPublishDateYear = ParamUtil.getInteger(actionRequest,"unPublishDateYear");

I checked the above the values in the portlet class were all Zero, I could not retrieve the Day, month and year

Second Method:
<liferay-ui:input-date yearValue="<%= year %>"
dayValue="<%= day %>"
monthValue="<%= month %>"
yearRangeStart="1900"
yearRangeEnd="2090"
dayParam="UnPubDay"
monthParam="UnPubMonth"
yearParam="UnPubYear"/>
For this method I do not know how to get the date values in the portlet class.

Please kindly advice, I think I am missing something here.

Regards,
Mano
MANOVINAYAK AYYAPPAN
RE: Date Picker
June 28, 2011 9:19 PM
Answer

MANOVINAYAK AYYAPPAN

Rank: Regular Member

Posts: 132

Join Date: June 13, 2011

Recent Posts

If you an Sample Date Picker Implementation. Please share , I can refer to it and learn.

Regards,
Mano
MANOVINAYAK AYYAPPAN
RE: Date Picker
June 30, 2011 11:18 PM
Answer

MANOVINAYAK AYYAPPAN

Rank: Regular Member

Posts: 132

Join Date: June 13, 2011

Recent Posts

Hi All,

I got my problem resolved :-) !!!

it was due to enctype="multipart/form-data" in the form that was cuasing the date picker values not appearing in the actionRequest.

Regards,
mano
Artur Pirozhkov
RE: Date Picker
July 27, 2011 11:16 PM
Answer

Artur Pirozhkov

Rank: New Member

Posts: 9

Join Date: May 17, 2011

Recent Posts

Hi mano

I am interested in the same question

how did you imported the class Enewsletter, which library is it from?
MANOVINAYAK AYYAPPAN
RE: Date Picker
August 4, 2011 3:36 AM
Answer

MANOVINAYAK AYYAPPAN

Rank: Regular Member

Posts: 132

Join Date: June 13, 2011

Recent Posts

Hi Artur,

The Enesletter class is my custom entity Object and not a liferay standard library emoticon.


Regards,
Mano
Alberto Gonzalez
RE: Date Picker
November 8, 2011 7:31 AM
Answer

Alberto Gonzalez

Rank: New Member

Posts: 6

Join Date: November 3, 2011

Recent Posts

You receive them like params, isn´t it?
Yamini T
RE: Date Picker
November 16, 2011 10:31 PM
Answer

Yamini T

Rank: Junior Member

Posts: 32

Join Date: July 26, 2011

Recent Posts

Hi Friends, I am not getting the calendar.
Can you please share the code to implement a aui datepicker in custom portlet.

Thanks & Regards
Jhansi Rani P.
MANOVINAYAK AYYAPPAN
RE: Date Picker
November 16, 2011 11:24 PM
Answer

MANOVINAYAK AYYAPPAN

Rank: Regular Member

Posts: 132

Join Date: June 13, 2011

Recent Posts

Hi All,

Below is the Sample Code Which I implemented. There could be better Implementation than this.

 1// In The JSP Page
 2
 3<%
 4   Calendar cal = Calendar.getInstance(); 
 5%>
 6
 7<table>
 8             <tr>
 9            <td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">From Date</td>
10            <td align="left" style="padding-left:23px;">
11            <aui:fieldset>
12                <aui:field-wrapper>
13                    <liferay-ui:input-date
14                      dayParam="fromDateDay"
15                      dayValue="<%= cal.get(Calendar.DATE) %>"
16                      disabled="<%= false %>"
17                      firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>"
18                      monthParam="fromDateMonth"
19                      monthValue="<%= cal.get(Calendar.MONTH) %>"
20                      yearParam="fromDateYear"
21                      yearValue="<%= cal.get(Calendar.YEAR) %>"
22                      yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>"
23                      yearRangeEnd="<%= cal.get(Calendar.YEAR) + 60 %>"
24                    />
25                </aui:field-wrapper>
26            </aui:fieldset>
27            </td>
28            </tr>
29        </table>            
30        </tr>
31        <tr>
32            <table>
33            <tr>
34            <td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">To Date</td>
35            <td align="left" class="greyText" style="padding-left:36px;">
36            <aui:fieldset>
37                <aui:field-wrapper>
38                    <liferay-ui:input-date
39                      dayParam="toDateDay"
40                      dayValue="<%= cal.get(Calendar.DATE) %>"
41                      disabled="<%= false %>"
42                      firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>"
43                      monthParam="toDateMonth"
44                      monthValue="<%= cal.get(Calendar.MONTH) %>"
45                      yearParam="toDateYear"
46                      yearValue="<%= cal.get(Calendar.YEAR) %>"
47                      yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>"
48                      yearRangeEnd="<%=cal.get(Calendar.YEAR) + 60 %>"
49                    />
50                </aui:field-wrapper>
51            </aui:fieldset></td>
52            </tr>
53            </table>
54        </tr>
55
56
57
58//Inside Portlet Class:
59
60                // Getting the Date Range
61                    fromDay = ParamUtil.getInteger(actionRequest, "fromDateDay");
62                    fromMonth = ParamUtil.getInteger(actionRequest, "fromDateMonth");
63                    fromYear = ParamUtil.getInteger(actionRequest, "fromDateYear");
64                    toDay = ParamUtil.getInteger(actionRequest, "toDateDay");
65                    toMonth = ParamUtil.getInteger(actionRequest, "toDateMonth");
66                    toYear = ParamUtil.getInteger(actionRequest, "toDateYear");
67
68        // Get Date Range
69                    fromDate = getDate(fromMonth, fromDay, fromYear);
70                    toDate = getDate(toMonth, toDay, toYear);
71
72
73        //To get the Actual Date Make a Call to the Method Below:
74
75        public static Date getDate(int month, int day, int year){
76               
77                Date finalDate = null;
78               
79                try {
80                    finalDate = PortalUtil.getDate(month, day, year, new PortalException());
81                } catch (PortalException e) {
82                    // TODO Auto-generated catch block
83                    e.printStackTrace();
84                    return finalDate = null;
85                }
86               
87                return finalDate;
88            }


This is my Implementation, there could be better ways of doing it.


Regards,
Mano
Yamini T
RE: Date Picker
November 17, 2011 4:12 AM
Answer

Yamini T

Rank: Junior Member

Posts: 32

Join Date: July 26, 2011

Recent Posts

Thank you for quick reply.

Regards
Jhansi
Sunil G
RE: Date Picker
January 2, 2012 1:52 AM
Answer

Sunil G

Rank: New Member

Posts: 6

Join Date: December 8, 2011

Recent Posts

Your Date picker code was very helpful

Thanks.
MANOVINAYAK AYYAPPAN
RE: Date Picker
January 3, 2012 5:53 PM
Answer

MANOVINAYAK AYYAPPAN

Rank: Regular Member

Posts: 132

Join Date: June 13, 2011

Recent Posts

sunil G:
Your Date picker code was very helpful

Thanks.

You are welcomeemoticon

Regards,
Mano
Rufus Pwner
RE: Date Picker
January 4, 2012 8:40 AM
Answer

Rufus Pwner

Rank: New Member

Posts: 3

Join Date: January 4, 2012

Recent Posts

Hi, thanks for your code snippet. It is really helpful, but the getInteger methods in the portlet all return "0".

This is my JSP Code, which is quite the same as your
 1
 2<table>
 3             <tr>
 4            <td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">From Date</td>
 5            <td align="left" style="padding-left:23px;">
 6            <aui:fieldset>
 7                <aui:field-wrapper>
 8                    <liferay-ui:input-date
 9                      dayParam="fromDateDay"
10                      dayValue="<%= cal.get(Calendar.DATE) %>"
11                      disabled="<%= false %>"
12                      firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>"
13                      monthParam="fromDateMonth"
14                      monthValue="<%= cal.get(Calendar.MONTH) %>"
15                      yearParam="fromDateYear"
16                      yearValue="<%= cal.get(Calendar.YEAR) %>"
17                      yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>"
18                      yearRangeEnd="<%= cal.get(Calendar.YEAR) + 60 %>"
19                    />
20                </aui:field-wrapper>
21            </aui:fieldset>
22            </td>
23            </tr>
24        </table>            
25            <table>
26            <tr>
27            <td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">To Date</td>
28            <td align="left" class="greyText" style="padding-left:36px;">
29            <aui:fieldset>
30                <aui:field-wrapper>
31                    <liferay-ui:input-date
32                      dayParam="toDateDay"
33                      dayValue="<%= cal.get(Calendar.DATE) %>"
34                      disabled="<%= false %>"
35                      firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>"
36                      monthParam="toDateMonth"
37                      monthValue="<%= cal.get(Calendar.MONTH) %>"
38                      yearParam="toDateYear"
39                      yearValue="<%= cal.get(Calendar.YEAR) %>"
40                      yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>"
41                      yearRangeEnd="<%=cal.get(Calendar.YEAR) + 60 %>"
42                    />
43                </aui:field-wrapper>
44            </aui:fieldset></td>
45            </tr>
46            </table>

Portlet Code:
 1
 2package com.test;
 3
 4import java.io.IOException;
 5import java.util.Date;
 6
 7import javax.portlet.ActionRequest;
 8import javax.portlet.ActionResponse;
 9import javax.portlet.PortletException;
10
11import com.liferay.portal.kernel.exception.PortalException;
12import com.liferay.portal.kernel.util.ParamUtil;
13import com.liferay.portal.util.PortalUtil;
14import com.liferay.util.bridges.mvc.MVCPortlet;
15
16public class VeranstaltungsPortlet extends MVCPortlet {
17
18    public void machen(ActionRequest actionRequest, ActionResponse actionResponse)
19    throws IOException, PortletException{
20          // Getting the Date Range
21      int  fromDay = ParamUtil.getInteger(actionRequest, "fromDateDay");
22      int  fromMonth = ParamUtil.getInteger(actionRequest, "fromDateMonth");
23        int fromYear = ParamUtil.getInteger(actionRequest, "fromDateYear");
24     int   toDay = ParamUtil.getInteger(actionRequest, "toDateDay");
25        int toMonth = ParamUtil.getInteger(actionRequest, "toDateMonth");
26        int toYear = ParamUtil.getInteger(actionRequest, "toDateYear");
27        System.out.println("FromDay: "+fromDay+" FromMonth: "+fromMonth+" FromYear: "+fromYear);
28        System.out.println("FromDay: "+toDay+" FromMonth: "+toMonth+" FromYear: "+toYear);
29// Get Date Range
30        Date fromDate = getDate(fromMonth, fromDay, fromYear);
31        Date toDate = getDate(toMonth, toDay, toYear);
32    }
33
34//To get the Actual Date Make a Call to the Method Below:
35
36public static Date getDate(int month, int day, int year){
37   
38    Date finalDate = null;
39   
40   
41        try {
42            finalDate = PortalUtil.getDate(month, day, year, new PortalException());
43        } catch (PortalException e) {
44            // TODO Auto-generated catch block
45            e.printStackTrace();
46        }
47   
48   
49    return finalDate;
50}
51    }


Do you have any idea why?
I am using LR 6.1 RC.
MANOVINAYAK AYYAPPAN
RE: Date Picker
January 5, 2012 5:33 PM
Answer

MANOVINAYAK AYYAPPAN

Rank: Regular Member

Posts: 132

Join Date: June 13, 2011

Recent Posts

Hi Rufus,

I believe you have included the below Calendar Object Instance in your code.
1
2<%
3   Calendar cal = Calendar.getInstance();
4%>


And by any chance does this Date Picker falls within a form which has a enctype="multipart/form-data".

Is it Something as below ?

 1<aui:form  method="post" name="fm" enctype="multipart/form-data">
 2<table>
 3             <tr>
 4            <td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">From Date</td>
 5            <td align="left" style="padding-left:23px;">
 6            <aui:fieldset>
 7                <aui:field-wrapper>
 8                    <liferay-ui:input-date
 9                      dayParam="fromDateDay"
10                      dayValue="<%= cal.get(Calendar.DATE) %>"
11                      disabled="<%= false %>"
12                      firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>"
13                      monthParam="fromDateMonth"
14                      monthValue="<%= cal.get(Calendar.MONTH) %>"
15                      yearParam="fromDateYear"
16                      yearValue="<%= cal.get(Calendar.YEAR) %>"
17                      yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>"
18                      yearRangeEnd="<%= cal.get(Calendar.YEAR) + 60 %>"
19                    />
20                </aui:field-wrapper>
21            </aui:fieldset>
22            </td>
23            </tr>
24        </table>            
25            <table>
26            <tr>
27            <td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">To Date</td>
28            <td align="left" class="greyText" style="padding-left:36px;">
29            <aui:fieldset>
30                <aui:field-wrapper>
31                    <liferay-ui:input-date
32                      dayParam="toDateDay"
33                      dayValue="<%= cal.get(Calendar.DATE) %>"
34                      disabled="<%= false %>"
35                      firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>"
36                      monthParam="toDateMonth"
37                      monthValue="<%= cal.get(Calendar.MONTH) %>"
38                      yearParam="toDateYear"
39                      yearValue="<%= cal.get(Calendar.YEAR) %>"
40                      yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>"
41                      yearRangeEnd="<%=cal.get(Calendar.YEAR) + 60 %>"
42                    />
43                </aui:field-wrapper>
44            </aui:fieldset></td>
45            </tr>
46            </table>
47</aui:form>


If yes then it is the nature of "multipart/form-data" form request processing.

Regards,
Mano
Rufus Pwner
RE: Date Picker
January 9, 2012 12:56 PM
Answer

Rufus Pwner

Rank: New Member

Posts: 3

Join Date: January 4, 2012

Recent Posts

I am sorry that i bothered you. I did not use the
<aui:form method="post" name="fm" enctype="multipart/form-data">
The only thing I did not do was to wrap my table with an aui:form at all.... stupid me.
Now that i have surrounded it with an aui:form tag it works like a charm
Thank you a lot for your advice and code snippet!
Keep up the good work!
Mohammad Azharuddin
RE: Date Picker
September 17, 2013 12:05 AM
Answer

Mohammad Azharuddin

Rank: Expert

Posts: 479

Join Date: September 17, 2012

Recent Posts

Hi


Use of PortalUtil.getDate is deprecated.Any alternative method

HTH