Spring Web Flow异常处理

标签 spring spring-webflow spring-webflow-2

如何防止异常, 如果 requestParameters.sortBy 作为字符串传递 (java.lang.NumberFormatException) 或丢失 (java.lang.NullPointerException)?

<view-state id="journeySearch" model="journeyForm">

     ...

    <transition on="sort">
        <set name="journeyCriteria.sortBy" value="requestParameters.sortBy" type="int" />
        <evaluate expression="bookingService.searchJourneys(journeyCriteria)" result="viewScope.journeys" /> 
    </transition>
</view-state>

最佳答案

requestParameters.sortBy如果不存在则为 null,但不应该抛出 NullPointerException

关于 NumberFormatException,您可以使用类似的东西:

<global-transitions>
    <transition on-exception="java.lang.NumberFormatException" to=""/>
</global-transitions>

您还可以实现自己的异常处理程序并将其与 <exception-handler bean=""/> 一起使用您可以在流或状态级别使用它。

关于Spring Web Flow异常处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13086376/

相关文章:

java - 从子流返回后调用 flowRedirect 会引发异常

java - 传输方案未识别 : [tcp]

java - Springboot事件发布者有延迟

java - 在 hibernate 状态下保存外键

grails - Web流上的Grails “not-null property references a null or transient value”异常

Spring-Webflow使用HTML链接表示事件

java - Spring MVC IllegalStateException 错误

grails - Grails 中的 Web 流 - 困惑

java - 使用 Spring Security 取消 Spring 流的安全

java - Barebonds Hello World 安全示例