0

I have a portlet embedded in a theme. The only solution that I found to permit the theme to get parameters values from the portlet is to use an intermediate database. What I did is that I created a table in the portlet and then I tried to access to this table from the theme:

Java Code in the portlet:

ExpandoTable table=null;
        try {
            table = ExpandoTableLocalServiceUtil.addTable(CompanyLocalServiceUtil.getCompanies().get(0).getCompanyId(), User.class.getName(), "ClientTab");
        }
        catch (  DuplicateTableNameException dtne) {
            table=ExpandoTableLocalServiceUtil.getTable(CompanyLocalServiceUtil.getCompanies().get(0).getCompanyId(), User.class.getName(), "ClientTab");
        }

The velocity code in the theme:

#set ($accountsTableName = "ClientTab")

#set ($accountsTable = $expandoTableLocalService.getTable($accountsTableName, $accountsTableName))

#if (!$accountsTable)
 <h2> The table ClientTab doesn't exist </h2>
#else
 <h2> Well The table ClientTab exists </h2>
#end

But the result that I got is:

The table ClientTab doesn't exist

I used those references to develop my code:

http://myjavaexp.blogspot.com/2013/01/liferay-expando-services.html

http://www.programcreek.com/java-api-examples/index.php?api=com.liferay.portlet.expando.DuplicateColumnNameException

http://www.liferay.com/fr/web/raymond.auge/blog/-/blogs/715049

Kallel Omar
  • 1,208
  • 2
  • 17
  • 51
  • Any errors? And are you sure you are not missing arguments in: `#set ($accountsTable = $expandoTableLocalService.getTable($accountsTableName, $accountsTableName))`. Also why not display `$accountsTable` to check. – Prakash K Jan 08 '15 at 13:52

1 Answers1

0

If you just want to pass values from your portlet to the theme you can add new Velocity variables in your render method, like this:

HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request);
Map<String, Object> velocityVariables = (Map<String, Object>)httpRequest.getAttribute(WebKeys.VM_VARIABLES);
if(velocityVariables == null) {
    velocityVariables = new HashMap<String, Object>();
}

velocityVariables.put("mySpecialKey", "mySpecialValue");
request.setAttribute(WebKeys.VM_VARIABLES, velocityVariables);

Then you can use the variable in your theme like this:

<h1>Here's the value added by my portlet --> $mySpecialKey</h1>

Don't forget the $ character on the front of the variable.

clav
  • 4,221
  • 30
  • 43