Forums de discussion

custom attribute of type checkbox

Gaurav Talwar, modifié il y a 14 années.

custom attribute of type checkbox

New Member Publications: 13 Date d'inscription: 05/04/10 Publications récentes
Hi All,

I want to add a new field of type checkbox on the create account page. I can't find checkbox type when creating custom attributes. Any ideas how to achieve this?

Thank you
Gaurav
thumbnail
Nidhi Singh, modifié il y a 14 années.

RE: custom attribute of type checkbox

Regular Member Publications: 155 Date d'inscription: 07/10/09 Publications récentes
Hi,

you have to modify create_account.jsp.
In LR 5.2.3, custum attribute is provided only for users and organization.

Thanks
Nidhi Singh
thumbnail
Amos Fong, modifié il y a 14 années.

RE: custom attribute of type checkbox

Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
Hi Gaurav,

The best I can figure it out is to use type Boolean and override page.jsp for custom_attribute to output a checkbox instead of a select box
Gaurav Talwar, modifié il y a 14 années.

RE: custom attribute of type checkbox

New Member Publications: 13 Date d'inscription: 05/04/10 Publications récentes
Thanks for the replies!

But from what Nidhi is saying i understand that a custom attribute cannot be added on "create account" page as it can only be viewed by guests. Correct me if i am wrong!

Thank you
Gaurav
Gaurav Talwar, modifié il y a 13 années.

RE: custom attribute of type checkbox

New Member Publications: 13 Date d'inscription: 05/04/10 Publications récentes
Hi Amos,

I have managed to get a select drop down with boolean values. Its in the format:


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


But i can't understand how a select is getting generated from above code.. Can you point me to some documentation or tell me how would i convert the above custom attribute code to checkbox?

Thanks heapsemoticon
Gaurav
thumbnail
Amos Fong, modifié il y a 13 années.

RE: custom attribute of type checkbox

Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
Yes, it is generated in /html/taglib/ui/custom_attribute/page.jsp

You can use a jsp hook to override it.
Gaurav Talwar, modifié il y a 13 années.

RE: custom attribute of type checkbox

New Member Publications: 13 Date d'inscription: 05/04/10 Publications récentes
Thanks Amos.

For the benefit of others, this is what i did:

replace the following in page.jsp


<select id="<%= randomNamespace %><%= escapedName %>" name="<portlet:namespace />ExpandoAttribute(<%= escapedName %>)">
							<option <%="curValue" ? "selected" : "" %> value="1"&gt;</option>
							<option <%="!curValue" ? "selected" : "" %> value="0"&gt;</option>
						</select>


by


<input id="<%= randomNamespace %><%= escapedName %>" type="checkbox" name="<portlet:namespace />ExpandoAttribute(<%= escapedName %>)" value="1" <%="curValue" ? "checked" : ""%>
						/&gt;


Thanks
Gaurav Talwar
thumbnail
Mati Khan, modifié il y a 13 années.

RE: custom attribute of type checkbox

Junior Member Publications: 25 Date d'inscription: 01/11/10 Publications récentes
Hi Gaurav,

I tried to override page.jsp and add your code for input-checkbox instead of select, but it doesn't save correct value, if the box is checked or not it is saving default value in expando column.



Can you please explain how you came to fix it?
Temire Emmanuel, modifié il y a 7 années.

RE: custom attribute of type checkbox

New Member Publications: 2 Date d'inscription: 21/02/17 Publications récentes
But It does not return the correct value. whether checked or not the default value is always returned
Pallavi Havale, modifié il y a 7 années.

RE: custom attribute of type checkbox

New Member Publications: 9 Date d'inscription: 28/08/15 Publications récentes
Hi Amos Fong,
Could you please tell me where can I find out the page.jsp file in liferay 7.
In Liferay 7 Hook I checked with all jars ,but there also I couldn't find out the page.jsp.

Thanks In Advance,
Pallavi
thumbnail
Amos Fong, modifié il y a 7 années.

RE: custom attribute of type checkbox

Liferay Legend Publications: 2047 Date d'inscription: 07/10/08 Publications récentes
I believe it's in foundation/expando/expando-taglib
thumbnail
sunil G, modifié il y a 11 années.

RE: custom attribute of type checkbox

New Member Publications: 6 Date d'inscription: 09/12/11 Publications récentes
Hi Amos,


I want a custom attribute which loads all organizations(Drop Down) in user profile. Can u suggest any idea.

Thanks in advance,
Sunil
Hiral Barot, modifié il y a 11 années.

RE: custom attribute of type checkbox

New Member Publications: 17 Date d'inscription: 03/01/12 Publications récentes
You can achieve this by following code snippet :

User user = PortalUtil.getUser(renderRequest);
List<Organization> allOrg = OrganizationLocalServiceUtil.getOrganizations(-1, -1);
String[] str = new String[allOrg.size()];
for (int i = 0; i < allOrg.size(); i++) {
str= allOrg.get(i).getName();

}
user.getExpandoBridge().setAttributeDefault("test",str); // where "test" is your custom attribute name