Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type Mismatch when trying to connect multi-value field to Java Bean with XPages

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;
}
like image 985
David Leedy Avatar asked Oct 19 '13 00:10

David Leedy


1 Answers

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?

like image 129
Cameron Gregor Avatar answered Oct 23 '22 11:10

Cameron Gregor