根据Liferay datepicker中的选定日期在jsp上显示数据

时间:2013-05-29 10:47:44

标签: jsp liferay liferay-6

我有一个日期选择器。我想要实现的是:根据用户选择的日期,应该在jsp上显示当天的数据。 我使用了serveResource函数来显示某些其他形式的数据。 我是否应该创建另一个此类函数,以便根据所选日期显示该特定数据的数据?

2 个答案:

答案 0 :(得分:1)

您可以在resourceURL下传递参数,并在serveResorce方法下检查该参数。根据该参数调用您的函数或代码

<portlet:resourceURL var="userdetail" >
<portlet:param name="userinfo" value="true"></portlet:param>
</portlet:resourceURL>

答案 1 :(得分:1)

您正在使用serveResource,因此您想使用ajax获取数据。

很遗憾,resourceURL的行为与actionURL的行为不同,在其他方面,您无法使用多种方法提供resourceRequest,就像您必须提供actionRequest一样。

  1. 因此,您可以使用actionURL来调用不同的方法,但会刷新您不希望看到的页面
  2. OR,否则你可以在resourceURL中设置一个参数,让serveResource方法知道你想要返回什么,然后在portlet的serveResource方法中{{1}或} switch-case来确定此请求的来源。
  3. 采用第二种方法:

    你的jsp看起来像这样(可能无法正常工作):

    if-else

    你的<aui:button value="Click to get today's data" onClick="fetchCurrentDateData()" /> <portlet:resourceURL var="currentDateDataResourceURL" > <portlet:param name="whicData" value="currentDateData" /> </portlet:resourceURL> <aui:script> function fetchCurrentDateData() { A.io.request( currentDateDataResourceURL, { dataType: 'text', // since you might want to execute a JSP and return HTML code on: { success: function(event, id, xhr) { A.one("#theDivWhereNeedsToBeDisplayed").html(this.get('responseData')); }, failure: function(event, id, xhr){ } } } ); } </aui:script> 方法会是这样的(我假设你的portlet扩展了serveResource类的liferay:

    MVCPortlet

    注意:
    作为旁注,您可以尝试Spring MVC portlet,这样您就可以使用不同的方法来投放public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) { String strWhichData = ParamUtil.getString(resourceRequest, "whicData"); if (strWhichData.equals("currentDateData")){ // call service layer to fetch all the current date data // this is a method in MVCPortlet if you are extending liferay's MVCPortlet include("/html/myportlet/viewCurrentData.jsp", resourceRequest, resourceResponse); } else if (strWhichData.equals("otherAjaxStuff")) { // do you other stuff and return JSON or HTML as you see fit } else { // do your normal stuff // can return JSON or HTML as you see fit } }