Forums de discussion

Save additional fields data in DB of create account page

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

Save additional fields data in DB of create account page

New Member Publications: 10 Date d'inscription: 10/07/13 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
thumbnail
David H Nebinger, modifié il y a 10 années.

RE: Save additional fields data in DB of create account page

Liferay Legend Publications: 14916 Date d'inscription: 02/09/06 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, modifié il y a 10 années.

RE: Save additional fields data in DB of create account page

New Member Publications: 23 Date d'inscription: 15/07/13 Publications récentes
Hi,

Use following code snippet to save custom attribute in DB

private void addCustomFields(PortletConfig portletConfig, User user, ActionRequest actionRequest, ActionResponse actionResponse) {

try {
Enumeration<string> attrNames = user.getExpandoBridge().getAttributeNames();

ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

long userClassNameId = ClassNameLocalServiceUtil.getClassNameId(User.class.getName());

ExpandoTable expandoTable = ExpandoTableLocalServiceUtil.getDefaultTable(themeDisplay.getCompanyId(), userClassNameId);

while (attrNames != null &amp;&amp; attrNames.hasMoreElements()) {

String attribName = attrNames.nextElement();
String attribValue = actionRequest.getParameter(attribName);

ExpandoColumn expandoColumn = ExpandoColumnLocalServiceUtil
.getColumn(expandoTable.getTableId(), attribName);

ExpandoValueLocalServiceUtil.addValue(userClassNameId,
expandoTable.getTableId(), expandoColumn.getColumnId(),
user.getUserId(), attribValue);
}
} catch (PortalException e) {
logger.error("PortalException Occured", e);

} catch (SystemException e) {
logger.error("System exception Occured", e);

} catch (Exception e) {
logger.error("Exception Occured", e);
}
}
</string>


Thanks,
Laxman Rana
Surekha Technologies
www.surekhatech.com
Harsimrat Sin, modifié il y a 10 années.

RE: Save additional fields data in DB of create account page

New Member Publications: 10 Date d'inscription: 10/07/13 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
thumbnail
Tonu Sri, modifié il y a 10 années.

RE: Save additional fields data in DB of create account page

Regular Member Publications: 197 Date d'inscription: 15/04/11 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