Vue combinée Vue Plate Arborescence
Sujets [ Précédent | Suivant ]
toggle
Harsimrat Sin
Save additional fields data in DB of create account page
16 juillet 2013 04:44
Réponse

Harsimrat Sin

Rang: New Member

Publications: 10

Date d'inscription: 10 juillet 2013

Publications Récentes

Hi,

We have added custom fields to create account liferay page using hooks. Now we need to to save the custom fields data as well into database. Please suggest what is the appropriate way of achieving this? How should we override the service implementation for create_account jsp to store additional user information in database?

Thanks,
Harsimrat
David H Nebinger
RE: Save additional fields data in DB of create account page
16 juillet 2013 04:54
Réponse

David H Nebinger

Community Moderator

Rang: Liferay Legend

Publications: 11101

Date d'inscription: 1 septembre 2006

Publications Récentes

You do not do anything like you're thinking...

Instead you research how to use expandos, which are the appropriate way to add fields to Liferay entities.
Laxman Rana
RE: Save additional fields data in DB of create account page
16 juillet 2013 05:13
Réponse

Laxman Rana

Rang: New Member

Publications: 23

Date d'inscription: 14 juillet 2013

Publications Récentes

Hi,

Use following code snippet to save custom attribute in DB

 1private void addCustomFields(PortletConfig portletConfig, User user, ActionRequest actionRequest, ActionResponse actionResponse) {
 2
 3try {
 4Enumeration<String> attrNames = user.getExpandoBridge().getAttributeNames();
 5
 6ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
 7
 8long userClassNameId = ClassNameLocalServiceUtil.getClassNameId(User.class.getName());
 9
10ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getDefaultTable(themeDisplay.getCompanyId(), userClassNameId);
11
12while (attrNames != null && attrNames.hasMoreElements()) {
13
14String attribName = attrNames.nextElement();
15String attribValue = actionRequest.getParameter(attribName);
16
17ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil
18.getColumn(expandoTable.getTableId(), attribName);
19
20ExpandoValueLocalServiceUtil.addValue(userClassNameId,
21expandoTable.getTableId(), expandoColumn.getColumnId(),
22user.getUserId(), attribValue);
23}
24} catch (PortalException e) {
25logger.error("PortalException Occured", e);
26
27} catch (SystemException e) {
28logger.error("System exception Occured", e);
29
30} catch (Exception e) {
31logger.error("Exception Occured", e);
32}
33}


Thanks,
Laxman Rana
Surekha Technologies
www.surekhatech.com
Tonu Sri
RE: Save additional fields data in DB of create account page
16 juillet 2013 07:44
Réponse

Tonu Sri

Rang: Regular Member

Publications: 196

Date d'inscription: 15 avril 2011

Publications Récentes

Hi Harsimrat,

You can add custom fields for User through control panel and then modify your create_account.jsp using Hook by adding at last:

<liferay-ui:custom-attribute
className="<%= User.class.getName() %>"
classPK="<%= 0 %>"
editable="<%= true %>"
label="<%= true %>"
name="your-custom-field"
/>

Please make sure you have given proper permission to custom field for Guest User.

Thanks:
Tonu
Harsimrat Sin
RE: Save additional fields data in DB of create account page
21 juillet 2013 23:52
Réponse

Harsimrat Sin

Rang: New Member

Publications: 10

Date d'inscription: 10 juillet 2013

Publications Récentes

Thanks for the solution. I have been able to call strutportletaction on click of save button in create_account jsp and save the custom field in expando table. Now the issue is that i dont get user id of the user in process action method as i guess user is not already created at that time.

Please suggest how can i get user id of created user in strutportlet action method and also add the user to particular organization as right now i just add custom field info into expando table?

Thanks
Harsimrat