Monday, 15 January 2018

Dropdown values from liferay DB table

1>
<%
List<Organization> org = OrganizationLocalServiceUtil.getOrganizations(-1, -1);

List<Country> country = CountryServiceUtil.getCountries();

%>


2> 
<select>
  <option value="-1">Select</option>
  <%for (Organization organization : org) { %>
  <option value=<%=organization.getOrganizationId() %>><%=organization.getName()%></option>
  <%} %>
</select>

<select>
  <option value="-1">Select</option>
  <%for (Country cn : country) { %>
  <option value=<%=cn.getCountryId() %>><%=cn.getName()%></option>
  <%} %>
</select>

External Properties in Liferay DXP

1> Add below entry in portal-ext.properties
    PropertiesLocation=D:/liferay-dxp-digital-enterprise-7.0-sp3/external.properties

2> Now you can add keys in external properties file.
    Example:-
    key1 = external_Id

3> Use above key using below java code..


         /**
 * Getting the location holding file containing data 
 *
 * @param queryString
 * @return
 */
public static String getPropertiesContent(final String queryString) {
final Properties properties = new Properties();
try {
final FileReader reader = new FileReader(
        PropsUtil.get("PropertiesLocation"));
properties.load(reader);
} catch (final IOException e) {
return "File path not found";
}
return properties.getProperty(queryString, "");
}

4> Now you can use like below
keyName=<ClassName>.getPropertiesContent(
        "key1" );