留言板
Date picker and Liferay
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....
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....
Kyle Joseph Stiemann,修改在8 年前。
RE: Date picker and Liferay
Liferay Master 帖子: 760 加入日期: 13-1-14 最近的帖子
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!
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!
Kyle Joseph Stiemann,修改在8 年前。
RE: Date picker and Liferay
Liferay Master 帖子: 760 加入日期: 13-1-14 最近的帖子
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
- Kyle
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:
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.
<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.
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:
Catching:
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">
<%
Calendar startingDateCalendar= CalendarFactoryUtil.getCalendar();
if (myModelId!=0 && 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());
}
%>
<aui:input name="startingDate" value="<%=startingDateCalendar %>" helpMessage="yyyy-MM-dd" />
....
<aui:button type="submit" value="save" [b]onClick="<%= renderResponse.getNamespace() + "updateAgentRenumeration();" %>[/b]" />
</aui:form>
<aui:script>
function <portlet:namespace />updateModel() {
document.<portlet:namespace />fm.<portlet:namespace /><%= Constants.CMD %>.value = "<%= Constants.UPDATE %>";
[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);
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.
be cool to see a ping/pong dev.life on
- hey I want to do this
- well here it is in Liferay source...
- hey I want to do this
- well here it is in Liferay source...
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.
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.
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