留言板

Liferay IDE+Hook Plugin+ Expando+Custom Fields

thumbnail
p chandru,修改在13 年前。

Liferay IDE+Hook Plugin+ Expando+Custom Fields

New Member 帖子: 6 加入日期: 10-2-19 最近的帖子
Hi All,
I would like to add custom attributes to the Liferay portlets using the "Expando".
Can anyone please help me.
I am using Liferay 6+Tomcat 6+MySql.
I configured Eclipse for LiferayIDE.
I need an example.
Thanks in advance.




Chandru P
thumbnail
Georaj K,修改在13 年前。

RE: Liferay IDE+Hook Plugin+ Expando+Custom Fields

Junior Member 帖子: 64 加入日期: 10-3-31 最近的帖子
Hi all


Iam suffering the same prblms

p chandru:
Hi All,
I would like to add custom attributes to the Liferay portlets using the "Expando".
Can anyone please help me.
I am using Liferay 6+Tomcat 6+MySql.
I configured Eclipse for LiferayIDE.
I need an example.
Thanks in advance.




Chandru P




g.r.k
Francisco Aranda,修改在13 年前。

RE: Liferay IDE+Hook Plugin+ Expando+Custom Fields

New Member 帖子: 6 加入日期: 10-5-24 最近的帖子

protected void setupExpandos(long companyId) throws Exception {
		
		ExpandoTable table = null;

		//FIRST TRY TO ADD A TABLE
		
		try {
			
			table = ExpandoTableLocalServiceUtil.addTable(
				companyId, User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME);

			/*A little note about this: 
			  Using ExpandoTableConstants.DEFAULT_TABLE_NAME you are trying to add the default expando column.
                          And it will always fail, because that table aready exists within liferay.
                          You can change this value to create a new table, for example:
			  table = ExpandoTableLocalServiceUtil.addTable(companyId, User.class.getName(), "MYTABLE");
			  And of course you can change User.class.getName(), to add expando values to any other liferay model.
			  Usign ExpandoTableConstants.DEFAULT_TABLE_NAME You are going to be able to see and modify them as Custom fields from control Panel.
			  If you create other table, you are not going to be able to modify them from control panel.
			  
			*/

		}
		catch (DuplicateTableNameException dtne) {
			/* Get the default table for User Custom Fields */
			table = ExpandoTableLocalServiceUtil.getTable(companyId, User.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME);
		}

                String column = "";

                column = "alternativeEmail";
		//Try to add a new column to store alternativeEmail
		try {	
                  ExpandoColumnLocalServiceUtil.addColumn(table.getTableId(),column, ExpandoColumnConstants.STRING);
                } catch (DuplicateColumnNameException dcne) { MyUtils.trace(column+" already exists!"); }
                
		/*Now the column is created, so next we are going to try to get the column and Add some permission.
		We need to do this, in order to set values to the expando columns from a Hook or portlet. 
		personaly I understand that it may be a security 'issue', 
		but grant permission to GUEST is the only way I found to add values not being the user that owns that  Custom Field. */
		
		try {
	 
                 ExpandoColumn ecolumn = ExpandoColumnLocalServiceUtil.getColumn(companyId, User.class.getName(),ExpandoTableConstants.DEFAULT_TABLE_NAME,column);
                 /*This method 'Permissions.setRolePermissions' is the KEY to add permission to almost everything in liferay, I was using other method in LR5 but it doesn't seems to work anymore.. this is the KEY! :-) */ 
		 Permissions.setRolePermissions(companyId,ExpandoColumn.class.getName() ,ecolumn.getPrimaryKey(), RoleConstants.GUEST, new String[] { ActionKeys.VIEW, ActionKeys.UPDATE });
                 
               } catch(Exception e) { MyUtils.trace(e.getMessage()); }
                
	
		/* that's it. Now you can add some values from the hook */                



	}

thumbnail
Baptiste Grenier,修改在13 年前。

RE: Liferay IDE+Hook Plugin+ Expando+Custom Fields

