Fórum

Where should I initialize Expando Columns?

José A. Benítez, modificado 12 Anos atrás.

Where should I initialize Expando Columns?

New Member Postagens: 20 Data de Entrada: 07/04/11 Postagens Recentes
Hello everybody!

Lately I have needed to recourse to using Expando Columns to store the creatorId and the creatorName of Journal Articles, as the current userId and userName store the values of the user who last modified the articles.

Although I have reached a solution, we would like to improve it. Currently, the function that creates these colums is called in the doGetDocument method of JournalArticle extended class. I know it works and only creates these colums the first time, but I am trying to tackle where to locate the next piece of code so it would execute just in the startup:

	protected void setupExpandosJornalArticle(long companyId) throws Exception {
		ExpandoTable table = null;
		try{
			table = ExpandoTableLocalServiceUtil.addTable(
			companyId, JournalArticle.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME);
		}
		catch (DuplicateTableNameException dtne){
			table = ExpandoTableLocalServiceUtil.getTable(companyId, JournalArticle.class.getName(), ExpandoTableConstants.DEFAULT_TABLE_NAME);
		}
		String column1 = Field.CREATOR_USER_ID;
		String column2 = Field.CREATOR_USER_NAME;
		
		try{
			ExpandoColumnLocalServiceUtil.addColumn(table.getTableId(),column1, ExpandoColumnConstants.STRING);
		}catch (DuplicateColumnNameException dcne){
			
		}
		
		try{
			ExpandoColumnLocalServiceUtil.addColumn(table.getTableId(),column2, ExpandoColumnConstants.STRING);
		}catch (DuplicateColumnNameException dcne){
			
		}

	} 


Any kind of help would be welcomed.

Thank you in advance.
thumbnail
jelmer kuperus, modificado 12 Anos atrás.

RE: Where should I initialize Expando Columns?

Liferay Legend Postagens: 1191 Data de Entrada: 10/03/10 Postagens Recentes
Create a startup action from a hook eg :

public StartupAction extends SimpleAction {
    public void run(String[] ids) throws ActionException {
       // your code here
    }
}


liferay-hook.xml :

<!--?xml version="1.0" encoding="UTF-8"?-->

<hook>
	<portal-properties>portal.properties</portal-properties>
</hook>


portal.properties :

application.startup.events=com.yourcompany.hook.actions.StartupAction 
José A. Benítez, modificado 12 Anos atrás.

RE: Where should I initialize Expando Columns?

New Member Postagens: 20 Data de Entrada: 07/04/11 Postagens Recentes
Thank you very much!