Spring Web Flow exception handling

元气小坏坏 提交于 2019-12-24 00:25:34

问题


How to prevent exception, if requestParameters.sortBy is passed as string (java.lang.NumberFormatException) or is missing (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>

回答1:


requestParameters.sortBy will be null if it doesn't exist, but it should not throw a NullPointerException

about the NumberFormatException, you could use something like that:

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

you could also implement your own exception-handler and use it with <exception-handler bean=""/> you can use it at the flow or state level.



来源:https://stackoverflow.com/questions/13086376/spring-web-flow-exception-handling

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!