Forums de discussion

Modifying create account page to add custom fields

Harsimrat Sin, modifié il y a 10 années.

Modifying create account page to add custom fields

New Member Publications: 10 Date d'inscription: 10/07/13 Publications récentes
Recently i created a hook to override create account page functionality and add custom fields info in expando table on click of save button to create the user

Following are the steps that i followed

1. Add the following code to liferay-hook.xml

<struts-action>
<struts-action-path>/login/create_account</struts-action-path>
<struts-action-impl>com.liferay.sample.hook.action.CreateAccountStrutsPortletAction</struts-action-impl>
</struts-action>

2. Create the package "com.liferay.sample.hook.action" and add CreateAccountStrutsPortletAction class that implements BaseStrutsPortletAction

3. Override the ProcessAction method in the class and call the below code to create the user

originalStrutsPortletAction.processAction(
originalStrutsPortletAction, portletConfig, actionRequest,
actionResponse);

4. Get the user id of the created user using following code

long userid = UserLocalServiceUtil.getUserIdByEmailAddress(themeDisplay.getCompanyId(), actionRequest.getParameter("emailAddress"));

5. Create expando table to hold custom field info and user id mapping for retrevial post login

ExpandoTable table = ExpandoTableLocalServiceUtil.addTable(
themeDisplay.getCompanyId(), userClassNameId, "UserAddOn");

ExpandoColumn col2 = ExpandoColumnLocalServiceUtil.addColumn(tableId, "Organization", ExpandoColumnConstants.LONG_ARRAY);

ExpandoValueLocalServiceUtil.addValue(userClassNameId,
tableId, col2.getColumnId(), classpk, addons.getOrganization());

This will create the custom field "Organization" in expando table and add the value. The key thing to note here is that classpk will be the userid of the user in order to establish the user and custom field mapping so that custom field info for a particular user can be retrieved later through user id.

Hope this will help people implementing hook to override the create account page functionality and looking to add custom fields to the page. I am putting it together here so that you find solution at one place as info is scattered in various forums for implementing this.

Thanks
Harsimrat
thumbnail
Umer Sayeed, modifié il y a 10 années.

RE: Modifying create account page to add custom fields

Junior Member Publications: 51 Date d'inscription: 08/08/12 Publications récentes
Hi Harsimrat,

can u explain how to do with expando?
Harsimrat Sin, modifié il y a 10 années.

RE: Modifying create account page to add custom fields

New Member Publications: 10 Date d'inscription: 10/07/13 Publications récentes
Hi Umer,
Not sure if i understand your question correctly. Are you talking about how to retrieve the custom fields info from expando table on user login?

ExpandoTable expandoTable;
long classpk = userId;
long tableId = 0;
ExpandoColumn col = null;
expandoTable = ExpandoTableLocalServiceUtil.getTable(themeDisplay.getCompanyId(), userClassNameId, "UserAddOn");
tableId = expandoTable.getTableId();
col = ExpandoColumnLocalServiceUtil.getColumn(expandoTable.getTableId(), "Organization");
ExpandoValue expandoValue = ExpandoValueLocalServiceUtil.getValue(expandoTable.getTableId(), col.getColumnId(), classpk);
orgName = expandoValue.getData();

I hope you find this helpful.

Thanks,
Harsimrat
thumbnail
Umer Sayeed, modifié il y a 10 années.

RE: Modifying create account page to add custom fields

Junior Member Publications: 51 Date d'inscription: 08/08/12 Publications récentes
Hi ,
Harsimrat Thanks for replying emoticon

What u have explained above is very helpful, and one more question is how to create Expando Table,columns rows and how to do map with other liferay exiting table???
Harsimrat Sin, modifié il y a 10 années.

RE: Modifying create account page to add custom fields

New Member Publications: 10 Date d'inscription: 10/07/13 Publications récentes
I have already explained that above in this thread

//Create Expando Table
ExpandoTable table = ExpandoTableLocalServiceUtil.addTable(
themeDisplay.getCompanyId(), userClassNameId, "UserAddOn");

//Add column "Organization" to Expando Table
ExpandoColumn col2 = ExpandoColumnLocalServiceUtil.addColumn(tableId, "Organization", ExpandoColumnConstants.LONG_ARRAY);

//Add value to column
ExpandoValueLocalServiceUtil.addValue(userClassNameId,
tableId, col2.getColumnId(), classpk, addons.getOrganization());

For mapping Expando to existing table for instance "user_" you will map the userid column value of "user_" table with the classpk value of the Expando table
So in above case, expando table will create a row with organization name and userid which is defined through classpk and then this userid can be used to fetch the organization name
thumbnail
Umer Sayeed, modifié il y a 10 années.

RE: Modifying create account page to add custom fields

Junior Member Publications: 51 Date d'inscription: 08/08/12 Publications récentes
Thanks Harsimrat, this wt m searcing. emoticon, its very helpful
sedki jdaida, modifié il y a 7 années.

RE: Modifying create account page to add custom fields

Junior Member Publications: 25 Date d'inscription: 08/09/16 Publications récentes
Hi ,
i need a help i need to fin the page jsp of create account : in liferay 6.2 there is a page named "create_account.jsp" and i don't find the page of creating account in liferay 7