how to catch unhandled exception in the conversation bean
ellenzhao Aug 19, 2007 11:04 AMIn my view code, the inputText fields are tied to the field setters of managed entities. My conversation bean manages UseCase-related states.
Let's say there is a UseCase called updateAFood. There is an action button "submit" which calls this method in the conversation bean:
private List<Exception> errors = new ArrayList<Exception>(); private UseCaseStack; public void tryFinishUpdateAFood(){ if (there is no exception from entity bean's setter methods) { this.finishUpdateAFood(); } else { this.errors.addAll(exceptions from entity beans' setter methods); } } private void finishUpdateAFood(){ Conversation.instance().end(); this.useCases.removeUseCase(UseCase.updateAFood); this.food.setStatus(CRUDStatus.UPDATED.getSymbolInDB()); }
Here is my utility class UseCaseStack.java
public class UseCaseStack { private UseCase[] stack; private int nEntries; private int size; public UseCaseStack() { size = 10; stack = new UseCase[size]; nEntries = 0; } public Integer size() { return nEntries; } public Boolean isEmpty() { return nEntries == 0; } public void push(UseCase uc) { if (nEntries == size) { UseCase[] newstack = new UseCase[2 * size]; for (int i = 0; i < size; i++) newstack = stack; stack = newstack; size *= 2; } this.stack[nEntries++] = uc; } public UseCase pop() { nEntries--; UseCase uc = this.stack[nEntries]; this.stack[nEntries] = null; return uc; } public UseCase peek() { if (this.nEntries == 0) { return UseCase.startApp; } else { return this.stack[nEntries - 1]; } } public UseCase previous() { if (this.nEntries <= 1) { return UseCase.startApp; } else { return this.stack[nEntries - 2]; } } public Boolean contains(UseCase uc) { boolean result = false; for (int i = nEntries - 1; i >= 0; i--) { if (this.stack.equals(uc)) { result = true; break; } } return result; } public void removeUseCase(UseCase uc) { for (int i = nEntries - 1; i >= 0; i--) { if (this.stack.equals(uc)) { for (int j = i; j < nEntries - 2; j++) this.stack[j] = this.stack[j + 1]; this.nEntries--; break; } } } public void removeUpto(UseCase uc) { while (pop() != uc); } } public enum UseCase { .... }
Any hint on how to catch the exceptions from the entity bean's setter classes in the conversation bean would be highly appreciated!
Regards,
Ellen