Using enums in DWR to populate select or multi-select

July 6, 2009 at 11:34 pm (Uncategorized) (, )

In case we need to population enumeration data in combo  box or multi-select widgets, in DWR (integrated on Spring), following is the approach:

1) In the spring’s applicationContext.
a) Add the method which returns the enum entity to <dwr:remote>
b) Add a dwr:convert tag of type ‘enum’ (as below)

<dwr:remote javascript="myoperations">
   <dwr:include method="getDataAsEnum"/>
   <dwr:convert type="enum"/>
</dwr:remote>

2) In the view (jsp) file, you could invoke the following javascript function with <body onload=”loadEnumeration();”>

function loadEnumeration()
{ myOperations.getDataAsEnum(callbackFunctionHandle);
};
var callbackFunctionHandle = function(data)
{   dwr.util.removeAllOptions('enum_select');
     dwr.util.addOptions('enum_select',['--Select--']);
     dwr.util.addOptions('enum_select', data);
}

Post a Comment