如何根据操作结果有条件地调用 a4j:commandButton oncomplete 脚本
我有一个
<a4j:commandButton action="#{myBean.doCalculation}"
oncomplete="redirectBrowser()" />
但是,如果 myBean.doCalculation()
出现错误,则始终调用 oncomplete
属性。我如何让它取决于操作方法的结果?
I have a
<a4j:commandButton action="#{myBean.doCalculation}"
oncomplete="redirectBrowser()" />
However, if there is an error at myBean.doCalculation()
, then oncomplete
attribute is always invoked. How do I let it depend on result of action method?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以检查 oncomplete 事件中的错误,并在未找到错误时重定向。可以这样做
You can check for errors in the oncomplete event and redirect when none are found. It can be done like this
如果您使用的是 JSF 2.0,则可以使用
FacesContext#isValidationFalied()
检查验证是否失败:但是,仅在操作方法中执行重定向会更干净:
然而,更干净的是只是通过验证器进行验证。这样,当验证失败时,根本不会调用操作方法。
If you're on JSF 2.0, you can use
FacesContext#isValidationFalied()
to check if validation has failed or not:However, just performing redirect in the action method is more clean:
Yet more clean would be to just do the validation by a
Validator
. This way the action method will simply not be invoked at all when the validation has failed.好吧,仅仅查找 facesContext.maximumSeverity == null 是不够的,可能会出现当前最大严重性的警告,也应该重定向。相反,编写一个方法来检查是否存在任何最大严重程度的优先级错误......
Well, just looking for facesContext.maximumSeverity == null is not enough, there may be a warning as current max severity, that should redirect, too. Instead, write a method that looks if there are any max severities of priority error...