留言板

How to create hidden expando column?

thumbnail
Cameron McBride,修改在12 年前。

How to create hidden expando column?

Expert 帖子: 269 加入日期: 11-2-8 最近的帖子
If you use the UI to create custom fields for users you can select for the property to be hidden, I want to do this programatically. I can add and get a new custom field with this:
		try { 
			ExpandoColumnLocalServiceUtil.addColumn( 
					table.getTableId(), 
					"accountApproved", 
					ExpandoColumnConstants.INTEGER); 
		} catch (Exception e) {
				System.out.println("accountApproved already exists!");
		}  

		ExpandoColumn column = null;
		try {
			column = ExpandoColumnLocalServiceUtil.getColumn(
					table.getTableId(),
					"accountApproved");
		} catch (Exception e) {
			System.out.println("error getting column");
		}


The problem is trying to set that hidden property. I see an ExpandoColumnConstants.PROPERTY_HIDDEN but do not know how to set it. I have tried the following:
		if (column != null) {
			System.out.println("Settings: "+column.getTypeSettings());
			column.setTypeSettings(ExpandoColumnConstants.PROPERTY_HIDDEN);
			System.out.println("Settings: "+column.getTypeSettings());
			
			try {
				ExpandoColumnLocalServiceUtil.updateExpandoColumn(column);
			} catch (Exception e) {
				System.out.println("Error setting settings");
			}
		} else {
			System.out.println("column is null");
		}


When I get the column I can see now that it is set to hidden, but there is no effect. The field still shows to the end user and in the custom fields UI I see it is set to false for Hidden.
thumbnail
Cameron McBride,修改在12 年前。

RE: How to create hidden expando column? (答复)

Expert 帖子: 269 加入日期: 11-2-8 最近的帖子
Solved, this did the trick!

			UnicodeProperties up = new UnicodeProperties();
			up.put(ExpandoColumnConstants.PROPERTY_HIDDEN, "true");
			column.setTypeSettingsProperties(up);
			
			try {
				ExpandoColumnLocalServiceUtil.updateExpandoColumn(column);
			} catch (Exception e) {
				System.out.println("Error setting settings");
			}
thumbnail
David H Nebinger,修改在12 年前。

RE: How to create hidden expando column?

Liferay Legend 帖子: 14914 加入日期: 06-9-2 最近的帖子
Doesn't it just feel grand when you can solve your own problem? I knew that's when I turned the corner on Liferay...

Thanks for sharing the result of your labor, Cameron!