2

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>
Shruti
  • 1
  • 13
  • 55
  • 95

1 Answers1

5

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.

rptmat57
  • 3,643
  • 1
  • 27
  • 38