All blog posts, code samples and downloads licensed under Apache License 2.0.
Close

Extension Library Namepicker issue - finally worked-around

Oliver Busse on 02/26/2014 22:11:31 CET, filed under XSP Java 

I encountered a problem using the Extlib's namepicker bound to readers and authors fields: the names you pick are stored in abbreviated manner into the field. The result is that those fields are stored in the document but theyx have no impact. Even if you have those names in the fields one can not see (or edit) those documents as the values are inappropiate.

As long as the namepicker is not able to be configured in how to store the values in the corresponding field you may have a look at my solution.

I coded a managed bean with one method to be called in the postSaveDocument event of your datasource on your XPage.

package org.openntf.filesilo;
import java.io.Serializable;
import java.util.Vector;
import lotus.domino.Document;
import lotus.domino.Session;
import com.ibm.xsp.extlib.util.ExtLibUtil;

public class RightsManagement implements Serializable {
	private static final long serialVersionUID = 8157811105680678241L;
	public RightsManagement() {
	}
	/**
	 * Calculate all name fields to canonical form
	 * 
	 * @param doc
	 */
	@SuppressWarnings("unchecked")
	public void setNames(Document doc) {
		Session session = ExtLibUtil.getCurrentSession();
		Vector names = null;
		// item names as array
		String items[] = { "fileAdmin", "fileReaders", "fileAuthors" };
		try {
			for (String item : items) {
				names = session.evaluate("@Name([Canonicalize]; " + item + ")", doc);
				doc.replaceItemValue(item, names);
			}
			doc.save();

		} catch (Exception e) {
		}
	}
}

<!-- faces-config -->
<managed-bean>
	<managed-bean-name>rights</managed-bean-name>
	<managed-bean-class>org.openntf.filesilo.RightsManagement</managed-bean-class>
	<managed-bean-scope>view</managed-bean-scope>
</managed-bean>

<!-- usage on your XPage -->
<xp:this.postSaveDocument>
	<![CDATA[#{javascript:// canonicalize
		rights.setNames(currentDocument.getDocument());
</xp:this.postSaveDocument>

As the bean is view-scoped you don't have to bother to recycle the document object.


Tagged with xpages extlib bug domino access