假如我们捕捉到一个异常,我们就在按钮组件中添加一个错误方法。codebehind 对象根据属性中配置的名称实例化页面中的每个组件。然后返回 failure。假如没有对失败返回值配置导航的话,它就会返回到同一个页面。我们可以添加一个链接到按钮控制的错误组件。 catch (com.deploybook.stock.exceptions.StockException e) { e.PRintStackTrace(System.err); context.addMessage(buttonEx1, new javax.faces.application.MessageImpl( javax.faces.application.Message.SEVERITY_ERROR, "Stock Not found", "Symbol Not Found or invalid" )); return "failure"; } catch (com.deploybook.stock.exceptions.SymbolNotFoundException e) { e.printStackTrace(System.err); context.addMessage(buttonEx1, new javax.faces.application.MessageImpl( javax.faces.application.Message.SEVERITY_ERROR, "Stock Not found", "Symbol Not Found or invalid" )); return "failure"; } catch (com.deploybook.trade.exception.InvalidSymbolException e) { e.printStackTrace(System.err); context.addMessage(buttonEx1, new javax.faces.application.MessageImpl( javax.faces.application.Message.SEVERITY_ERROR, "Stock Not found", "Symbol Not Found or invalid" )); return "failure"; }