Xpages - How to add a param to custom beanNamePicker for xe:namePicker control

212 Views Asked by At

I need a names control that allows users to select people from one group only. I want to have some possibility to add some param with the group name.

I have the following namepicker

<xe:namePicker id="namePicker1"
                for="myControlId" dialogTitle="Select person">
        <xe:this.dataProvider>
            <xe:beanNamePicker dataBean="mybean.BeanPickerGroupMembers" loaded="true">
                </xe:beanNamePicker>
    </xe:this.dataProvider>
</xe:namePicker>

My bean looks like this:

public class BeanPickerGroupMembers implements INamePickerData {

    public BeanPickerGroupMembers() {}

    @Override
    public IPickerResult readEntries(IPickerOptions options) {
        List<IPickerEntry> entries = new ArrayList<IPickerEntry>();

        //do something according to desired group name

        return new SimplePickerResult(entries, -1);     

    }   

    @Override
    public List<IPickerEntry> loadEntries(Object[] ids, String[] attributeNames) {return null;}

    @Override
    public String[] getSourceLabels() {return null;}

    @Override
    public boolean hasCapability(int capability) {return false;}
}

How can I pass some group param to my bean from namePicker? I know that I may use some scope variables but I want to have posiibility to use more than 1 picker control with my provider with different groups selected.

1

There are 1 best solutions below

3
John Dalsgaard On

I have had a similar requirement. I could not find a way to add an argument to the name picker - but I added the "filter value" to a viewscope variable - and just checked for it in my name picker code in the readEntries() method.

So where you have // Do something.... I have this code:

if (null != ClubAdminBean.getCurrentInstance().getLocationType()) {
    locationType = ClubAdminBean.getCurrentInstance().getLocationType(); 
    System.out.println("locationType=" + locationType);
}

... and in my ClubAdminBean I have implemented this method to get the bean:

public static ClubAdminBean getCurrentInstance() {
    // This is a neat way to get a handle on the instance of this bean in the application scope from other Java code...
    FacesContext context = FacesContext.getCurrentInstance();
    ClubAdminBean bean = (ClubAdminBean) context.getApplication().getVariableResolver().resolveVariable(context, "ClubAdmin");
    return bean;
}

which I tend to implement in all my beans for easy retrieval :-)

Obviously, you don't need to have a bean - but could also just have a single value stored in a viewscope variable.

/John