RE: DXP 7.1- Form- Introducing a new field to capture logged in users detai

Gopal Satapathy, modified 6 Years ago. Junior Member Posts: 74 Join Date: 7/28/15 Recent Posts
Hi,

I am using DXP 7.1. Any idea on how i can have a field that will populate logged in user's details; like username?


Thanks
​​​​​​​Gopal
thumbnail
Ramalingaiah. D, modified 6 Years ago. Expert Posts: 489 Join Date: 8/16/14 Recent Posts
Hi Gopal,

Login with admin>>>contral panel>>>> configuration>>>>Custom Fields>>>>user>> right side + buttan  Click 

you can create........


Thank you 
​​​​​​​Ram
Gopal Satapathy, modified 6 Years ago. Junior Member Posts: 74 Join Date: 7/28/15 Recent Posts
Ramalingaiah. D
​​​​​​​Hi Gopal,

Login with admin>>>contral panel>>>> configuration>>>>Custom Fields>>>>user>> right side + buttan  Click 

you can create........


Thank you 
​​​​​​​Ram
Hello Ramalingaiah,

I think you got it wrong. My intension is not to create custom fields for User, but in "DXP 7.1 Liferay Form" i need to have a form field which can automatically show logged in user's details when it is added to the form.

Thanks,
Gopal
thumbnail
Ramalingaiah. D, modified 6 Years ago. Expert Posts: 489 Join Date: 8/16/14 Recent Posts
Hi Gopal ,

you can add jsp 
​​​​​​​

<%@ page import="com.liferay.portal.kernel.model.User"%>

User Name::<%User userU = themeDisplay.getUser();%><%=userU.getFullName()%>
 Email Id:<%=user.getEmailAddress()%>


Thank you
Ram
Gopal Satapathy, modified 6 Years ago. Junior Member Posts: 74 Join Date: 7/28/15 Recent Posts
Ramalingaiah. DHi Gopal ,

you can add jsp 
​​​​​​​

<%@ page import="com.liferay.portal.kernel.model.User"%>

User Name::<%User userU = themeDisplay.getUser();%><%=userU.getFullName()%>
 Email Id:<%=user.getEmailAddress()%>


Thank you
Ram

Hello Ramalingaiah,

My question is specific to "Liferay Forms" which comes with DXP 7.1. I need to know which extension point to use or if i need to create a custom field. Your suggestion is a generic one which i am aware of.

Thanks
Gopal
Gopal Satapathy, modified 6 Years ago. Junior Member Posts: 74 Join Date: 7/28/15 Recent Posts
Andrew JardineDid you try this?

https://dev.liferay.com/en/develop/tutorials/-/knowledge_base/7-1/form-field-types
Hello Andrew,

Thanks for the reply.

Yes i have been looking to the link you have provided. i am able to create a field, but am bit confused on where to write the code to set the value of that field.In mycase i will fetch the logged in user's say userid/emailaddress. Could you please advise?

Thanks
​​​​​​​Gopal
thumbnail
Andrew Jardine, modified 6 Years ago. Liferay Legend Posts: 2416 Join Date: 12/22/10 Recent Posts
Hi Gopal, 

I think yo uare supposed to use the predefined value from the FormFiteldType. I'm looking at the Liferay source and I can see that the *DDMFormFieldTemplateContextContributor adds this predefined value the parameter map​​​​​​​
@Override
public Map<string, object> getParameters(
   DDMFormField ddmFormField,
   DDMFormFieldRenderingContext ddmFormFieldRenderingContext) {

   Map<string, object> parameters = new HashMap&lt;&gt;();

   parameters.put(
      "predefinedValue",
      GetterUtil.getString(ddmFormField.getPredefinedValue(), ""));

   String predefinedValue = getPredefinedValue(
      ddmFormField, ddmFormFieldRenderingContext);

   if (predefinedValue != null) {
      parameters.put("predefinedValue", predefinedValue);
   }

   return parameters;
}

protected String getPredefinedValue(
   DDMFormField ddmFormField,
   DDMFormFieldRenderingContext ddmFormFieldRenderingContext) {

   LocalizedValue predefinedValue = ddmFormField.getPredefinedValue();

   if (predefinedValue == null) {
      return null;
   }

   return predefinedValue.getString(
      ddmFormFieldRenderingContext.getLocale());
}
</string,></string,>