• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Many-to-Many form with checkboxes,no converter java.lang.String to type @javax.persistence.OneToMany

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good morning,
i'm current learning Spring MVC (java annotation), hibernate, thymeleaf, Spring webflow2 making a big application for a sales network managment for the company where i'm working.

I had many problems in the past months, but i always found a solution; but this time i really can't get out of this trouble and, also on Stackoverflow, i can't get help.

The absurde thing is that i'm stuck in a very common step in web development: a simple form with checkboxes!!!

I have a Many-to-many relationship, realized following this tutorial hibernate-many-to-many-example-join-table-extra-column-annotation

I have one many-to-many relationship between Contest and Services. In the middle i have 2 classes: ContestServiceId, and ContestService.

Contest class:



Service class:


ContestSercvice class:


ContestServiceId class:



I'm trying to make a webflow where, in one step, i can select (checboxes) which Services are involved in the Contest; but when i try to load that page i get this error:

org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type java.lang.String to type @javax.persistence.OneToMany java.util.Set



How can i make this converter?

I already did one converter for each single entity (eg. StringToContestConverter, useful, for example, for select).

I tried to do an empty converter (with no code inside because i don't know what i have to do with ids)
and i set a breakpoint... it never stop there...




Here the code used in my view that generate the error:




services_list is binded in the flow with:





Another try i did it was this:


but when i submit the form, i get validator error:

typeMismatch on contestServices





I tryed use Set, List, TreeSet, LinkedHashSet but nothing... If i have to change how to implement ManyToMany relationship may not be a problem... but i really need have this page where check which services are involved in contest...
It's not possible that i'm the first tryingo to do this...


thank you for any tips or suggestion.
 
Alan Morelli
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm looking for a Conversion Service or a Binding service, but still not have idea how to do it and use in webflow
 
Alan Morelli
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found a solution. I don't think is the best but it works:

- in the view, i give a name to all checkboxes (chk_services, chk_agencies)

- on transition to the next step, i take the comma separated string generated from POST with the checked ids (id1, id2, ...) and i pass to a method
which split the string and, for each id, takes from db the related entity and put these in my Set of many-to-many entity (ContestService)



(i do this either when i go to the next step and to the previously step)

- on entry to the view, i want check again the checkboxes. to do this, i need to convert my Set<ContestService> to a list of ids:


- in the view, i see if check or no each checkbox with:



NOTE: '' + service_el.id is needed as without '' + it doesn't work


I post full code. i hope that someone will find it useful.

Any improvements and suggestion are welcome.


Webapp config (i'm using java annotation):
configuration of the bean with methods used in the flow



ContestFlow bean with my methods:




View of the step 2: form with services checkboxes:



View of the step 3: form with agencies checkboxes:



finally: the flow xml configuration:
reply
    Bookmark Topic Watch Topic
  • New Topic