質問

Let's look at an usual RequestFactory server side code trying to find a student.

Student s = null;
try{
    ....
    s = pm.findStudent(....)
    ....
}catch(Exception e){
    ....
}finally{
    pm.close();
}
return s;

Here if there is an exception there is a chance that 's' remains null. But it will be difficult for the client side code to determine whether there was an exception or whether the student was not found. So instead if I remove the exception block:

Student s = null;
try{
    ....
    s = pm.findStudent(....)
    ....
}finally{
    pm.close();
}
return s;

I will be able to handle the exception on the client side with RequestFactory's onFaliure. This will help me easily take the necessary action for both cases i.e. if the student is not found v/s there is an exception.

I wish to understand if this is the right way, potential pitfalls, or is there a better one?

役に立ちましたか?

解決

You have to think in terms of requests (method name and arguments) and responses (return type).

If you want to return an object and/or an error, then use a ValueProxy with two properties, e.g.

@ProxyFor(FindStudentResponse.class)
interface FindStudentResponseProxy extends ValueProxy {
  StudentProxy getStudent();
  FindError getError();
}

where FindError would be an enum.

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