掲示板

I have a service related to my aui form in liferay 7.

6年前 に Aayush Bhalla によって更新されました。

I have a service related to my aui form in liferay 7.

New Member 投稿: 8 参加年月日: 17/06/07 最新の投稿
While trying to perform the CRUD operations, I manually tried to add data in MYSQL table. After adding I reloaded the page but data is not being updated in table on browser. It takes approximately half an hour after which I reload and data is added in table. How can I instantly display output in table on browser after adding in SQL table.

This is my java file:

package com.example.portlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.portlet.Portlet;
import javax.portlet.PortletException;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import javax.portlet.ResourceRequest;
import javax.portlet.ResourceResponse;

import org.osgi.service.component.annotations.Component;

import com.billpol.model.Bil;
import com.billpol.model.Pol;
import com.billpol.service.BilLocalServiceUtil;
import com.billpol.service.PolLocalServiceUtil;
import com.liferay.portal.kernel.dao.orm.Query;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.json.JSONArray;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.portlet.bridges.mvc.MVCPortlet;
import com.liferay.portal.kernel.service.UserLocalServiceUtil;

@Component(immediate = true, property = { "com.liferay.portlet.display-category=category.ers",
"com.liferay.portlet.instanceable=true", "javax.portlet.display-name=result Portlet",
"javax.portlet.init-param.template-path=/", "javax.portlet.init-param.view-template=/view.jsp",
"javax.portlet.resource-bundle=content.Language",
"javax.portlet.security-role-ref=power-user,user" }, service = Portlet.class)
public class PolicymvcportletPortlet extends MVCPortlet {
@Override
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {
super.doView(renderRequest, renderResponse);
}

@Override
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse)
throws IOException, PortletException {
try {
System.out.println("====serveResource========");
JSONObject jsonPol = null;
JSONArray usersJsonArray = JSONFactoryUtil.createJSONArray();
List<Pol> polList = PolLocalServiceUtil.getPols(QueryUtil.ALL_POS, QueryUtil.ALL_POS);
for (Pol userObj : polList) {
jsonPol = JSONFactoryUtil.createJSONObject();
jsonPol.put("pol_id", userObj.getPol_id());
jsonPol.put("pol_billlimit", userObj.getPol_billLimit());
jsonPol.put("pol_desc", userObj.getPol_desc());
jsonPol.put("pol_lastUpOn", userObj.getPol_lastUpBy());
jsonPol.put("pol_lastUpBy", userObj.getPol_lastUpOn());
jsonPol.put("isresc", userObj.getIsResc());
jsonPol.put("companyId", userObj.getCompanyId());
jsonPol.put("Action", userObj.getPol_id());
usersJsonArray.put(jsonPol);
}
PrintWriter out = resourceResponse.getWriter();
System.out.println(usersJsonArray.toString());
out.print(usersJsonArray.toString());
} catch (Exception e) {
e.printStackTrace();
}
}
}
thumbnail
6年前 に Christoph Rabel によって更新されました。

RE: I have a service related to my aui form in liferay 7.

Liferay Legend 投稿: 1554 参加年月日: 09/09/24 最新の投稿
You can disable the cache in the service.xml.
<entity name="Something" .... cache-enabled="false">

But be careful, disabling the cache for your entities might impact performance.
6年前 に Aayush Bhalla によって更新されました。

RE: I have a service related to my aui form in liferay 7.

New Member 投稿: 8 参加年月日: 17/06/07 最新の投稿
I tried doing it, it affected my performance but wasnt able to solve my issue. It takes like half an hour to display the data I manually entered in sql.
thumbnail
6年前 に Jack Bakker によって更新されました。

RE: I have a service related to my aui form in liferay 7.

Liferay Master 投稿: 978 参加年月日: 10/01/03 最新の投稿
you also can clear the cache programmatically, add to your PolLocalServiceImpl

public void clearCache(){
        polPersistence.clearCache();
 }

then call it, perhaps only while in debug? with PolLocalServiceUtil.clearCache()
6年前 に Aayush Bhalla によって更新されました。

RE: I have a service related to my aui form in liferay 7.

New Member 投稿: 8 参加年月日: 17/06/07 最新の投稿
I tried it but it made no changes in the output. I added the data in sql table and refreshed my browser. It did nothing.
thumbnail
6年前 に Andrew Jardine によって更新されました。

RE: I have a service related to my aui form in liferay 7.

Liferay Legend 投稿: 2416 参加年月日: 10/12/22 最新の投稿
when you set a breakpoint in your serveResource method, on the line after the list, do you get the same List size for each call? For example.

1. YOu have 5 records in the database.
2. You load the portlet -- and call serve resource, you size is 5
3. You add 3 more records (manually as you say)
4. Call the serve resource method -- I would expect you to still see 5.
5. Flush the cache (you can cheat by just using the one in the Control Panel > Server Administration -- clear all the caches. db, jvm, etc)
6. Reload and this time you should see 8 (in my example) as your list size.

.. if you do this and you see that as the output then for sure it is a caching problem. Repeating the steps but only clearing the db cache, or just the entity cache will allow you to isolate the issue.

But rather than adding the records by hand (which circumvents the whole Liferay API) why not add a simple action method to add the data. If you use the framework then it will make sure that caches and such are expired when you make the add/updates. Doing things directly in the database is never a good idea with LR. There are a million posts in the forums telling people NOT to do that emoticon