留言板

Date Picker

thumbnail
MANOVINAYAK AYYAPPAN,修改在12 年前。

Date Picker

Regular Member 帖子: 131 加入日期: 11-6-13 最近的帖子
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
thumbnail
MANOVINAYAK AYYAPPAN,修改在12 年前。

RE: Date Picker

Regular Member 帖子: 131 加入日期: 11-6-13 最近的帖子
If you an Sample Date Picker Implementation. Please share , I can refer to it and learn.

Regards,
Mano
thumbnail
MANOVINAYAK AYYAPPAN,修改在12 年前。

RE: Date Picker

Regular Member 帖子: 131 加入日期: 11-6-13 最近的帖子
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
thumbnail
Artur Pirozhkov,修改在12 年前。

RE: Date Picker

New Member 帖子: 9 加入日期: 11-5-17 最近的帖子
Hi mano

I am interested in the same question

how did you imported the class Enewsletter, which library is it from?
thumbnail
MANOVINAYAK AYYAPPAN,修改在12 年前。

RE: Date Picker

Regular Member 帖子: 131 加入日期: 11-6-13 最近的帖子
Hi Artur,

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


Regards,
Mano
Alberto Gonzalez,修改在12 年前。

RE: Date Picker

New Member 帖子: 6 加入日期: 11-11-3 最近的帖子
You receive them like params, isn´t it?
Jhansi Rani,修改在12 年前。

RE: Date Picker

Junior Member 帖子: 32 加入日期: 11-7-27 最近的帖子
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.
thumbnail
MANOVINAYAK AYYAPPAN,修改在12 年前。

RE: Date Picker

Regular Member 帖子: 131 加入日期: 11-6-13 最近的帖子
Hi All,

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

// In The JSP Page 

&lt;%
   Calendar cal = Calendar.getInstance();  
%&gt;

<table>
 			<tbody><tr>
        	<td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">From Date</td>
        	<td align="left" style="padding-left:23px;">
			<aui:fieldset>
				<aui:field-wrapper>
				    <liferay-ui:input-date dayParam="fromDateDay" dayValue="<%= cal.get(Calendar.DATE) %>" disabled="<%= false %>" firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>" monthParam="fromDateMonth" monthValue="<%= cal.get(Calendar.MONTH) %>" yearParam="fromDateYear" yearValue="<%= cal.get(Calendar.YEAR) %>" yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>" yearRangeEnd="<%= cal.get(Calendar.YEAR) + 60 %>" />
				</aui:field-wrapper>
			</aui:fieldset>
			</td>
			</tr>
		</tbody></table>	        
        
        
        	<table>
        	<tbody><tr>
        	<td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">To Date</td>
        	<td align="left" class="greyText" style="padding-left:36px;">
        	<aui:fieldset>
        		<aui:field-wrapper>
				    <liferay-ui:input-date dayParam="toDateDay" dayValue="<%= cal.get(Calendar.DATE) %>" disabled="<%= false %>" firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>" monthParam="toDateMonth" monthValue="<%= cal.get(Calendar.MONTH) %>" yearParam="toDateYear" yearValue="<%= cal.get(Calendar.YEAR) %>" yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>" yearRangeEnd="<%=cal.get(Calendar.YEAR) + 60 %>" />
				</aui:field-wrapper>
			</aui:fieldset></td>
			</tr>
			</tbody></table>
        



//Inside Portlet Class:

				// Getting the Date Range
					fromDay = ParamUtil.getInteger(actionRequest, "fromDateDay");
					fromMonth = ParamUtil.getInteger(actionRequest, "fromDateMonth");
					fromYear = ParamUtil.getInteger(actionRequest, "fromDateYear");
					toDay = ParamUtil.getInteger(actionRequest, "toDateDay");
					toMonth = ParamUtil.getInteger(actionRequest, "toDateMonth");
					toYear = ParamUtil.getInteger(actionRequest, "toDateYear");

		// Get Date Range 
					fromDate = getDate(fromMonth, fromDay, fromYear);
					toDate = getDate(toMonth, toDay, toYear);


		//To get the Actual Date Make a Call to the Method Below:

		public static Date getDate(int month, int day, int year){
				
				Date finalDate = null;
				
				try {
					finalDate = PortalUtil.getDate(month, day, year, new PortalException());
				} catch (PortalException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
					return finalDate = null;
				}
				
				return finalDate;
			}


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


Regards,
Mano
Jhansi Rani,修改在12 年前。

RE: Date Picker

Junior Member 帖子: 32 加入日期: 11-7-27 最近的帖子
Thank you for quick reply.

Regards
Jhansi
thumbnail
sunil G,修改在12 年前。

RE: Date Picker

New Member 帖子: 6 加入日期: 11-12-9 最近的帖子
Your Date picker code was very helpful

Thanks.
thumbnail
MANOVINAYAK AYYAPPAN,修改在12 年前。

RE: Date Picker

Regular Member 帖子: 131 加入日期: 11-6-13 最近的帖子
sunil G:
Your Date picker code was very helpful

Thanks.

You are welcomeemoticon

Regards,
Mano
Rufus Pwner,修改在12 年前。

RE: Date Picker

New Member 帖子: 3 加入日期: 12-1-4 最近的帖子
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

