Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3788794
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:03:18+00:00 2026-05-19T12:03:18+00:00

I have a PropertyEditor in order to translate ids into Persons , with it’s

  • 0

I have a PropertyEditor in order to translate ids into Persons, with it’s setAsText (String text) as follows:

public void setAsText(String text) throws IllegalArgumentException {
    try {
        int id = Integer.parseInt(text);
        Person person = peopleService.get(id);
        this.setValue(person);
    }
    catch (NumberFormatException ex) {
        // ...
        throw new IllegalArgumentException("Not a number!: " + text);
    }
    catch (PersonNotFoundExcetion ex) {
        // ...
        throw new IllegalArgumentException("Impossible to get Person: " + text);
    }
}

And my PeopleController has a method as follows:

@RequestMapping("/getPerson")
public void ver (@RequestParam Person person, Model model) {
    model.addAttribute (person);
    // ...
}

I want to catch the IllegalArgumentException in order to show a friendly message to the user, such as “Sorry, the Person you are looking for isn’t here”, but I don’t know where to do that…

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:03:19+00:00Added an answer on May 19, 2026 at 12:03 pm

    General exception handling can be done in this way:

    @ExceptionHandler(Exception.class)
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    public String handleAllExceptions(Exception e) {
      return "redirect:/error.html"; /* use the correct view name */
    }
    

    More specfic you could use BindingResult

    @RequestMapping(value = "/datedata", method = RequestMethod.POST)
    public String create(
        @ModelAttribute("datedata") final DateData datedata,
        final BindingResult result) {
    
        if (result.hasErrors()) {
            return "datedata/create";
        } else {
            ...
            return "myView";
        }
     }
    

    But I guess this works only for “Forms” (ModelAttribute)

    In my humble opinion it is not a good idea to let Spring handle validaten of user input by property editors. I would strongly recommend to use the Form way: Build a command object with a STRING field an use a validator on it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following custom property in my code: public Dictionary<int, string> ServiceIdList {
I have 2 class like below, public class CheckInBean implements Serializable{ private String user;
Have a look at this picture alt text http://www.abbeylegal.com/downloads/2009-04-01/web%20part%20top%20line.jpg Does anyone know what css
Have data that has this kind of structure. Will be in ascending order by
Have a xml string, goal is to replace an xml element value to a
Have an app that can use tts to read text messages. It can also
Have just started to get into CakePHP since a couple of weeks back. I
How can I disable JEDI string property editor? I have tried to disable these
have a small javscript that users can include into their sites like so: <script
Have a string: myString = '<p>Phone Number:</p><p>706-878-8888</p>' Trying to regex out all HTML tags,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.