個人而言,我更喜歡liferay-ui:input-date。只是一定要保持一個日期或日曆對象控制器類
<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>
回到控制器..
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);
即使在編輯之後,我不確定你的問題是什麼。是關於將日期傳遞給控制器並返回給jsp(ajax或不),還是使用資源階段?你以前能夠將日期傳遞給控制器嗎? – yannicuLar
@yannicuLar: 我爲此使用了Ajax。 我將用戶選擇的數據傳遞給serveResource,現在我正在檢索jsp中的json對象。儘管如此,我還是有其他問題。現在我使用的顯示數據: 成功:函數(JSONArray),其中{ \t \t \t \t \t \t \t \t警報(JSONArray),其中, \t \t \t \t \t \t \t \t $( '#displayDate')的HTML(jsonArray [0])。 \t \t \t} 有沒有辦法可以存儲json對象並在liferay搜索容器中使用它? –