Skip to content

Instantly share code, notes, and snippets.

@jamesfalkner
Created November 15, 2013 20:22
Show Gist options
  • Save jamesfalkner/7490960 to your computer and use it in GitHub Desktop.
Save jamesfalkner/7490960 to your computer and use it in GitHub Desktop.
<p><em>Expando Demo 1: Creating and Reading Expando Data</em></p>
## get the static field constant for Expando String type.
## In freemarker, this is much easier:
## <#assign DATE = staticUtil["java.util.Calendar"].DATE>
#set ($expandoConstants = $portal.getClass().forName("com.liferay.portlet.expando.model.ExpandoColumnConstants"))
#set ($expandoConstantsInstance = $expandoConstants.newInstance())
#set ($stringType = $expandoConstants.getField("STRING").get($expandoConstantsInstance))
## create table
#set ($table = $expandoTableLocalService.getTable($getterUtil.getLong($companyId), "org.lrnas2.james", "MyExpandoTable"))
#if ($validator.isNull($table))
#set ($table = $expandoTableLocalService.addTable($getterUtil.getLong($companyId), "org.lrnas2.james", "MyExpandoTable"))
#end
## add a column
#set ($col = $expandoColumnLocalService.addColumn($table.getTableId(), "FavoriteColor", $stringType))
## add some rows
#foreach ($color in ["red", "blue", "pink", "green"])
#set ($V = $expandoValueLocalService.addValue($getterUtil.getLong($companyId), "org.lrnas2.james", "MyExpandoTable", "FavoriteColor", $color.hashCode(), $color))
#end
## now echo them
#foreach ($rowVal in $expandoValueLocalService.getColumnValues($getterUtil.getLong($companyId), "org.lrnas2.james", "MyExpandoTable", "FavoriteColor", -1, -1))
<p>Color: $rowVal.getString()</p>
#end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment