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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:34:24+00:00 2026-05-18T04:34:24+00:00

In my Spring MVC project I have an update page for Class1 that must

  • 0

In my Spring MVC project I have an update page for Class1 that must display a list of form:checkbox tags that is bound to a collection of entities on Class1.

Class1.java:

class Class1 {
  private Set<Class2> set;
  //... other fields 
}

In updateclass1.jspx:

<c:forEach items="${allClass2Instances}" var="class2">
   <form:checkbox label="${class2.name}" path="set" value="${class2}"/><br/>
</c:forEach>

With the checkbox tag as above, when I display the page, the checkbox is ticked if the Class2 instance is part of the Set on class1, and unticked if it isn’t. But when I hit submit, I get the following error:

Failed to convert property value of type 'java.lang.String[]' to required type 'java.util.Set' for property 'set'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "Name 1" from type 'java.lang.String' to type 'java.lang.Long'; nested exception is java.lang.NumberFormatException: For input string: "Name1"

As far as I can tell when the page is populated, the form:checkbox tag needs an instance to set the correct checked/unchecked value, but on submit the JSP is sending an array of class2.toString() values to a converter that expects the IDs. Conversely when I change the tag to the following:

<form:checkbox label="${class2.name}" path="set" value="${class2.id}"/><br/>

The binding works fine, but when I view the update page the checkboxes are not ticked / unticked correctly because the tag does not know that value being passed in is the object id.

How do I make the binding after submit consistent with what the checkbox tag expects?

In case it matters – this is all inside a scaffolding page generated by Roo.

  • 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-18T04:34:25+00:00Added an answer on May 18, 2026 at 4:34 am

    Figured out how to make this work for now. If anyone comes up with a neater solution please add it and I’ll mark it correct instead.

    The problem above was being caused by needing ${InstanceOfClass2} to evaluate to different things in different places:

    1. At the time of evaluation of the tag, <form:checkbox> needed an expression that evaluated to an actual instance of Class2
    2. After the tag completed, the value attribute of the generated <input type="checkbox"> tag needs to be equal to a numerical ID field of an instance of Class2

    The solution was to add a converter to my Class1Controller, eg:

    Converter<Class2, String> getClass2Converter() {
        return new Converter<Class2, String>() {
            public String convert(Class2 instance) {
                return "" + instance.getId();
            }
        };
    }
    

    Thus the expression ${InstanceOfClass2} evaluates to a Class2 instance for the checkbox tag, but when it comes to writing the actual HTML is converted to a numerical ID.

    This approach is very messy when working with Roo. All of the other scaffolding relating to Class1 then wants to use this same Converter, so I started seeing a whole bunch of IDs everywhere that you would want to see Class2.name or other such fields. I solved this by modifying the Spring Roo <field:display> custom tag – added an attribute fmtCollectionToString that if present forces the tag to evaluate collections by iterating them and calling toString on each element, instead of calling spring:eval on the whole collection, which also seems to end up with the Converter being invoked.

    Like I say, neater solutions greatly appreciated! If there’s a way of making converters behave differently in different circumstances, for instance – still want to hear it.

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

Sidebar

Related Questions

I have a MVC 3 project that uses Entity Framework. I can successfully update
I have an ASP.NET MVC project with a form. In the Action method that
I have a Mavenized Spring MVC project that deploys locally or remotely (passing all
I'm working on a Spring MVC project, and I have unit tests for all
I'm currently migrating a project that is using Spring MVC without annotations to Spring
So I have a spring mvc web application that I built in IntelliJ 9,
I have a Spring 3.1 MVC project, and I'm having trouble deserializing a request
i have been using the spring mvc frameworks lately for a university project. Could
I have a spring mvc project and am trying to test out a rest
I've been working on an ASP.net MVC project that uses checkbox HTML Helpers in

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.