Announcement

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

    ListGrid RestDataSource and Errors : errorMessage

    Hy, i follow the RestDataSource on ShowCase and the RestDataSource javadoc

    But, how to set an alert ? when :
    * An unrecoverable error, such as an unexpected server failure : status = -1
    * Validation failure : status = -4

    By default, the listGrid and DataSource does not create alert when error occur ? What's the best way to catch and displays errors (errorMessage) ?
    Last edited by immobilia; 5 May 2009, 05:28.

    #2
    Originally posted by immobilia
    Hy, i follow the RestDataSource on ShowCase and the RestDataSource javadoc

    But, how to set an alert ? when :
    * An unrecoverable error, such as an unexpected server failure : status = -1
    * Validation failure : status = -4

    By default, the listGrid and DataSource does not create alert when error occur ? What's the best way to catch and displays errors (errorMessage) ?
    1) Register a global RPCManager error callback
    2) Override transformResponse(..) of your RestDataSource and call DSResponse.getStatus().
    Edit : You can also register DataSource.addHandleErrorHandler
    Last edited by smartgwt.dev; 5 May 2009, 06:26.

    Comment


      #3
      Validation failure : status = -4

      It's damage we can not use the same fonctionnality of Validator on Update RestDataSource.

      In a Remove RestDataSource, as you say, i add a HandleErrorHandler and get errors with event.getResponse().getErrors().

      But I do not know how to convert to Java Object instead of JavaScriptObject....
      How to get all <response><data><record><errors> ? or convert response().getErrors() ?

      Code:
              countryDS.addHandleErrorHandler(new HandleErrorHandler() {
      
      			@Override
      			public void onHandleError(ErrorEvent event) {
      				SC.say("Error");
      				
      				Map erreurs = event.getResponse().getErrors();
      				if( erreurs != null ) {
      					System.out.println("response.getErrors() IS NOT NULL");
      					Set<String> keys = erreurs.keySet();
      					
      					Iterator<String> it = keys.iterator();
      					while (it.hasNext()) // tant que j'ai un element String non parcouru
      					{
      					  String s = it.next();
      					  System.out.println(s + " : " + erreurs.get(s).getClass());
      					  
      					  JavaScriptObject javaScriptObject = JavaScriptObject.createObject();
      					  javaScriptObject = (JavaScriptObject)erreurs.get(s);
      					  
      //					  Object o = JSOHelper.convertToJavaRefDataClassArray(javaScriptObject);
      //					  Object o[] = JSOHelper.convertToJavaObjectArray(javaScriptObject);erreurs.get(s));
      					  
      					}
      				}else{
      					System.out.println("response.getErrors() IS NULL");
      				}				
      				
      			}
      			
      
              	
              });

      Code:
      <response>
      	<status>-4</status>
      	<data>
      		<record>
      
      			<errors>
      				<countryCode>
      					<errorMessage>errorMessage1</errorMessage>
      					<errorMessage>errorMessage2</errorMessage>
      				</countryCode>
      				<capital>
      					<errorMessage>errorMessage3</errorMessage>
      					<errorMessage>errorMessage4</errorMessage>
      				</capital>
      			</errors>
      
      		</record>
      	</data>
      </response>

      Comment


        #4
        Wrong format for validation errors, see the RestDataSource docs for the correct format to use for both validation errors and unrecoverable errors.

        Comment


          #5
          Yes, but the following RestDataSource exemple doesn't write my ListGrid fields as error.

          Code:
           <response>
              <status>-4</status>
              <errors>
          				<countryCode>
          					<errorMessage>errorMessage1</errorMessage>
          					<errorMessage>errorMessage2</errorMessage>
          				</countryCode>
          				<capital>
          					<errorMessage>errorMessage3</errorMessage>
          					<errorMessage>errorMessage4</errorMessage>
          				</capital>
              </errors>
           </response>
          Tomorow i'll check my XPath configuration.

          Comment

          Working...
          X