Display data on jsp based on selected date from Liferay datepicker

こ雲淡風輕ζ 提交于 2019-12-13 02:54:48

问题


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?


回答1:


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

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

Going with the second approach:

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>

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

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




回答2:


You can pass parameter under resourceURL and check that parameter under serveResorce method. Based on that parameter call your function or code

i.e

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


来源:https://stackoverflow.com/questions/16811854/display-data-on-jsp-based-on-selected-date-from-liferay-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!