<table>
             <tbody><tr>
            <td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">From Date</td>
            <td align="left" style="padding-left:23px;">
            <aui:fieldset>
                <aui:field-wrapper>
                    <liferay-ui:input-date dayParam="fromDateDay" dayValue="<%= cal.get(Calendar.DATE) %>" disabled="<%= false %>" firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>" monthParam="fromDateMonth" monthValue="<%= cal.get(Calendar.MONTH) %>" yearParam="fromDateYear" yearValue="<%= cal.get(Calendar.YEAR) %>" yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>" yearRangeEnd="<%= cal.get(Calendar.YEAR) + 60 %>" />
                </aui:field-wrapper>
            </aui:fieldset>
            </td>
            </tr>
        </tbody></table>            
            <table>
            <tbody><tr>
            <td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">To Date</td>
            <td align="left" class="greyText" style="padding-left:36px;">
            <aui:fieldset>
                <aui:field-wrapper>
                    <liferay-ui:input-date dayParam="toDateDay" dayValue="<%= cal.get(Calendar.DATE) %>" disabled="<%= false %>" firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>" monthParam="toDateMonth" monthValue="<%= cal.get(Calendar.MONTH) %>" yearParam="toDateYear" yearValue="<%= cal.get(Calendar.YEAR) %>" yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>" yearRangeEnd="<%=cal.get(Calendar.YEAR) + 60 %>" />
                </aui:field-wrapper>
            </aui:fieldset></td>
            </tr>
            </tbody></table>

Portlet Code:

package com.test;

import java.io.IOException;
import java.util.Date;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;

import com.liferay.portal.kernel.exception.PortalException;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;

public class VeranstaltungsPortlet extends MVCPortlet {

	public void machen(ActionRequest actionRequest, ActionResponse actionResponse)
	throws IOException, PortletException{
	      // Getting the Date Range
      int  fromDay = ParamUtil.getInteger(actionRequest, "fromDateDay");
      int  fromMonth = ParamUtil.getInteger(actionRequest, "fromDateMonth");
        int fromYear = ParamUtil.getInteger(actionRequest, "fromDateYear");
     int   toDay = ParamUtil.getInteger(actionRequest, "toDateDay");
        int toMonth = ParamUtil.getInteger(actionRequest, "toDateMonth");
        int toYear = ParamUtil.getInteger(actionRequest, "toDateYear");
        System.out.println("FromDay: "+fromDay+" FromMonth: "+fromMonth+" FromYear: "+fromYear);
        System.out.println("FromDay: "+toDay+" FromMonth: "+toMonth+" FromYear: "+toYear);
// Get Date Range
        Date fromDate = getDate(fromMonth, fromDay, fromYear);
        Date toDate = getDate(toMonth, toDay, toYear);
	}

//To get the Actual Date Make a Call to the Method Below:

public static Date getDate(int month, int day, int year){
   
    Date finalDate = null;
   
   
        try {
			finalDate = PortalUtil.getDate(month, day, year, new PortalException());
		} catch (PortalException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
   
   
    return finalDate;
}
	}



Do you have any idea why?
I am using LR 6.1 RC.
thumbnail
MANOVINAYAK AYYAPPAN,修改在12 年前。

RE: Date Picker

Regular Member 帖子: 131 加入日期: 11-6-13 最近的帖子
Hi Rufus,

I believe you have included the below Calendar Object Instance in your code.

&lt;%
   Calendar cal = Calendar.getInstance(); 
%&gt;


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

Is it Something as below ?

<aui:form method="post" name="fm" enctype="multipart/form-data"> 
<table>
             <tbody><tr>
            <td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">From Date</td>
            <td align="left" style="padding-left:23px;">
            <aui:fieldset>
                <aui:field-wrapper>
                    <liferay-ui:input-date dayParam="fromDateDay" dayValue="<%= cal.get(Calendar.DATE) %>" disabled="<%= false %>" firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>" monthParam="fromDateMonth" monthValue="<%= cal.get(Calendar.MONTH) %>" yearParam="fromDateYear" yearValue="<%= cal.get(Calendar.YEAR) %>" yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>" yearRangeEnd="<%= cal.get(Calendar.YEAR) + 60 %>" />
                </aui:field-wrapper>
            </aui:fieldset>
            </td>
            </tr>
        </tbody></table>            
            <table>
            <tbody><tr>
            <td align="left" class="greyText" style="padding-top:10px; vertical-align:top;">To Date</td>
            <td align="left" class="greyText" style="padding-left:36px;">
            <aui:fieldset>
                <aui:field-wrapper>
                    <liferay-ui:input-date dayParam="toDateDay" dayValue="<%= cal.get(Calendar.DATE) %>" disabled="<%= false %>" firstDayOfWeek="<%= cal.getFirstDayOfWeek() - 1 %>" monthParam="toDateMonth" monthValue="<%= cal.get(Calendar.MONTH) %>" yearParam="toDateYear" yearValue="<%= cal.get(Calendar.YEAR) %>" yearRangeStart="<%= cal.get(Calendar.YEAR) - 60 %>" yearRangeEnd="<%=cal.get(Calendar.YEAR) + 60 %>" />
                </aui:field-wrapper>
            </aui:fieldset></td>
            </tr>
            </tbody></table>
</aui:form>


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

Regards,
Mano
Rufus Pwner,修改在12 年前。

RE: Date Picker

New Member 帖子: 3 加入日期: 12-1-4 最近的帖子
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!
thumbnail
mohammad azaruddin,修改在10 年前。

RE: Date Picker

Expert 帖子: 492 加入日期: 12-9-17 最近的帖子
Hi


Use of PortalUtil.getDate is deprecated.Any alternative method

HTH