Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    custom "multiple" editor

    SC_SNAPSHOT-2010-10-24/EVAL Deployment

    Hi,

    We have an ArrayList of custom objects returning from the server.
    We have implemented a SimpleType and a custom editor which extends SelectItem (see below).

    The idea is to show all the id's of a related object (in a user-readable format) where the current object is linked to (via PICKLIST). For example all books of a certain author.

    The problem I'm facing is that I'm not able to get the data into the custom editor itself. I mean the data is retrieved (see RPC call) and the editor is able to display the correct value after the fetch... but when I click the editor open, no values appear in the drop down list. Not even the one that is already being displayed.

    I'm thinking this is because there is no real valueMap (or optionDataSource) but only an Arraylist with my custom objects.
    Is this what's happening, because there is no valueMap or optionDataSource it's not filling the dropdown list?

    So, how can I "tell" my editor that the values are in the delivered object and not in a valueMap? How is this supposed to work with a custom object?

    I have tried tirelessly by setting different attributes, defining a picklist etc. I'm just not seeing how I can get this to work.

    DataSource xml
    Code:
    <DataSource ID="93" dropExtraFields="true" sparseUpdates="true">
    <fields>
    <field sraId="317" name="id" title="Id" canEdit="false" type="integer" primaryKey="true" defaultValue="-2000000" crud="2" >
    </field>
    <field name="theRootObjectLinks" title="Root Object" multiple="true" type="silkMultipleLink" javaClass="outpost.dto.LinkDTO" crud="15" required="true" valueField="id" displayField="representation" />
    </fields>
    </DataSource>
    Code:
    public class SilkMultipleLink extends SimpleType {
    
    	public final static String SIMPLETYPE_NAME = "silkMultipleLink";
    
    	// field names as
    	public final static String FIELD_ID = "id";
    	public final static String FIELD_SYSREPRELATION_ID = "sysRepRelationID";
    	public final static String FIELD_DESTSYSREPOBJECT_ID = "destSysRepObjectID";
    	public final static String FIELD_REPRESENTATION = "representation";
    
    	public SilkMultipleLink() {
    		super(SIMPLETYPE_NAME, FieldType.ANY);
    
    		this.setShortDisplayFormatter(new SilkMultipleLinkFormatter());
    		this.setNormalDisplayFormatter(new SilkMultipleLinkFormatter());
    	}
    	
    	
    	private class SilkMultipleLinkFormatter implements SimpleTypeFormatter {
    
    		public String format(Object value, DataClass field, DataBoundComponent component, Record record) {
    
    			if (value == null) {
    				return SilkDBConstants.NULL_STRING;
    			}
    
    			if (value instanceof JavaScriptObject) {
    				JavaScriptObject jsObject = (JavaScriptObject) value;
    				Record[] items = Record.convertToRecordArray(jsObject);
    				if (items.length > 0) {
    					String representation = items[0].getAttribute(FIELD_REPRESENTATION);
    					return representation;
    				}
    				return SilkDBConstants.NULL_STRING;
    			}
    
    			return (String) value;
    		}
    	}
    	
    }
    Code:
    public class SilkMultipleLinkEditor extends SelectItem {
    	
    	//private final ListGrid pickList;
    		
    	public SilkMultipleLinkEditor() {
    		super();
    		this.setAutoFetchData(false);
    		this.setFetchMissingValues(false);
    		this.setMultipleAppearance(MultipleAppearance.PICKLIST);
                              
    		// link the formatter to the editor
    		this.setEditorValueFormatter(new SilkMultipleLinkValueFormatter());
    		this.setEditorValueParser(new SilkMultipleLinkValueParser());		
    	}
    		
    	public class SilkMultipleLinkValueFormatter implements FormItemValueFormatter {
    
    		public String formatValue(Object value, Record record, DynamicForm form, FormItem item) {
    
    			if (value == null)
    				return SilkDBConstants.NULL_STRING;
    
    			if (value instanceof JavaScriptObject) {
    				JavaScriptObject jsObject = (JavaScriptObject) value;
    				Object[] items = JSOHelper.convertToJavaObjectArray(jsObject);
    				if (items.length > 0) {
    					JavaScriptObject jsItem = (JavaScriptObject) items[0];
    					id = JSOHelper.getAttributeAsInt(jsItem, SilkLink.FIELD_ID);
    					if (id == null || id == SilkDBConstants.NULL_INT)
    						return SilkDBConstants.NULL_STRING;
    
    					sysRepRelationID = Integer.parseInt(JSOHelper.getAttribute(jsItem, SilkMultipleLink.FIELD_SYSREPRELATION_ID));
    					destSysRepObjectID = Integer.parseInt(JSOHelper.getAttribute(jsItem, SilkMultipleLink.FIELD_DESTSYSREPOBJECT_ID));
    					representation = JSOHelper.getAttribute(jsItem, SilkMultipleLink.FIELD_REPRESENTATION);
    					// when no representation present, return the id
    					if (representation == null || representation.length() < 1)
    						return id.toString();
    					return representation;
    				}
    				return SilkDBConstants.NULL_STRING;
    			}
    
    			return (String) value;
    		}
    
    	}
    
    	public class SilkMultipleLinkValueParser implements FormItemValueParser {
    
    		public Object parseValue(String value, DynamicForm form, FormItem item) {
    
    			JavaScriptObject jsObject = (JavaScriptObject) item.getValue();
    			if (value == null)
    				return jsObject;
    
    			Object[] items = JSOHelper.convertToJavaObjectArray(jsObject);
    			ArrayList list = new ArrayList(items.length);
    
    			for (int i = 0; i < items.length; i++) {
    				JavaScriptObject jsItem = SilkJSOHelper.clone((JavaScriptObject) items[i]);
    				JSOHelper.setAttribute(jsItem, SilkMultipleLink.FIELD_ID, id);
    				JSOHelper.setAttribute(jsItem, SilkMultipleLink.FIELD_DESTSYSREPOBJECT_ID, destSysRepObjectID);
    				JSOHelper.setAttribute(jsItem, SilkMultipleLink.FIELD_SYSREPRELATION_ID, sysRepRelationID);
    				JSOHelper.setAttribute(jsItem, SilkMultipleLink.FIELD_REPRESENTATION, representation);
    				list.add(jsItem);
    				break;
    			}
    
    			return JSOHelper.arrayConvert(list.toArray());
    		}
    
    	}
                 }
    Code:
    public class LinkDTO extends Serializable {
    
    	private Integer sysRepRelationID = DBConstants.NULL_INT;
    	/**
    	 * The destination sysrepobject.
    	 */
    	private Integer destSysRepObjectID = DBConstants.NULL_INT;
    	/**
    	 * The linked object.
    	 */
    	private Integer id = DBConstants.NULL_INT;
    	private String representation = DBConstants.NULL_STRING;
    	private Integer status = Status.NOTMODIFIED;
    
    ...
    Code:
    [
        {
            invalidateCache:false, 
            data:{ 
                selection:[
                    {
                        id:294, 
                        theRootObjectLinks:[
                            {
                                destSysRepObjectID:47, 
                                dynAttributes:[
                                ], 
                                encodedData:{
                                    dataType:3, 
                                    text:""
                                }, 
                                id:1, 
                                representation:"Contact", 
                                status:0, 
                                sysRepObjectId:-2147483648, 
                                sysRepRelationID:170, 
                                timestamp:"1900-01-01 00:00:00.000"
                            }
                        ],  
                        timestamp:"2010-07-07 00:00:00.000",                     
                    }
                ], 
                sessDtoId:294
            }, 
            status:0, 
            isDSResponse:true
        }
    ]
    Thanx

    #2
    First, a sanity check: is this worth attempting? A typical UI for picking related entities is to show a pop-up dialog with a grid in it with a checkbox for each row. You could add a FormItemIcon to launch such a pop-up dialog.

    Your current path is basically trying to repurpose a SelectItem to work with a completely different internal data model - you'll probably end up having to implement your own PickList, among other challenges. And the result may well be less usable than the more common pop-up dialog.

    Comment

    Working...
    X