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

╄→尐↘猪︶ㄣ 提交于 2021-02-16 12:56:41

问题


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;
}

回答1:


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?



来源:https://stackoverflow.com/questions/19460844/type-mismatch-when-trying-to-connect-multi-value-field-to-java-bean-with-xpages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!