Monday, June 25, 2012

Multi value fields and Beans in XPages

I had an issue with multi value fields bound to bean fields in an XPages I worked on.

I got this error message on refresh:
java.lang.IllegalArgumentException: argument type mismatch

The issue turned out to be a somewhat inconsistent underlying API. When the field is empty, or has single value, it tries to set a string. When there are multiple values, it tries to set a list.

To work around the issue, have the getter return an Object, and the setter accept an object.

public Object getInputMulti() {
 return this.inputMulti;
@SuppressWarnings( "unchecked" )
public void setInputMulti( Object inputMulti ) {
 if( inputMulti == null ){
  this.inputMulti = null;
 if( inputMulti instanceof String ) {
  Vector inputNameList = new Vector();
  inputNameList.add( (String) inputMulti );
  this.inputMulti = inputNameList;  
 if( inputMulti instanceof List ) {
  this.inputMulti = (Vector) inputMulti;

You can have the translation for the setter be done in a utility method. E.g.
public static 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;

Then, for the setter:

@SuppressWarnings( "unchecked" )
public void setInputMulti( Object inputMulti ) {
  this.inputMulti = UtilityClass.translateToVector( inputMulti );

Example of multi value fields: Checkbox group, multi value fields (fields with multipleSeparator), list boxes.

Friday, June 22, 2012

Update for Enhanced Messages Control - Show "system" messages

In response to this question on the XPages Forums, I've updated the source code for my Enhanced Messages Control, so that it also shows messages not bound to controls.

The "system" messages are show above the messages from components.

Friday, June 15, 2012

Recommended tutorials for doing asynchronous processing in beans

Asynchronous processing in Java applications – leveraging those multi-cores

Using asynchronous mechanisms in Java and JavaScript for improving the user experience

Friday, June 8, 2012

Update for Enhanced Messages - Now in page order

I added a small snippet of code that sorts the messages in the order that the components are in the page.

I only had a simple page to test on, but in theory it should work for large pages with complex structure.

Original post with source code for custom control