Announcement Announcement Module
Collapse
No announcement yet.
Clinic.roo script combo box data list items. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Clinic.roo script combo box data list items.

    Hi,
    We are testing roo for one of our projects. We ran script clinic.roo script and all runs ok. However when we try to create a visit object, the vet list box displays wierd items like .. id 1, Version 0, Firstname: Gary ... etc. We would like to display just the Firstname only. What changes are needed in the script?
    Also command dod doesn't work, there is no sample data loaded in pojos.

    -Irshad.

  • #2
    That weird behavior you are seeing is because roo simply uses the generated toString() method when displaying the elements of the dropdown.
    The probably easiest way to get around this is to remove the @RooToString annotation from the affected class (here it is vet) and supply your own toString-Method that only prints the name.

    This is something you have to change in the code not in the script.

    Comment


    • #3
      Or if you want to retain the original toString() method for debugging purposes, you can change the update and create views to display a given field value instead of calling toString(), by adding the bit in blue (as explained in the Spring taglib doco):

      Code:
      <form:options itemValue="id" items="${vets}" itemLabel="firstName"/>
      Be aware though that Roo will overwrite those changes next time it runs unless you tell it not to (by setting automaticallyMaintainView = false in the controller).

      Comment


      • #4
        You can also write your own toString() method and then get Roo to generate you an inbuilt toString via changing the @RooToString annotation to something like @RooToString(toStringMethod="myGeneratedToString") : http://static.springsource.org/sprin...oToString.html

        Comment


        • #5
          Do the above comments hold good for 1.1.0 M1? I am yet to try them out. I am on the verge of delivering a spring roo based application to a client. The only show stopper for me is the data that is shown in the dropdowns. In my case, the user needs to enter the details of the city where he has to select the state from the dropdown. He is however presented with the statename as well as other fields from the states table as part of the dropdown. I guess it must be the generated tostring which is causing this.

          Need some clarification on this one. Assistance in this regard would be a great help.

          Comment


          • #6
            Yes, my previous advice on toString() still applies. Just write a toString() by hand and you should be fine.

            Comment


            • #7
              don't forget about the converters

              I tried to get drop downs to change using this advice of changing the toString method, and thought app wasn't working correctly and building me 'newest' version.

              Found that the problem was in the converter generated by Aspectj for the controller as it's what determines what parts of model are returned to jsp and then added to form.

              Comment


              • #8
                Try to override converters?

                The approach that I tried was to pull-in the generated converters (along with the 'registerConverters' method) from the .aj into the .java source; and modify them. It is partially successful - the customised converter is activated from the 'show.jspx', but not from the 'list.jspx'. I don't understand why - as far as I can follow, show.jspx ends up invoking "spring:eval object[field]" (in display.tagx) and list.jspx ends up invoking "spring:eval item[column]" (in table.tagx); which should result in the same.

                The approach of changing the name of the generated 'toString' method does have the desired effect, though.

                Comment


                • #9
                  override converters to suit your needs

                  yes, this is what I ended up doing, and it worked for most things. However, I've still not found how to display a date as dd/mm/yyyy, or even mmm/yyyy instead of getting java.util.Calandar showing up in a drop-down box. Any ideas for that greatly appreciated.

                  Comment


                  • #10
                    Re: override converters to suit your needs

                    pgf & scharlau how did you guys manage to pull in the generated converter?

                    When I do this I have to also pull in the 'registerConverters' method. Wich forces me to add
                    Code:
                    @Autowired
                    protected GenericConversionService conversionService;
                    to my controler. After I do that the roo console keeps giving me this message
                    Code:
                    ...Field 'conversionService' already defined in target type...
                    ans stops managing my .aj files

                    Comment


                    • #11
                      Work around to this problem

                      If anyone is interested, someone as an interesting work around to this problem. You can find it here

                      It worked for me.

                      Comment

                      Working...
                      X