Ask Questions and Find Answers
Important:
Ask is now read-only. You can review any existing questions and answers, but not add anything new.
But - don't panic! While ask is no more, we've replaced it with discuss - the new Liferay Discussion Forum! Read more here here or just visit the site here:
discuss.liferay.com
Liferay 7.2 - Refreshing view.jsp
Hi,
I have the following code in my java class for my portlet:
I have the following code in my java class for my portlet:
@Override
public void doView(RenderRequest request, RenderResponse response) throws IOException, PortletException {
ThemeDisplay theme = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
long start = 0;
if (request.getAttribute("start-date") != null) start = (long) request.getAttribute("start-date");
request.removeAttribute("start-date");
long end = 0;
if (request.getAttribute("end-date") != null) end = (long) request.getAttribute("end-date");
request.removeAttribute("end-date");
List<object> objects = new ArrayList<object>();
if (start == 0 && end == 0) objects.addAll(getObjects());
System.out.println(objects.toString());
super.doView(request, response);
}
@ProcessAction(name="filterByDate")
public void filterByDate(ActionRequest request, ActionResponse response) throws ReadOnlyException {
request.setAttribute("start-date", ParamUtil.getLong(request, "start-date"));
request.setAttribute("end-date", ParamUtil.getLong(request, "end-date"));
}<br><br>Now in my view.jsp I have the following:<br><br><pre><code><portlet:defineobjects />
<portlet:actionurl name="filterByDate" var="filterURL" />
<input type="text" id="daterange">
<script>
$(function () {
$('#daterange').daterangepicker({
endDate: moment(),
maxDate: moment(),
locale: {
"format": "DD/MM/YYYY",
"separator": " - ",
}, function (start, end) {
var startDate = new Date(start.toString());
var endDate = new Date(end.toString());
$.ajax({
url : '${filterURL}',
type : 'POST',
data : {
"<portlet:namespace/>start-date": startDate.getTime(),
"<portlet:namespace/>end-date": endDate.getTime()
}
});
});
$('#daterange').on('apply.daterangepicker')
});
</script></code></pre><br><br>Now, this is doing the following: when I start my portlet, the values for the "start" and "end" variables are 0, so I add all my objects and System.out.println them. Then I open my Date Picker, click on submit and the "filterByDate" method is called. After that the "doView" is called again and now the "start" and "end" variables are not 0 and the System.out.println prints an empty list. So this is working until here.<br><br>My problem is that the view.jsp is not refreshed with the new "doView". It is not supposed to refresh? How can I refresh my view with the new information after I submit an ActionURL?</object></object>
Hi,
I think your calling action method through ajax that why its not refreshing , you can submit the form and try
I think your calling action method through ajax that why its not refreshing , you can submit the form and try
Hi Mohammed,
Thanks for your answer. Yes, I am calling action method through ajax. How can I submit the form?
Thanks for your answer. Yes, I am calling action method through ajax. How can I submit the form?
You can have that date picker inside a form and have a submit button something like
<aui:form action="${filterURL}">
<aui: input type="text" id="daterange" />
<aui:button type="submit" value="save" />
</aui:form>
If you want to have start and end date you can have hidden input which you can set in javascript and then submit from javascript also.
<aui:form action="${filterURL}">
<aui: input type="text" id="daterange" />
<aui:button type="submit" value="save" />
</aui:form>
If you want to have start and end date you can have hidden input which you can set in javascript and then submit from javascript also.
You are a lifesaver Mohammed!
It is working! I ended with something like this:
And in my view.jsp:
It is working! I ended with something like this:
@Override
public void processAction(ActionRequest request, ActionResponse response) throws IOException, PortletException {
request.setAttribute("start-date", ParamUtil.getLong(request, "startDate"));
request.setAttribute("end-date", ParamUtil.getLong(request, "endDate"));
super.processAction(request, response);
}
And in my view.jsp:
<portlet:defineobjects />
<portlet:actionurl var="filterURL" />
<aui:form name="filterForm" action="${filterURL}" method="post">
<aui:input id="startDate" name="startDate" type="hidden" />
<aui:input id="endDate" name="endDate" type="hidden" />
</aui:form>
<input type="text" name="dateFilter">
<script type="text/javascript">
$(function() {
$('input[name="dateFilter"]').daterangepicker({
endDate: moment(),
maxDate: moment()
});
$('input[name="dateFilter"]').on('apply.daterangepicker', function(ev, picker) {
var startDate = new Date(picker.startDate.toString());
$("#<portlet:namespace/>startDate").val(startDate.getTime());
var endDate = new Date(picker.endDate.toString());
$("#<portlet:namespace/>endDate").val(endDate.getTime());
$("#<portlet:namespace/>filterForm").submit();
});
});
</script>
Copyright © 2025 Liferay, Inc
• Privacy Policy
Powered by Liferay™