From the course: Java EE: JavaServer Faces JSF

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Custom JSF converters as managed beans

Custom JSF converters as managed beans

From the course: Java EE: JavaServer Faces JSF

Start my 1-month free trial

Custom JSF converters as managed beans

- [Instructor] Now let's fill out the getAsString method. Now, the getAsString method will get, obviously, a dessert object in the value parameter, so given a dessert object, what do we want to display to the user? We want to display the dessert names. So, we want to be sure that value isn't null, and it's an instance of dessert. Given that, we want to return the dessert name. We'll perform a cast here on line 43, cast the value, to get the dessert name. Let's close that out, and otherwise, we'll return nothing. Recall what I said earlier about converters acting like lightweight validators. So in the real world, you code a bit more defensively in both the getAsObject and the getAsString methods. But for the sake of brevity here, I'm just going to wrap all the code in a try-catch block, and through a converter exception, passing in a faces message with the available exception message, so here for example, we'll try here, and catch any exception. And we throw the new converter exception…

Contents