Announcement

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

    How to use ServerObject for Spring Lookup?

    Version: SmartClient 7.0RC2 Pro, smartGWTpro 2.3, MySQL 5.0

    I tried running HibernateSpringDMI sample code using the HibernateSpringDMI.ds.xml. It worked. I want to skip ds.xml file while using HibernateSpring.
    So I wrote HibernateSpringDMIDS.java to replace the Fieldmapping - which is getting called from HibernateSpringDMI entrypoint class

    Code:
    //DataSource dataSource = DataSource.get("supplyItemSpringDMI");
    DataSource dataSource = HibernateSpringDS .getInstance();
    HibernateSpringDS.java

    Code:
     public class HibernateSpringDS extends DataSource{
    
    
        private static HibernateSpringDS instance = null;
    
        public static HibernateSpringDS getInstance() {
        	System.out.println("HibernateSpringDS is here");
            if (instance == null) {
                instance = new HibernateSpringDS("HibernateSpringDS");
            }
            return instance;
        }
    
        public HibernateSpringDS(String id) {
        	System.out.println("HibernateSpringDS Mapping is here");
            setID(id);
            DataSourceField pkItemId = new DataSourceTextField("itemID", "Item Id");
            pkItemId.setPrimaryKey(true);
            pkItemId.setHidden(true);
            
     ...
           DataSourceDateField nextShipment = new DataSourceDateField("nextShipment", "Next Shipment");
            
    
            setFields(pkItemId, itemName, sku, description,
                    category, units, unitCost, inStock, nextShipment);
    
            setClientOnly(false); 
    
            OperationBinding operationBinding = new OperationBinding();
            operationBinding.setOperationType(DSOperationType. FETCH);
            operationBinding.setAttribute("fetch", "fetch");
    
          //ToDo... Code to write serverObject for spring lookup ??
     
       }
    
        protected Object transformRequest(DSRequest dsRequest) {  
            return super.transformRequest(dsRequest);  
        }  
    
    }
    I would like to know what code shld I write in the above </b>ToDo</b> space for invoking the spring serverObject, so that I can fetch/call the dao methods.

    The ds.xml I m referring is as per your sample code of HibernateSpringDMI.
    Code:
     <DataSource
        ID="supplyItemSpringDMI"
        serverType="generic"
       
    >
        <fields>
            <field name="itemID"      type="sequence" hidden="true"       primaryKey="true"/>
    ...
            <field name="nextShipment"  type="date" title="Next Shipment"/>
        </fields>
    
        
       <b> <serverObject lookupStyle="spring" bean="supplyItemDao"/> </b>
       OR
        <operationBindings>
            <binding operationType="fetch" serverMethod="fetch">
            <serverObject  lookupStyle="spring" bean="supplyItemDao"/>
            </binding>
        </operationBindings>
        
    </DataSource>
    The SupplyItem.java , SupplyItemDao.java classes remains same.

    Is there any way to access the serverObject ? Or any other solution to access the Datasource without using ds.xml ??
    Waiting for your reply,
    Thanks,
    Anurag

    #2
    Your current approach can't work, because you are trying to write client-side code to call Spring, which is on the server. Even if it could work, it's insecure. One of the purposes of the .ds.xml file is to tell the server what the client is allowed to call.

    Other key reasons to have it are to declare validation and security rules in one place, so you don't need parallel client and server code.

    So you should rethink your attempt to eliminate it - you probably do not want to do so.

    Comment

    Working...
    X