Reputation: 5923
I have followed all the steps of this guide to add a custom field in Liferay, and able to get the label and text box to enter the data on the account details page (html\portlet\users_admin\user\details.jsp
).
My code is:
<div class="exp-ctrl-holder">
<liferay-ui:custom-attribute
className="<%= User.class.getName() %>"
classPK="<%= 0 %>"
editable="<%= true %>"
label="<%= true %>"
name="Bio"
/>
</div>
The problem is that when i save its not populating the field on page. When i write anything in my "Bio: input" and i click on save, the page loads and then what I had written is cleared. Why? What's missing?
Thanks,
Upvotes: 0
Views: 706
Reputation: 11698
This is incorrect: classPK="<%= 0 %>"
.
classPK
is basically the user's primary-key i.e. userId
. So while adding the User classPK
will be zero since there is no user created yet, but when you have saved or are updating, then the User would have a classPK and the custom-field Bio
you are saving will be associated with that userId
.
Instead you need to use
`classPK="<%= (selUser != null) ? selUser.getUserId() : 0 %>"
so that when you save and the User is updated, the Users custom-field would be populated.
Upvotes: 1