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 7531795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:16:09+00:00 2026-05-30T05:16:09+00:00

I have a custom toString method in my enum: enum TaxRate implements Serializable {

  • 0

I have a custom toString method in my enum:

enum TaxRate implements Serializable {
    RATE23(23.0),
    ...

    private String s
    private BigDecimal rate

    private TaxRate(BigDecimal s) {
        this.s = s + "%"
        this.rate = s * 0.01
    }

    public String toString() {
        return s
    }

Now when I display the rates in HTML I get nice output like TAX: 23.0%.

But what happens when a user selects the tax from a <select> and the sent value is i.e. 23.0% is that Grails can’t create/get the TaxRate instance…

What should I override to support this custom mapping? Trying to override valueOf(String) ended with a error..

  • 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-30T05:16:11+00:00Added an answer on May 30, 2026 at 5:16 am

    Have you seen the entry at the bottom of this page?

    If you want to use a Enum with a “value” String attribute (a pretty common idiom) in a element, try this:

    enum Rating {
        G("G"),PG("PG"),PG13("PG-13"),R("R"),NC17("NC-17"),NR("Not Rated")
    
        final String value
    
        Rating(String value) { this.value = value }
    
        String toString() { value }
        String getKey() { name() }
    }
    

    Then add optionKey="key" to your tag.

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

Sidebar

Related Questions

I have a custom HtmlHelper; public static MvcHtmlString DeleteEmployeeOtherLeave(this HtmlHelper html, string linkText, Leave
I have a custom class class RouteStop { public int number; public string location;
hi i would like to create a custom calendar, this calendar will have custom
I have to make this addRows method with some data, which needs following construction.
This is probably best shown with an example. I have an enum with attributes:
I have written code for onClick method for Custom Dialog top of the another
I have a custom Install method in a project where I'm loading a user's
I have a custom exception class: public class MyException: Exception { public MyException(MyExceptionEnum myError)
I am looking for a way to override default decimal.ToString(c) method calls. I have
I have custom coded several enterprise applications for mid to large organizations to use

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.