Announcement

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

    How to use performCustomOperation?

    I have unsuccessfully spent the better of a day trying to correctly use the performCustomOperation method to invoke a custom server method. I have read and reread the documentation across the quick start guide and the javadocs as well as reviewed the discussion in threads http://forums.smartclient.com/showthread.php?t=12142 and http://forums.smartclient.com/showth...ght=custom+arg.

    If I use the following datasource definition:
    Code:
    <DataSource ID="initializeSubjects" serverType="generic">
    	<serverObject ID="initializeSubjects" lookupStyle="new" className="com.clp.dear.server.ListServerDMI"/>
    	<operationBindings>
    		<!-- Can add method arguments with: methodArguments="$dsRequest, $dsRequest.criteria.name" -->
    		<binding operationID="initializeSubjects" operationType="custom" serverMethod="initializeSubjects">
    			<serverObject lookupStyle="new" className="com.clp.dear.server.ListServerDMI"/>
    		</binding>
    	</operationBindings>
    </DataSource>
    I get the following error:
    Code:
    === 2010-12-02 15:33:10,115 [90-5] WARN  RequestContext - dsRequest.execute() failed: 
    java.lang.Exception: attempt to call unknown operationType: custom
    	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:171)
    	at com.isomorphic.datasource.DataSourceDMI.execute(DataSourceDMI.java:64)
    ...
    If I use the following datasource definition:
    Code:
    <DataSource ID="initializeSubjects" serverType="generic">
    
    	<operationBindings>
    		<!-- Can add method arguments with: methodArguments="$dsRequest, $dsRequest.criteria.name" -->
    		<binding operationID="initializeSubjects" operationType="custom" serverMethod="initializeSubjects">
    			<serverObject lookupStyle="new" className="com.clp.dear.server.ListServerDMI"/>
    		</binding>
    	</operationBindings>
    </DataSource>
    I get the following error:
    Code:
    === 2010-12-02 15:26:15,152 [90-6] WARN  RequestContext - dsRequest.execute() failed: 
    java.lang.Exception: Operation type 'custom' not supported by this DataSource (initializeSubjects)
    	at com.isomorphic.datasource.DataSource.notSupported(DataSource.java:1594)
    	at com.isomorphic.datasource.DataSource.executeCustom(DataSource.java:1577)
    ...
    Based on the nature of these errors and the reading I have done, it appears that the first data source definition is closer to the correct one than the second.

    I connect the following handler to a list grid field within a list grid and I _do_ receive the "clicked record" dialog box when I click the record:

    Code:
        			new RecordClickHandler() {
    			        public void onRecordClick(RecordClickEvent event) {
    SC.say("clicked record");
    
    			        	DataSource ds = DataSource.get("initializeSubjects");
    			    		ds.performCustomOperation("initializeSubjects", event.getRecord(), new DSCallback() {
    			    			public void execute(DSResponse response, Object rawData, DSRequest request) {
    SC.say("DS Callback");
    //			    				RootPanel.get().add(new Label("Response = " + (String) rawData));
    			    			}
    			    		}, new DSRequest());
    			        }
            		}
    Code:
    Inside ListServerDMI I have a server side method of:
    
    	public DSResponse initializeSubjects(DSRequest dsRequest) throws Exception {
    		return fetch(dsRequest);
    	}
    I have also changed the name of this method to "custom" and it still is not invoked.

    Can someone tell me precisely what I need to do to invoke the custom method initializeSubjects?
    Last edited by gsl1; 2 Dec 2010, 15:02. Reason: Changed URL's to actual links.

    #2
    Why are you using operationType:"custom" at all? Looks like a fetch. The typical use case for operationType:"custom" is a SQLDataSource where the operation you want to do is SQL, but isn't a SELECT, UPDATE, INSERT or DELETE. For example, creating a table.

    Comment


      #3
      Thank you for the gentle nudge in the right direction. I am now making significantly more progress now that I retrenched and modeled this as a fetch.

      Comment


        #4
        Just some suggestions, which I know are cheap, but you might consider adding your answer, altered slightly but for the most part in its entirety, to the JavaDoc for the performCustomOperation method, since I don't appear to be the first person to go down the wrong path and likely won't be the last. Might save you from having to answer this question yet again. Also, it might be useful, when time is available, to post an example using the performCustomOperation method to guide people in its proper use. The method name itself led me down the wrong path.

        Comment


          #5
          We had the same thought, and in upcoming nightlies you'll see that the docs for performCustomOperation point people to the right APIs to use in various cases where we've seen people misuse performCustomOperation.

          Comment


            #6
            I recently asked what was an effective way to invoke other server logic (which many times will never interact with data) and using a custom method in the datasource was recommended. Reading the documentation, I see that it says that this is rarely used, and in general it's used in cases where something other than CRUD is needed, e.g. CREATE, DROP, etc.

            If I have a server method that does something else what should I do? I have no need for a datasource in that case.

            Thanks,

            Comment


              #7
              An operationBinding with type "custom" is an effective way to do something other than CRUD. As you'll see in the docs, we are careful to steer people away from using "custom" when they really mean just CRUD *plus* something else.

              Your other option is RPC DMI (explained under the DMI overview). This is the same general mechanism, but requires a separate .app.xml file, and most people find it more convenient to just stick custom operations onto the DataSource they are most closely related to.

              Comment


                #8
                My application has several methods that need to be invoked on the server via button clicks, events, etc. on the client. In no way do these items interact with data on the server.

                Would it be better to use RPC DMI to achieve this?

                I ask because it seems like it is necessary to have at least one data object referenced in a datasource, and that is not what the application calls for. Instead I'd like to have a way to simply make calls to server methods and pass parameters.

                Are there any examples of this on the showcase that I might have missed?

                Thanks,
                Last edited by ls3674; 1 Mar 2012, 16:43.

                Comment


                  #9
                  As we said: "Your other option is RPC DMI (explained under the DMI overview). This is the same general mechanism, but requires a separate .app.xml file, and most people find it more convenient to just stick custom operations onto the DataSource they are most closely related to."

                  So, if your application has no DataSources at all, you need to use RPC DMI. Otherwise if there are DataSources, it's up to you whether to just place the non-DataSource operations on whichever DataSource is most closely related, or use RPC DMI.

                  The DMI docs cover RPC DMI with some sample code / configuration, but there's no separate running sample of RPC DMI.

                  Comment

                  Working...
                  X