Fórum

Date picker and Liferay

thumbnail
Puj Z, modificado 8 Anos atrás.

Date picker and Liferay

Regular Member Postagens: 220 Data de Entrada: 14/01/10 Postagens Recentes
Hi guys,

after one hour of searching the internet and trying various code, I got headache and gave up. Seriously, Liferay doesn't offer ANY relatively simple and clean method for a date picker? This is just embarrassing. Every time I have to use a String field and do some tricks to save a simple date. How difficult could it be....
thumbnail
Kyle Joseph Stiemann, modificado 8 Anos atrás.

RE: Date picker and Liferay

Liferay Master Postagens: 760 Data de Entrada: 14/01/13 Postagens Recentes
Hi Puj Z,
Have you tried AlloyUI's DatePicker or liferay-ui:input-date?

- Kyle
thumbnail
Puj Z, modificado 8 Anos atrás.

RE: Date picker and Liferay

Regular Member Postagens: 220 Data de Entrada: 14/01/10 Postagens Recentes
Hi Kyle,

Thanks for your reply. I am unfortunately not a Jquery or JS savvy. As I see no variable is being sent.
Here is my case:
I have a model with two dates attributes: startingDate and endingDate. When I use normal <aui:input> in my form, a calendar (supported by browser) pops up automatically, but the date is not picked up. It means I always receive the current date (apparently the hidden default value) when I call

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
ParamUtil.getDate(request,"startingDate",dateFormat)

Would you please provide me a simple piece of code, that I pick the date , and it would be sent as a normal request parameter so that I can catch it in my action method for this case?
Seriously I am trying to convince my colleague that Liferay is a sophisticated platform, but things like this are like a spit in the face. Things that other platforms have solved centuries ago!
thumbnail
Kyle Joseph Stiemann, modificado 8 Anos atrás.

RE: Date picker and Liferay

Liferay Master Postagens: 760 Data de Entrada: 14/01/13 Postagens Recentes
Hi Puj, unfortunately all I can do is point you towards AlloyUI's DatePicker and liferay-ui:input-date because I'm not a expert on the JSP taglibs (I work with JSF and AlloyUI). Hopefully someone else will come around and be able to give you a more specific answer to your questions.

- Kyle
thumbnail
David H Nebinger, modificado 8 Anos atrás.

RE: Date picker and Liferay

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
Umm, the Liferay source has plenty of examples for the AUI date input tag. Here's the snippet from /html/portlet/login/create_account.jsp:

<aui:input name="birthday" value="<%= birthdayCalendar %>" />


birthdayCalendar is just a calendar object initialized to a particular date.

you can see how to read the birthday values in the com.liferay.portlet.login.action.CreateAccountAction class.
thumbnail
Puj Z, modificado 8 Anos atrás.

RE: Date picker and Liferay

Regular Member Postagens: 220 Data de Entrada: 14/01/10 Postagens Recentes
Hi David,

Thank you for your tip! I tried, it didn't work at first, since somewhere in some liferay js file the hidden day-month-year variables were set.
I copied the same logic as Liferay without knowing exactly what is happening and it worked! Here is my code for those who want to skip the headache:

Setting om edit.jsp:
<aui:form method="POST" action="<%=editModel %>" name="fm">
&lt;%
    Calendar startingDateCalendar= CalendarFactoryUtil.getCalendar();
	if (myModelId!=0 &amp;&amp; myModel.getStartingDate() != null)
		startingDateCalendar.setTime(myModel.getStartingDate());
	else
	{
		int startingDateDay = ParamUtil.getInteger(request, "startingDateDay", 0);
		if (startingDateDay!=0)
		{
		int startingDateMonth = ParamUtil.getInteger(request, "startingDateMonth");
		int startingDateYear = ParamUtil.getInteger(request, "startingDateYear");

		Date startingDateDate = PortalUtil.getDate(startingDateMonth, startingDateDay, startingDateYear);
		startingDateCalendar.setTime(startingDateDate);
		}
		else
			startingDateCalendar.setTime(DateUtil.newDate());
	}
%&gt;
<aui:input name="startingDate" value="<%=startingDateCalendar %>" helpMessage="yyyy-MM-dd" />
....

<aui:button type="submit" value="save" [b]onClick="<%= renderResponse.getNamespace() + &quot;updateAgentRenumeration();&quot; %>[/b]" /> 
</aui:form>

<aui:script>
	function <portlet:namespace />updateModel() {
		document.<portlet:namespace />fm.<portlet:namespace />&lt;%= Constants.CMD %&gt;.value = "&lt;%= Constants.UPDATE %&gt;";

		[b]submitForm(document.<portlet:namespace />fm);[/b]
	}
</aui:script>


Catching:
	
int startingDateDay = ParamUtil.getInteger(request, "startingDateDay");
		int startingDateMonth = ParamUtil.getInteger(request, "startingDateMonth");
		int startingDateYear = ParamUtil.getInteger(request, "startingDateYear");
		Date startingDate = PortalUtil.getDate(startingDateMonth, startingDateDay, startingDateYear);
thumbnail
David H Nebinger, modificado 8 Anos atrás.

RE: Date picker and Liferay

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
The Liferay source is often the best place to look to find how to do something "the Liferay way". All of the Liferay portlets and widgets you see out of the box are all "the Liferay way" so it can be a solid (albeit not well documented) example.
thumbnail
Jack Bakker, modificado 8 Anos atrás.

RE: Date picker and Liferay

Liferay Master Postagens: 978 Data de Entrada: 03/01/10 Postagens Recentes
be cool to see a ping/pong dev.life on

- hey I want to do this
- well here it is in Liferay source...
thumbnail
David H Nebinger, modificado 8 Anos atrás.

RE: Date picker and Liferay

Liferay Legend Postagens: 14915 Data de Entrada: 02/09/06 Postagens Recentes
I think the problem is, Jack, that most folks don't want to build portlets "the liferay way". I mean, Liferay MVC just feels dated when you get into it, and I still know people add jQuery into their themes/portlets rather than using AUI...

I think Liferay MVC loses out when compared to Spring Portlet MVC even though there's really a lot of overlap there.

If you're reading this, Liferay, I'm not knocking Liferay MVC as I've actually found it to be the most scalable solution by far. I'm just saying that it doesn't leave you feeling like you're doing anything new, modern, or relevant.
Aime Bukasa, modificado 8 Anos atrás.

RE: Date picker and Liferay

New Member Postagens: 2 Data de Entrada: 19/01/15 Postagens Recentes
Puj Z:
Hi guys,

after one hour of searching the internet and trying various code, I got headache and gave up. Seriously, Liferay doesn't offer ANY relatively simple and clean method for a date picker? This is just embarrassing. Every time I have to use a String field and do some tricks to save a simple date. How difficult could it be....


Hi Puj

I have just experienced the same problem and simply resolved this way:

Change your code from:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
ParamUtil.getDate(request,"startingDate",dateFormat)

to:

SimpleDateFormat dateFormat = new SimpleDateFormat("mm/dd/yyyy");
ParamUtil.getDate(request,"startingDate",dateFormat)

The date format need to be "mm/dd/yyyy" (the date picker date format) instead of "yyyy-MM-dd".

Aime
Aime Bukasa, modificado 8 Anos atrás.

RE: Date picker and Liferay

New Member Postagens: 2 Data de Entrada: 19/01/15 Postagens Recentes
Quick rectification: Use form "MM/dd/yyyy" instead of "mm/dd/yyyy" as "MM" is interpreted as Month and "mm" as minutes.