Announcement Announcement Module
No announcement yet.
Selected options in SELECT tag using Converter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Selected options in SELECT tag using Converter

    Hi all,

    I noticed a weird behaviour using Spring webflow 2.0.6 and spring webmvc 2.5.6 over the select tag.

    I'm using a converter to automatically convert the attribute from my form and options in my collection. Everything is converted alright both sides, but there is an issue with the isSelected feature (from options tag).

    I was hoping that isSelected method would actually compare the String-converted object to check equality. Apparently not. Is that normal?

    Is this issue part of SWF project or does it has its place here?

    Thanks for your help

  • #2

    We just upgraded from Web flow 2.0.5 to 2.0.7 and we now have the same behaviour as explained here.

    I can't figure out how to get it working properly again. The following work around works, but i'd prefer to go back to how it was set up with 2.0.5.

    In the Bean class of your collection, override the toString() method and let it return the ID of the bean (the attribute identifying your object and used in the option value html attribute).

    You may have to get rid of the itemValue attribute of the form options tag as well, I did this when I tried my work around, but I don't think it necessary...



    • #3
      Hi there,

      Well, I started with 2.0.5, and had the problem. I thought about the workaround of the "toString()", but upgrading to 2.0.6 solved the problem, still working with 2.0.7.

      Are you sure your converter is registered properly? Do you use form-options?
      Here's my JSP code :

      <form:select path="bip">
      	<form:option value="">[select one value]</form:option>
      	<form:options items="${bipList}" itemLabel="labelAttribute"/>
      Note that I don't specify any itemValue in the tag.


      • #4
        Hi again,

        Yep, using form-options.

        This is the code we had working in 2.0.5
        <form:select path="vaccinationProgrammeItem.vaccineType" multiple="false">
        	<form:option value="">Text.../form:option>
        	<form:options items="${vaccinationProgrammeItemForm.vaccineTypes}" itemValue="vaccineTypeId" itemLabel="name" />
        This is the work around cod, itemValue is removed. v2.0.7
        <form:select path="vaccinationProgrammeItem.vaccineType" multiple="false">
        	<form:option value="">Text.../form:option>
        	<form:options items="${vaccinationProgrammeItemForm.vaccineTypes}" itemLabel="name" />
        This is how we register our converter
        public class ApplicationConversionService extends DefaultConversionService {
            protected void addDefaultConverters() {
               // Registers a default converter for VaccineTypeBean type
               addConverter(new StringToVaccineType());
        I have debugged the converter and the both the overridden methods are called. during either GET or POST.

        Also, i'm guessing the converter should be used when the select is populated. The select does populate nicely. And there is no problem selecting a value and posting it. It ends up in the database.

        The problem of getting the correct value selected in select box stays though...

        Any help appreciated!


        • #5

          I'm having the same problem getting the selected item set into the select box. My converter is getting fired in both directions (when posting the selected value and when populating the select box from the list of items) but not when choosing the selected item.

          I can get it working by either:
          1) adding an equals() method on my model object to compare the database IDs
          2) overriding toString() to return the database ID

          I never had any problems with this before using web flow 1.0 with property editors.

          Any insight would be appreciated.


          Spring: 2.5.6.SEC01
          Web flow: 2.0.8.RELEASE


          • #6
            I know this is a really old topic but I just had the same problem in my application. Everything was converted fine and populated, only the "selected" attribute was missing in the option.
            I've compared with the demo application "petclinic" where this behavior was working fine and I found that the only difference was in web.xml. To make it works I had to add OpenEntityManagerInViewFilter!!!!

            HTML Code:
                    <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
                    <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
            I don't know why but it seems to be some dependency to it, I hope this will save to another poor guy two days wasted.