尝试使用XPages将多值字段连接到Java Bean时键入Mismatch [英] Type Mismatch when trying to connect multi-value field to Java Bean with XPages
问题描述
我有此代码:
<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>
目标是只使用一个多值名称选择器,将其值保存在Java Bean中,而不是文档字段中.因此,名称选择器指向xe:djextNameTextBox以便于删除名称,并且xe:djextNameTextBox绑定到了我的bean.
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.
使用此Java代码-
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);
}
}
对于MULTIPLE值,它似乎工作正常.但是,如果仅使用一个小号,则会出现错误:java.lang.IllegalArgumentException:参数类型不匹配
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
我认为这与XPages有关,返回多个值的数组和单个值的字符串.但是我不确定如何使它工作.
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!!
-更新-Camac链接到的博客文章中的这段代码似乎有效.
--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;
}
推荐答案
我记得遇到了同样的问题,使用此链接中的提示有助于: http://dontpanic82.blogspot.com.au/2012/06/multi-value-fields-and-beans-in-xpages.html
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
也许尝试让公共获取器和设置器使用java.lang.Object,而不是使用2个不同的对象?
maybe try having the public getter and setter use java.lang.Object, instead of having 2 different ones?
这篇关于尝试使用XPages将多值字段连接到Java Bean时键入Mismatch的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!