6

I have this code:

<xe:formTable id="formTable1" formTitle="User Roles">
    <xe:formRow id="formRow1" label="Category Admin">
        <xe:djextNameTextBox id="edtCatAdmin" multipleSeparator="," value="#{exhibitorInfo.categoryAdmin}" />
        <xe:namePicker id="namePicker1" for="edtCatAdmin">
            <xe:this.dataProvider>
                <xe:namePickerAggregator>
                    <xe:this.dataProviders>
                        <xe:dominoNABNamePicker addressBookSel="first" groups="false" people="true" />
                        <xe:dominoViewNamePicker labelColumn="mailinName" viewName="lkp_MailIn" label="Group Mailboxes" />
                    </xe:this.dataProviders>
                </xe:namePickerAggregator>
            </xe:this.dataProvider>
        </xe:namePicker>
    </xe:formRow>
</xe:formTable>

The goal is to just have a multi-value name picker save it's valies in a Java Bean rather then a document field. So the name picker points to a xe:djextNameTextBox to make it easy to remove the names and the xe:djextNameTextBox is bound to my bean.

Using this Java Code -

public void setCategoryAdmin(ArrayList<String> categoryAdmin) {
    System.out.println("Set CategoryAdmin - List");
    this.categoryAdmin = categoryAdmin;
}


public void setCategoryAdmin(String categoryAdmin) { 
    System.out.println("Set CategoryAdmin - String");
    if (!this.isBlankString(categoryAdmin)) {
        ArrayList<String> al = new ArrayList<String>();
        al.add(categoryAdmin);
        this.setCategoryAdmin(al);
    }
}

It appears to work fine for MULTIPLE values. but if only a single valule is used I get an error: java.lang.IllegalArgumentException: argument type mismatch

I THINK this has to do with XPages returning an Array for multiple values and a String for single values. But I'm not sure how to make this work.

Any advice would be appreciated! Thanks!!

--UPDATE-- This code from the blogpost that Camac linked to seems to work.

public Object getCategoryAdmin() {
    System.out.println("getCategoryAdmin");
    return this.categoryAdmin;
}


@SuppressWarnings("unchecked")
public void setCategoryAdmin( Object inputMulti ) {
      this.categoryAdmin = this.translateToVector( inputMulti );
    }

@SuppressWarnings("unchecked")
public Vector translateToVector( Object object ){
 if( object instanceof String ){
  Vector list = new Vector();
  list.add( object );
  return list;
 }

 if( object instanceof List ){
  return (Vector)object;
 }

 return null;
}
David Leedy
  • 3,583
  • 18
  • 38
  • 3
    Looks like XPage does not understand bean method overloading and always picks the one with list argument. Camac's answer is the solution. Would be nice if XPage always returned String or List... – Panu Haaramo Oct 19 '13 at 06:17
  • 2
    @PanuHaaramo: This is a JSF specific issue. Only the first Public Setter is used because EL resolves a method by calling *Class* . *getMethods()* and uses the first public method found with the searched name. Another approach is to have a public method with handles an Object and calls the private setter. Then overloading works as expected. – Sven Hasselbach Oct 19 '13 at 17:03
  • How annoying is this xpages situation ! you saved my day, thanks. Another answer I was considering (but haven't implemened) was to always add a blank value to the end of the submitted string somehow,, so that it's always an array. then have your code ignore blanks. Haven't tried it though. – user2808054 Jan 28 '16 at 15:58

1 Answers1

7

i remember having the same problem and using tips from this link helped: http://dontpanic82.blogspot.com.au/2012/06/multi-value-fields-and-beans-in-xpages.html

maybe try having the public getter and setter use java.lang.Object, instead of having 2 different ones?

Cameron Gregor
  • 1,460
  • 7
  • 8