本文介绍了根据Liferay datepicker中的选定日期在jsp上显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期选择器.我要实现的是:根据用户选择的日期,该日的数据应显示在jsp上.我使用了serveResource函数以其他某种形式显示某些数据.我是否应该创建另一个这样的功能,以便根据选定的日期显示该特定数据的数据?

I have a datepicker. What I want to achieve is: based on the date selected by user, the data for that day should be displayed on the jsp.I have used a serveResource function for displaying some data in some other form.Should I create another such function such that based on selected date, data is displayed for that particular data?

推荐答案

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

You are using serveResource so you want to fetch data using ajax.

不幸的是,换句话说,您不能使resourceURL的行为与actionURL相同,也不能像提供actionRequest那样具有多种服务resourceRequest的方法.

Unfortunately you can't have resourceURL behave the same as actionURL in otherwords you can't have multiple methods for serving resourceRequest like you have to serve actionRequest.

  1. 所以您可以使用actionURL调用不同的方法,但是会刷新您不希望看到的页面
  2. OR,否则您可以在resourceURL中设置一个参数,以让serveResource方法知道您要返回的内容,然后在portlet的serveResource方法中使用switch-caseif-else来确定这个请求来自哪里.
  1. So either you can use actionURL to call different methods but would refresh the page which you don't want as I see
  2. OR, else you can set a parameter in the resourceURL to let the serveResource method know what you want to return and then in the serveResource method of the portlet have switch-case or if-else to determine from where has this request come.

采用第二种方法:

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

You jsp would look something like this (might not work as it is):

<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>

您的serveResource方法将类似于以下内容(我假设您的portlet扩展了liferay的MVCPortlet类):

Your serveResource method would be something like this (I am assuming your portlet extends MVCPortlet class of liferay):

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
    }
}

注意:
作为旁注,您可以尝试 Spring MVC portlet ,使您能够使用不同的方法来服务resourceRequest.

Note:
As a side-note you can try Spring MVC portlet which gives you the ability to have different methods for serving resourceRequest.

这篇关于根据Liferay datepicker中的选定日期在jsp上显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 02:15