Fórum

Liferay IDE+Hook Plugin+ Expando+Custom Fields

thumbnail
p chandru, modificado 13 Anos atrás.

Liferay IDE+Hook Plugin+ Expando+Custom Fields

New Member Postagens: 6 Data de Entrada: 19/02/10 Postagens Recentes
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, modificado 13 Anos atrás.

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

Junior Member Postagens: 64 Data de Entrada: 31/03/10 Postagens Recentes
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, modificado 13 Anos atrás.

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

New Member Postagens: 6 Data de Entrada: 24/05/10 Postagens Recentes

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, modificado 13 Anos atrás.

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

Regular Member Postagens: 100 Data de Entrada: 30/06/09 Postagens Recentes
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, modificado 13 Anos atrás.

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

Liferay Legend Postagens: 1191 Data de Entrada: 10/03/10 Postagens Recentes
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, modificado 13 Anos atrás.

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

Regular Member Postagens: 100 Data de Entrada: 30/06/09 Postagens Recentes
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, modificado 13 Anos atrás.

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

Junior Member Postagens: 47 Data de Entrada: 26/01/11 Postagens Recentes
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, modificado 13 Anos atrás.

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

Junior Member Postagens: 47 Data de Entrada: 26/01/11 Postagens Recentes
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, modificado 11 Anos atrás.

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

Liferay Legend Postagens: 7942 Data de Entrada: 24/03/10 Postagens Recentes
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, modificado 7 Anos atrás.

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

Junior Member Postagens: 25 Data de Entrada: 08/09/16 Postagens Recentes
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.