Regular Member 帖子: 100 加入日期: 09-6-30 最近的帖子
Francisco Aranda:

                 /*This method 'Permissions.setRolePermissions' is the KEY to add permission to almost everything in liferay, I was using other method in LR5 but it doesn't seems to work anymore.. this is the KEY! :-) */ 
		 Permissions.setRolePermissions(companyId,ExpandoColumn.class.getName() ,ecolumn.getPrimaryKey(), RoleConstants.GUEST, new String[] { ActionKeys.VIEW, ActionKeys.UPDATE });
                 
               } catch(Exception e) { MyUtils.trace(e.getMessage()); }
                }

Hello,
I know that this post is quite old, but could you please tell me from where is this Permissions class?
I am unable to find such a class with such a method into liferay 6 trunk and 6.0.5.

Regards,
Baptiste
thumbnail
jelmer kuperus,修改在13 年前。

RE: Liferay IDE+Hook Plugin+ Expando+Custom Fields

Liferay Legend 帖子: 1191 加入日期: 10-3-10 最近的帖子
See if this works for you

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, ExpandoColumn.class.getName(),
                    ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(ecolumn.getColumnId()), RoleConstants.GUEST, new String[] { ActionKeys.VIEW, ActionKeys.UPDATE });
thumbnail
Baptiste Grenier,修改在13 年前。

RE: Liferay IDE+Hook Plugin+ Expando+Custom Fields

Regular Member 帖子: 100 加入日期: 09-6-30 最近的帖子
jelmer kuperus:
See if this works for you

ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, ExpandoColumn.class.getName(),
                    ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(ecolumn.getColumnId()), RoleConstants.GUEST, new String[] { ActionKeys.VIEW, ActionKeys.UPDATE });

Hello,
Thanks for your help!
Using the method you suggested I was able to achieve my goal like this:
ExpandoColumn proxyColumn;
try {
     proxyColumn = ExpandoColumnLocalServiceUtil.addColumn(table.getTableId(), "GRID_PROXY", ExpandoColumnConstants.STRING);
} catch (final DuplicateColumnNameException dcne) {
     proxyColumn = ExpandoColumnLocalServiceUtil.getColumn(companyId, User.class.getName(),ExpandoTableConstants.DEFAULT_TABLE_NAME, "SELECTED_GW_HOSTNAME");
}
final Role user = RoleLocalServiceUtil.getRole(companyId, RoleConstants.USER);
ResourcePermissionLocalServiceUtil.setResourcePermissions(companyId, ExpandoColumn.class.getName(),
ResourceConstants.SCOPE_INDIVIDUAL, String.valueOf(proxyColumn.getColumnId()), user.getRoleId(), new String[] { ActionKeys.VIEW });
thumbnail
Andreas Müller,修改在13 年前。

RE: Liferay IDE+Hook Plugin+ Expando+Custom Fields

Junior Member 帖子: 47 加入日期: 11-1-26 最近的帖子
Can anybody tell me what this parameter 'companyId' in the addTable method means?
From the control panel I got the impression that custom fields are added to a model (user, page,...) globally, i.e. for the portal as a whole.
How come a 'companyId' must be specified to add custom fields programmatically then?
BTW, I regret very much that the official API-Docs do not offer valuable comments on anything, neither parameters nor return values nor exceptions nor even the method itself. Such best-practice comments would probably avoid many such questions in the forums!
thumbnail
Andreas Müller,修改在13 年前。

RE: Liferay IDE+Hook Plugin+ Expando+Custom Fields

Junior Member 帖子: 47 加入日期: 11-1-26 最近的帖子
One method to get the companyId is "PortalUtil.getDefaultCompanyId()".
It seems to work for my purpose of adding custom fields but I still do not understand the meaning and use of this parameter.
thumbnail
Hitoshi Ozawa,修改在11 年前。

RE: Liferay IDE+Hook Plugin+ Expando+Custom Fields

Liferay Legend 帖子: 7942 加入日期: 10-3-24 最近的帖子
This is an old thread but to close it, I'm going to reply to the unanswered question.

companyId is just the liferay's portal instance id. Liferay is a multi-tenant system and each tenant is assigned an unique companyId.
sedki jdaida,修改在7 年前。

RE: Liferay IDE+Hook Plugin+ Expando+Custom Fields

Junior Member 帖子: 25 加入日期: 16-9-8 最近的帖子
Hi ,

i have a problem in adding new column in table "expandocloumn" using java code , liferay 7 .and a hook module .

if any one have solution please tell me and thanks.