use of org.jaffa.flexfields.FlexCriteriaParam in project jaffa-framework by jaffa-projects.
the class FlexCriteriaBeanConverter method convertOutbound.
/* (non-Javadoc)
* @see org.directwebremoting.Converter#convertOutbound(java.lang.Object, org.directwebremoting.OutboundContext)
*
* Copied from BasicObjectConverter
*
* Added custom code to convert the flexCriteriaParams array as root level properties on the javascript object.
*/
@Override
public OutboundVariable convertOutbound(Object data, OutboundContext outctx) throws MarshallException {
FlexCriteriaBean flexCriteriaBean = (FlexCriteriaBean) data;
// Where we collect out converted children
Map ovs = new TreeMap();
// We need to do this before collecing the children to save recurrsion
ObjectOutboundVariable ov = new ObjectOutboundVariable(outctx);
outctx.put(flexCriteriaBean, ov);
try {
Map properties = getPropertyMapFromObject(flexCriteriaBean, true, false);
for (Iterator it = properties.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String name = (String) entry.getKey();
Property property = (Property) entry.getValue();
// CUSTOM CODE: Special handling for flexCriteriaParams
if ("flexCriteriaParams".equals(name)) {
FlexCriteriaParam[] flexCriteriaParams = flexCriteriaBean.getFlexCriteriaParams();
if (flexCriteriaParams != null) {
for (FlexCriteriaParam flexCriteriaParam : flexCriteriaParams) {
// Instead of the formatted value returned by flexCriteriaParam.getValue(),
// use the original value returned by the flexCriteriaBean. This will ensure
// standard DWR handling for those value.
Object value = flexCriteriaBean.get(flexCriteriaParam.getName());
if (value != null) {
// Added check to exclude null fields
OutboundVariable nested = getConverterManager().convertOutbound(value, outctx);
ovs.put(flexCriteriaParam.getName(), nested);
}
}
}
} else {
Object value = property.getValue(flexCriteriaBean);
if (value != null) {
// Added check to exclude null fields
OutboundVariable nested = getConverterManager().convertOutbound(value, outctx);
ovs.put(name, nested);
}
}
}
// Add the className to the object
if (flexCriteriaBean != null) {
String className = flexCriteriaBean.getClass().getSimpleName();
OutboundVariable var = getConverterManager().convertOutbound(className, outctx);
ovs.put("className", var);
}
} catch (MarshallException ex) {
throw ex;
} catch (Exception ex) {
throw new MarshallException(flexCriteriaBean.getClass(), ex);
}
ov.init(ovs, getJavascript());
return ov;
}
Aggregations