In your controller class, enclose the code that calls the service in a try-catch block.
Example:
try {
def searchResult = User.getUserByName(params.name)
if(searchResult != null)
else{
flash.message = message(code: 'user.nonfound.message', default: "No items found.")
render(view: "/admin/user/list", model: [userInstanceList: [], userInstanceTotal: 0])
}
} catch (e) {
flash.message = message(code: 'user.nonfound.message', default: "No items found.")
render(view: "/admin/user/list", model: [userInstanceList: [],userInstanceTotal: 0])
}
Example:
try {
def searchResult = User.getUserByName(params.name)
if(searchResult != null)
render(view: "/admin/user/list", model: [userInstanceList: searchResult?.results, userInstanceTotal: searchResult?.total])
else{
flash.message = message(code: 'user.nonfound.message', default: "No items found.")
render(view: "/admin/user/list", model: [userInstanceList: [], userInstanceTotal: 0])
}
} catch (e) {
flash.message = message(code: 'user.nonfound.message', default: "No items found.")
render(view: "/admin/user/list", model: [userInstanceList: [],userInstanceTotal: 0])
}
No comments:
Post a Comment