2

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.

dj_universe
  • 372
  • 5
  • 17

1 Answers1

0

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

John Dalsgaard
  • 2,797
  • 1
  • 14
  • 26
  • Well, it work's nice if you have single name picker which uses custom namePickerBean. In my case i want to have posiibility to use more than 1 picker control with my provider on my xpage with different groups selected. – dj_universe Oct 20 '16 at 07:00
  • Ok, I could not see that from your question.... but I think that could work. You just need to set the viewscope var (or bean) on focusing the relevant part of your form - so the name picker can detect which one of them you called. Don't know if you can get the "current element" (i.e. "id") - but that may also be another path to go.... – John Dalsgaard Oct 21 '16 at 07:42
  • Yes but this solution requires adding extra event that put a key value into scope. Well, ended up with adding sigle value picker that computes me labels and values. – dj_universe Oct 24 '16 at 11:33