Announcement

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

    SelectItem which has OptionDataSource does not handle Error

    Here's the code:
    Code:
    public class SimpleDiscoveryDMSelectionLayout  {
    
    private final SelectItem dmServerItem = 
            new SelectItem("dm_server_id", "My Server");
    
    public SimpleDiscoveryDMSelectionLayout() {
            
            this.dmServerItem.setOptionDataSource( DSFactory.getDS( DSType.DM_SERVER ) );
            this.dmServerItem.setValueField("dm_server_id");
            this.dmServerItem.setDisplayField("dm_name");
            this.dmServerItem.setAllowEmptyValue(false);
            this.dmServerItem.setAlign( Alignment.LEFT );
            this.dmServerItem.setDefaultToFirstOption( true );
            
            DSRequest dsRequestProperties = new DSRequest();
            dsRequestProperties.setWillHandleError(true);
            this.dmServerItem.setOptionFilterContext(dsRequestProperties);
            
            this.dmServerItem.addDataArrivedHandler(new com.smartgwt.client.widgets.form.fields.events.DataArrivedHandler(){
    
                @Override
                public void onDataArrived(DataArrivedEvent event) {
                   //this one never called for error
                    System.out.println("Arrived");
                    
                }
                
            });
            this.dmServerItem.setValueFormatter(new FormItemValueFormatter(){
    
                @Override
                public String formatValue(Object value, Record record,
                        DynamicForm form, FormItem item) {
                    String dispValue = SimpleDiscoveryDMSelectionLayout.this.dmServerItem.getDisplayValue(value.toString());
                    if (dispValue == null) {
                        return "";
                    }
                    return dispValue;
                }
                
            }
            );
            
            
    
    
        }
    My problem here is that I want to handle any error in the fetch on my own. For example if the reply came with the error code I want to clean up the SelectItem and make it disable.
    here's example of the request this item sends:
    {
    dataSource:"dm_server",
    operationType:"fetch",
    showPrompt:true,
    requestId:"dm_server$62746",
    fallbackToEval:false,
    bypassCache:true
    }
    and here's the reply
    [
    {
    invalidateCache:false,
    isDSResponse:true,
    queueStatus:-1,
    status:-606,
    data:null
    }
    ]
    Unfortunately, the DataArrivedHandler never triggered for the error code, but works just fine for the non-error one. What can I do to handle the error on my own here ?
    I know that in newer versions I can set callback to the dsRequestProperties ( dsRequestProperties .setCallback(new DSCallback() {...} ), but I use the old one: SmartClient Version: v9.0p_2014-04-23/PowerEdition Deployment (built 2014-04-23) (this is about support of the old clients).

    #2
    DataArrived would not be expected to fire since data did not arrive (an error did).

    Probably the simplest way to handle this is to use DataSource.transformResponse(), notice the error condition there, then modify the DSResponse to no longer be an error, and just have empty data. This will mean the SelectItem does not think an error occurred and DataArrived will fire. In transformResponse, you can set a global one-time flag that your SelectItem can look for in order to disable itself.

    Note that, aside from tying layers together in a weird way, it would be invalid for code in transformResponse() to directly disable the SelectItem (this is noted in the docs). Hence the strategy of "hiding" the error from the SelectItem, but allowing your application code to detect that it occurred.

    Comment

    Working...
    X