Quantcast
Channel: SmartClient Forums
Viewing all articles
Browse latest Browse all 4756

contribution - mark Row Errors On Grid from server side validation

$
0
0
Use for mark Row Errors On Grid send it form a server side validation.

My case is when user submit multiple edited rows, maybe ONE or multiple records results on server side error validation, the following code will mark ONLY that invalid rows as an row with erros.

Server side response:
Code:

  {"response":{
                "errors":[
            {
                "data":[
                    {
                        product_id:"100",
                        field:"product",
                        errorMessage:"error invalido numero 100 "
                    },
                    {
                        product_id:"98",
                        field:"name",
                        errorMessage:"error invalido numero 98"
                    }
                ]
            }
        ],
        status:-4,
        action:1
    }
 }


Gwt Smarclient code use
Code:

new DSCallback() {
@Override
public void execute(DSResponse response, Object rawData, DSRequest request) {
if (response.getStatus() < 0) {
        // Error handling here
        UIMessages.showSimpleErrorValidation();                                                               
        markRowErrorsOnGrid( response,  getGrid() );                                                                       
  } else {
          // Normal processing here
          UIMessages.showSuccess();       
 }
}
}, null);


        /*
        * Handle errors by rows       
        */
        public void  markRowErrorsOnGrid(DSResponse response , ListGrid Grid){
               
                Map<String,Object> errors = response.getErrors();
                //Get array
                for (Object error : errors.values()) {
                        if (error instanceof List) {
                                //iterate each error set
                                for (Map<String, String> errorMap : (List<Map<String,String>>)error) {
                                        int index = 0;
                                        String product_id = "", field = "", msg = "";
                                        //iterate each error set atributte
                                        for (String value : errorMap.values()) {
                                                //USE ON THIS ORDER THE RESPONDE- PRODUCT ID, FIELD, ERROR MSG
                                                if(index==0)
                                                        product_id = value;
                                                if(index==1)
                                                        field = value;
                                                if(index==2)
                                                        msg = value;                                                                                                               
                                                index++;
                                        }
                                        System.out.println( product_id + field + msg);
                                       
                                        // 2. lookup row position based on product id
                                        Record record = new Record();
                                        record.setAttribute("product_id", product_id );
                                        int RecordIndex = supergrid.getGrid().getRecordIndex(record);
                                                                                                                                               
                                    // 3. Set errors to row
                                        Map<String,String> errores = new HashMap<String,String>();                                                                                 
                                        errores.put( field , msg );
                                         
                                        //Asing error map
                                        Grid.setRowErrors( RecordIndex , errores  );       
                                }
                        }
                }

        }


Viewing all articles
Browse latest Browse all 4756

Trending Articles