Search in sources :

Example 1 with FlexCriteriaParam

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;
}
Also used : OutboundVariable(org.directwebremoting.extend.OutboundVariable) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) TreeMap(java.util.TreeMap) MarshallException(org.directwebremoting.extend.MarshallException) ObjectOutboundVariable(org.directwebremoting.dwrp.ObjectOutboundVariable) MarshallException(org.directwebremoting.extend.MarshallException) Iterator(java.util.Iterator) FlexCriteriaParam(org.jaffa.flexfields.FlexCriteriaParam) Map(java.util.Map) TreeMap(java.util.TreeMap) Property(org.directwebremoting.extend.Property) FlexCriteriaBean(org.jaffa.flexfields.FlexCriteriaBean)

Aggregations

Iterator (java.util.Iterator)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ObjectOutboundVariable (org.directwebremoting.dwrp.ObjectOutboundVariable)1 MarshallException (org.directwebremoting.extend.MarshallException)1 OutboundVariable (org.directwebremoting.extend.OutboundVariable)1 Property (org.directwebremoting.extend.Property)1 FlexCriteriaBean (org.jaffa.flexfields.FlexCriteriaBean)1 FlexCriteriaParam (org.jaffa.flexfields.FlexCriteriaParam)1