質問

Environment

  • GWT 2.5 using RequestFactory
  • EclipseLink 2.4.1
  • PostgreSQL 9.1

Problem

To give context to the part of RequestFactory I'm looking at, I've inserted the structure of the snippet below:

     requestContext.persist().fire(new Receiver<ObjectProxy>(){
             @Override
             public void onSuccess(ObjectProxy response){
                    //Run code here...
             }

             @Override
             public void onFailure(ServerFailure error){
                   //See the description below for what needs to be done here.
             }

In the onFailure() function, I'd like to have different responses to the errors that may be thrown by Postgresql such as a violation of the uniqueness constraint when a user tries to insert a new barcode or new id number that has already been taken (the user must be able to choose the id).

This does not just have to be in the onFailure() function - I am looking for some place in the framework to do this handling.

Questions

  • How do you identify and respond to different error types thrown by the database or server in GWT RequestFactory?
役に立ちましたか?

解決 2

Step 1 - DevGuideValidation

You should take a look at GWT validation support and its example here https://developers.google.com/web-toolkit/doc/latest/DevGuideValidation

Validation groups can be used to specify what constraints to run on the client and what to run on the server.

The above feature is based on Java' JSR-303 Bean Validation.

Step 2 - DevGuideLogging

Combine the Valiation feature with a simple remote logging feature of GWT and you have efficient clean way of handling exceptions - https://developers.google.com/web-toolkit/doc/latest/DevGuideLogging

他のヒント

We use the Step1 in @SSR 's answer, i.e. JSR-303 Bean Validation, it works just great. Also i think you can throw exception at server side and catch that exception at onFailure() at client side, that should work too.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top