Announcement

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

    One to Many Relationship

    I'm back on this project a more organized view. I am still trying to figure out the way to create a filtering

    this is my exact and complete data-source I am working with.

    parent datasource
    Code:
     
    <DataSource
        ID="productSQL"
        serverType="sql"
        tableName="product"
    >
        <fields>
            <field name="id"   type="text"   primaryKey="true"  />
        	<field name="name"           title="name"      type="text"	 required="true"/>
        	<field name="description"           title="description"      type="text"	 required="true"/>
        </fields>
    </DataSource>
    product table
    id | name | description
    -----------------------
    1 | product1 | prod1 desc
    2 | product2 | prod2 desc
    3 | product3 | prod3 desc




    child datasource
    Code:
    <DataSource
        ID="characteristicSQL"
        serverType="sql"
        tableName="characteristic"
      
    >
        <fields>
            <field name="id"  type="int" required="true" primaryKey="true" />
        	<field name="name"      required="true"      title="Characteristic"    type="text" />
    		<field name="description"  type="text"/>
    	</fields>
    </DataSource>
    characteristic table
    id | name | description
    -----------------------
    1 | char1 | char1 desc
    2 | char2 | char2 desc
    3 | char3 | char3 desc




    Relational Datasource
    Code:
    <DataSource
        ID="productCharacteristicsSQL"
        serverType="sql"
        tableName="product_Characteristics"
      
    >
        <fields>
        	<field name="productID"      includeFrom="productSQL.name"   rootValue="root"    type="text"	length="128" foreignKey="productSQL.name" />
        	<field name="characterisitcID"  title="Characteristic"   includeFrom="characteristicSQL.name"  rootValue="root"  type="text" foreignKey="characteristicSQL.name"/>
        </fields>
        
        
    </DataSource>
    characteristic table
    productID | characteristicID
    -----------------------
    1 | char1
    2 | char2
    1 | char3



    And the code

    Code:
    		DataSource parentDs = DataSource.get("productSQL");    
            DataSource childDs = DataSource.get("characteristicSQL"); 
            DataSource parentChildDs = DataSource.get("productCharacteristicsSQL");
            
            final DynamicForm form = new DynamicForm();  
            form.setWidth(300);  
            ListGridField parentField = new ListGridField("name");  
            SelectItem parentItem = new SelectItem("name");  
            parentItem.setOptionDataSource(parentDs);
            parentItem.setPickListWidth(450);  
            parentItem.setPickListFields(parentField);  
    
            final ListGrid listGrid = new ListGrid();  
            
            listGrid.setHeight(224);  
            listGrid.setWidth100();  
            listGrid.setDataSource(parentChildDs); 
            listGrid.setCanEdit(true);  
            listGrid.setAutoSaveEdits(false);
    
            ListGridField childIdField = new ListGridField("id");  
            final SelectItem childIdSelectItem = new SelectItem();
            childIdSelectItem.setOptionDataSource(childDs);
            childIdField.setEditorType(childIdSelectItem); 
            
            ListGridField childNameField = new ListGridField("name");  
            final SelectItem childNameSelectItem = new SelectItem();  
            childNameSelectItem.setOptionDataSource(childDs);
            childNameField.setEditorType(childNameSelectItem);         
                   
            final ListGridField childDescField = new ListGridField("description");  
            SelectItem childDescSelectItem = new SelectItem();
            childDescSelectItem.setOptionDataSource(childDs);
            childDescField.setEditorType(childDescSelectItem); 
    
            listGrid.setFields(childIdField, childNameField, childDescField);  
     
            form.setItems(parentItem);  
            form.draw(); 
            this.addMember(listGrid);
    The table is being populated with the option to choose all charactersitics despite which product is selected. How can I create the appropriate filter? I am not committed to the layout of this code

    Once again thank you for any assistance
    Attached Files
    Last edited by mdawson; 19 Jul 2012, 10:46.
Working...
X