1

I want to create a new field in XPages to do the same thing like a Names field from a form. TY

4
  • You need to use a converter to show the value in abbreviated format. Google for examples. Oct 11, 2013 at 11:46
  • 2
    4 great answers so far. Some clarification: does your name have to be a Names field? Because then some of the answers can not be used Oct 12, 2013 at 20:20
  • Yes it has to be a Names type field to do exactley the thing a names field does in normal case"open the namesnsf to select them" like for an e-mail. I am a noob in this thing!
    – MihaiRO
    Oct 15, 2013 at 8:35
  • MihaiRO, a names field can do a lot. What is the functionality you are looking for? My example is one that I use frequently to give similar functionality to the name lookup. It also prevents the user from typing in names that do not exist in the addressbook. Oct 22, 2013 at 0:31

4 Answers 4

2

Use the Extension Library's Name picker, and the DOJO form control's name text box. The name picker grabs from the directory and the name field displays the names.

Here is an example.

<xe:namePicker id="namePicker1"
for="djextNameTextBox1">
<xe:this.dataProvider>
<xe:dominoNABNamePicker groups="false"
    nameList="peopleByLastName">
</xe:dominoNABNamePicker>
</xe:this.dataProvider>
</xe:namePicker>
        <xe:djextNameTextBox id="djextNameTextBox1"
            value="#{document1.<FIELDNAME>}">
        </xe:djextNameTextBox>
1

You can use this simple SSJS code snippet to create Names field in your document.

var n:NotesItem = doc.replaceItemValue("Field1", "Value1");
n.setNames(true);
1

How about to use a java bean background? Create a java bean called NameConverter...

package converters;

import java.util.ArrayList;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import lotus.domino.Name;
import lotus.domino.NotesException;
import com.ibm.xsp.model.domino.DominoUtils;

public class NameConverter implements Converter {

private Name createName(String name) {
    Name n = null;

    try {
        n = DominoUtils.getCurrentSession().createName(name);
    } catch (NotesException e) {
        e.printStackTrace();
    }

    return n;
}

public Object getAsObject(FacesContext context, UIComponent component, String value) {
    String[] names = value.split(",");
    Name name = null;
    ArrayList<String> tmpNames = new ArrayList<String>();

    for (int i = 0; i <= names.length - 1; i++) {
        name = this.createName(names[i].trim());

        try {
            tmpNames.add(name.getAbbreviated());
        } catch (NotesException e) {
            e.printStackTrace();
        }
    }

    return tmpNames.toString().replace("[", "").replace("]", "");
}

public String getAsString(FacesContext context, UIComponent component, Object value) {
    String[] names = value.toString().split(",");
    Name name = null;
    ArrayList<String> tmpNames = new ArrayList<String>();

    for (int i = 0; i <= names.length - 1; i++) {
        name = this.createName(names[i].trim());

        try {
            tmpNames.add(name.getAbbreviated());
        } catch (NotesException e) {
            e.printStackTrace();
        }
    }

    return tmpNames.toString().replace("[", "").replace("]", "");
}
}

Register your converter in faces-config.xml...

<converter>
    <converter-id>nameConverter</converter-id>
    <converter-class>converters.NameConverter</converter-class>
</converter>

And then create a field with a simple converter in your xPage...

<xp:inputText id="userName" style="width:300px">
    <xp:this.converter>
        <xp:converter converterId="nameConverter" />
    </xp:this.converter>
</xp:inputText>

Simple as hell and perfectly scalable. Enjoy, JiKra

2
  • What are the advantages of your approach? Oct 11, 2013 at 23:33
  • 1
    Better scalability and separation of business logic and views. If he needs a picklist to grab names from NAB, your solution is better, but if he needs only a behavior of the names field (translation of names into abbreviated form), my solution is good enough.
    – JiKra
    Oct 12, 2013 at 9:36
0

custom converter is the best solution: getAsObject:@Name("[Cannonicalize]",@Explode(vlaue)) - the saved value getAsString:@Implode(@Name("[Abbreviate]",value),",") - value in web

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.