Announcement

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

    Problems saving and retrieving Data with DMI

    Hi there

    I'm still quite new to Smart Client and I need to build a simple proof of concept application using a couple of different technologies. Due to some restrictions I cannot use JSP pages and must utilise pure HTML pages.

    Alot of what I'm doing is based on the examples so I'm problably only have a small mistake.

    My HTML page
    Code:
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <html>
    <head>
    </head>
    <body>
    <script>window.isomorphicDir='../../YAPoC2/isomorphic/';</script>
    <script src="isomorphic/system/modules/ISC_Core.js?isc_version=5.6.js"></script><script>isc._lastModule='Core';</script>
    
    <script src="isomorphic/system/modules/ISC_Foundation.js?isc_version=5.6.js"></script><script>isc._lastModule='Foundation';</script>
    <SCRIPT SRC="isomorphic/system/modules/ISC_DataBinding.js?isc_version=5.6.js"></SCRIPT><SCRIPT>isc._lastModule='DataBinding';</SCRIPT>
    
    <script src="isomorphic/system/modules/ISC_Containers.js?isc_version=5.6.js"></script><script>isc._lastModule='Containers';</script>
    <script src="isomorphic/system/modules/ISC_Grids.js?isc_version=5.6.js"></script><script>isc._lastModule='Grids';</script>
    <script src="isomorphic/system/modules/ISC_Forms.js?isc_version=5.6.js"></script><script>isc._lastModule='Forms';</script>
    <script src="isomorphic/system/modules/ISC_DataBinding.js?isc_version=5.6.js"></script><script>isc._lastModule='DataBinding';</script>
    <script src="isomorphic/skins/SmartClient/load_skin.js?isc_version=5.6.js"></script>
        <span wicket:id = "navomaticBorder">
    
    <script>
     
    
    isc.DataSource.create({
        ID:"supplyItemDMI",
        serverType:"generic",
    //    operationBindings:[
    //        {operationType:"fetch", serverMethod:"fetch"},
    //        {operationType:"add", serverMethod:"add"},
    //        {operationType:"update", serverMethod:"update"},
    //        {operationType:"remove", serverMethod:"remove"}
    //    ],
        fields:{
            ID:{
                type:"text",
                name:"ID",
                length:45,
                hidden:true,
                primaryKey:true
            },
            Name:{
                type:"text",
                title:"Name",
                name:"name",
                length:120,
            },
            Address:{
                type:"text",
                title:"Address",
                name:"Address",
                length:255,
            },
            Age:{type:"Integer", title:"Age", name:"Age"},
            Sex:{type:"Integer", title:"Gender", name:"Sex"},
            DeletedFlag:{
                type:"Integer",
                name:"DeletedFlag",
                hidden:true
            }
        }
    })
    
    
    VStack.create({
    	left:50, top:75,
    	width:"70%",
    	membersMargin:20,
    	members:[
    
    		// databound DetailViewer
    		//   * click boundList records to display
    		DetailViewer.create({
    			ID:"boundViewer",
                  autoDraw: false,
                  dataSource: supplyItemDMI
    		}),
    				// databound ListGrid
    		//   * click records to edit in boundForm and view in boundViewer
    		//   * double-click record to edit inline (Return or arrow/tab off current row to save)
    		ListGrid.create({
    			ID:"boundList",
                autoDraw: false,
                dataSource: supplyItemDMI,
    			height:200,
    			canEdit:true,
                selectionChanged : function (record, state) {
                    if (this.selection.anySelected()) {
                        deleteBtn.enable();
                        saveBtn.setDisabled(this.selection.multipleSelected());
                        boundForm.editRecord(record);
                        boundViewer.viewSelectedData(this);
                    } else {
                        deleteBtn.disable();
                        saveBtn.disable();
                    }
                }
    		}),
    
    
    		// databound DynamicForm
    		//   * click boundList records to edit
    		DynamicForm.create({
    			ID:"boundForm",
                  autoDraw: false,
                  dataSource: supplyItemDMI,
    			numCols:"6",
    			autoFocus:false
    		}),
    
    		// toolbar to perform various actions using the boundForm values (see helpText above)
    		Toolbar.create({
    			autoDraw:false,
    			membersMargin:10,
                buttonConstructor: "IButton",
                height: 22,
    			buttons:[
    				{title:"Save", click:"boundForm.saveData()", ID:"saveBtn"},
    				{title:"Clear", click:"boundForm.clearValues();boundForm.editNewRecord();saveBtn.enable()"},
    				{title:"Filter", click:"boundList.filterData(boundForm.getValuesAsCriteria());"},
    				{title:"Fetch", 
                     click:"boundList.fetchData(boundForm.getValuesAsCriteria());"},
    				{title:"Delete", ID:"deleteBtn", disabled: true, 
                     click:"boundList.removeSelectedData();boundList.deselectAllRecords()"}
    			]
    		})
    		
    		
    	]
    });
    
    boundList.fetchData();
    
    
    
    </script>
    
    
        </span>
    </body>
    </html>
    My handler class that should handle all the requests that gets sent to the server

    Code:
    package com.stracienta.handlers;
    
    import java.io.*;
    import java.util.*;
    
    import com.isomorphic.util.DataTools;
    import com.isomorphic.datasource.*;
    import com.isomorphic.util.ErrorReport;
    import com.stracienta.PoC.persistenceObjects.SalesRepItem;
    import com.stracienta.PoC.businessLogic.*;
    
    public class SalesRepHandler
    {
    
    	private ThinLogicLayer logicLayer = null;
    
    	public SalesRepHandler ()
    	{
    		logicLayer = new ThinLogicLayer();
    	}
    
    	public DSResponse fetch(DSRequest dsRequest) throws Exception
    	{
    		DSResponse dsResponse = new DSResponse();
    
    		List<SalesRepItem> list = logicLayer.getSalesRep();
    
    		dsResponse.setStartRow(0);
    		dsResponse.setEndRow(list.size());
    		dsResponse.setData(list);
    
    		return dsResponse;
    	}
    
    	public SalesRepItem add(SalesRepItem item) throws Exception
    	{
    		logicLayer.addSalesRep(item);
    		return item;
    	}
    
    	public SalesRepItem update(SalesRepItem item) throws Exception
    	{
    
    		logicLayer.updateSalesRep(item);
    		return item;
    	}
    
    	public SalesRepItem remove(SalesRepItem item) throws Exception
    	{
    		logicLayer.remove(item);
    		return item;
    
    	}
    }
    My data source file on the server
    Code:
    <DataSource
        ID="supplyItemDMI"
        serverType="generic"
        testFileName="supplyItem.data.xml"
    >
        <fields>
        
        	private String id;
    	private String name;
    	private String address;
    	private int age;
    	private int sex;
    	private int deletedflag;
    	
            <field name="id"       		type="sequence" hidden="true"       primaryKey="true"/>
            <field name="iname"    		type="text"     title="Name"        length="120"       required="true"/>
            <field name="address"       type="text"     title="Address"     length="255"       required="true"/>
            <field name="age" 			type="integer"  title="Age" 		required="true"/>
            <field name="sex" 			type="integer"  title="Gender" 		required="true"/>
            <field name="deletedflag"	type="integer"  hidden="true"/>
    
        </fields>
    
        <serverObject lookupStyle="new" className="com.stracienta.handlers.SalesRepHandler"/>
    
    
        <!-- You can define an operationBindings section to bind operation names to server method
             (potentially additionally discriminated by the operationId).
             In the absense of this section, the server will look for a server method named after
             the operationType.  
        -->
        
        <operationBindings>
            <binding operationType="fetch" serverMethod="fetch">
            <serverObject  lookupStyle="new" className="com.stracienta.handlers.SalesRepHandler"/>
            </binding>
            <binding operationType="add" serverMethod="add">
            <serverObject  lookupStyle="new" className="com.stracienta.handlers.SalesRepHandler"/>
            </binding>
        </operationBindings>
        
    </DataSource>
    The problem.

    The communication between the server and the client is not working properly while debugging when you try to fetch the data the data gets retrieved from the database but it never gets populated in either the grid or the form. further when you try and Save any new data the save / add method is never called only the fetch method.

    Another thing that I have not yet seen how to do is one of my pages I am to develop is going to define the items for a dropdown box on another form, I would need to be able to retrieve all the items and dynamically populate the dropdown box further I'd need to associate the value to a key.

    Please say if you need any further information.

    #2
    Hi rvdwalt,

    The immediate problem is that you don't need both a server and client-side version of your DataSource. You should be using the loadDS tag to load the server-side DataSource, and not editing a client-side version in parallel.

    You should change your DataSource ID so that it differs from the one used in the examples, as this could cause conflicts (eg, the examples one being loaded instead of yours).

    Also, the Java code you've put into your server-side DataSource isn't actually doing anything and could be causing errors.

    Once you've corrected these problems, if you're still having trouble, you need to post the server logs and client-side logs (from the Developer Console) in order to allow people to help you.

    Comment


      #3
      Hi Isomoprhic,

      I have written the code the way you have replied for the post. I have a only one datasource and i am importing that datasource in my .jsp page.
      My question is:
      I have edited few values in my list grid. Now i will click on save button. After this i should update all the values in my oracle database. I am using the standalone tomcat server not the smartclient's embeded tomcat server that comes along with smartclient SDK.
      On click of save button how to call my add method in manager class. and how to get all the edited fields?

      From reference material, i found that ListGrid.saveAllEdits() is used to save all the edited fields. This is fine with the inbuilt database and embeded tomcat serever. But i am using oracle external database and tomcat server and also the updated data will be saved in diff tables of my database. All my problems will be solved if i know "On click of save button how to call my add method in manager class. and how to get all the edited fields?". Please help me.

      Comment


        #4
        Well, you'll get an "update" DSRequest on the server - which will have the old and new data. How you handle that is completely up to you.

        Comment

        Working...
        X