掲示板

Liferay IDE+Hook Plugin+ Expando+Custom Fields

thumbnail
13年前 に p chandru によって更新されました。

Liferay IDE+Hook Plugin+ Expando+Custom Fields

New Member 投稿: 6 参加年月日: 10/02/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
13年前 に Georaj K によって更新されました。

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

Junior Member 投稿: 64 参加年月日: 10/03/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
13年前 に Francisco Aranda によって更新されました。

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

New Member 投稿: 6 参加年月日: 10/05/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
13年前 に Baptiste Grenier によって更新されました。

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

Regular Member 投稿: 100 参加年月日: 09/06/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
13年前 に jelmer kuperus によって更新されました。

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

Liferay Legend 投稿: 1191 参加年月日: 10/03/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
13年前 に Baptiste Grenier によって更新されました。

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

Regular Member 投稿: 100 参加年月日: 09/06/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
13年前 に Andreas Müller によって更新されました。

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

Junior Member 投稿: 47 参加年月日: 11/01/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
13年前 に Andreas Müller によって更新されました。

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

Junior Member 投稿: 47 参加年月日: 11/01/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
11年前 に Hitoshi Ozawa によって更新されました。

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

Liferay Legend 投稿: 7942 参加年月日: 10/03/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.
7年前 に sedki jdaida によって更新されました。

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

Junior Member 投稿: 25 参加年月日: 16/09/08 最新の投稿
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.