Type Mismatch when trying to connect a multi-valued 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 simply select a multi-valued name picker to store it in the Java Bean, and not in the document field. So the name picker points to xe: djextNameTextBox to make it easier to remove names, and 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 seems to work fine for MULTIPLE values. but if only one valule is used, I get an error: java.lang.IllegalArgumentException: argument type mismatch

I THINK that this is because XPages returns an array for multiple values ​​and String for single values. But I'm not sure how to do this.

Any advice would be appreciated! Thanks!!

- UPDATE-- This code from the blogpost Camac is associated with 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; } 
+6
source share
1 answer

I remember that I had the same problem, and using the hints from this link helped: http://dontpanic82.blogspot.com.au/2012/06/multi-value-fields-and-beans-in-xpages.html

Perhaps try using public getter and setter using java.lang.Object instead of two different ones?

+7
source

Source: https://habr.com/ru/post/956297/


All Articles