1 2 3 Previous Next 61 Replies Latest reply on Sep 19, 2006 11:39 AM by Jim Hazen

    @SelectItems and @SelectItemsSelection annotations?

    Jim Hazen Expert

      I very much like Seam's enhanced support for JSF data tables. Are there plans to include support for other JSF types before the 1.0 release? Specifically I'd like to be able to handle SelectItems in a very similar manner.

      I guess I'll hit the src and see how complicated it would be to write. Any tips (or code donations) would be appreciated.

      -Jim

        • 1. Re: @SelectItems and @SelectItemsSelection annotations?
          js8523 Novice

          There is an open Jira for this (ithink around 132 area).

          When I discussed this previously I was thinking that we should tie it closer to the entities. With each ManyToOne or ManyToMany generating a selectable list .

          This may cloud the entity model with view centric behaviour?

          There is also a thread on the forum modeling lookup interface and converter using a session scope bean, have a look at that for information.

          Hope this helps,

          James

          • 2. Re: @SelectItems and @SelectItemsSelection annotations?
            Jim Hazen Expert

            It does help and got me thinking. I'm not sure what you mean about entities generating selectable lists. Unless you're talking about a seam custom JSF component that did that, and I don't see the value add there.

            I do like the idea brought up in the JIRA (129). A @Selectable annotation for lists. Not sure about the @Selectionname annotation mentioned in the list, seems limited to me. I guess if I were writing it my functionality would be:

            @Selectable(value="variableName", idMethod="methoda", valueMethod="methodb", ...)
            The annotation would have sensible defaults, but the optional parameters would allow for enhanced SelectItem mapping of arbitrary objects in a List (ordered collection).

            @Selected("variableName")
            Supplies a List of selected objects from the previous @Selectable or null if none were selected.

            I've included "variableName" in the @Selected annotation to hopefully allow a controller to handle multiple selections. This seems to be a limitation of the current @DataModelSelection and @DataModelSelectionIndex annotations.

            • 3. Re: @SelectItems and @SelectItemsSelection annotations?
              js8523 Novice

              Good thoughts on the idMethod and valueMethod.

              What I meant by "entities generating selectable lists" is that in the entity could be defined as

              @Selectable
              (therefore invoking the generation of a converter (for the object type) and attaching it to the jsf implementation).

              so you would have:

              @Entity
              @Name("customer")
              @Selectable(idMethod="...", valueMethod="...")
              public class Customer{
              ....
              }


              this would then mean that any location you have a list of customers you could have you own method to create the list of customers (perhaps passing them through a Seam converter to SelectItem's), and the converting would be handled automatically.

              But as I said this could be tying view functionality into the object model?

              Hope this explains that.

              If you don't have anything pre creating the converters on the fly (annotating entities) then the developer would still have to do this manually which is extra labour that could be automated.

              Interesting.

              James


              • 4. Re: @SelectItems and @SelectItemsSelection annotations?
                Jim Hazen Expert

                Yea. I think that adding @Selectable to an Entity would be too tightly coupling data and view. @Selectable is just not quite a record construct. On the other hand, I would be in favor of richer entity annotations that could be used down the road within the frameworks. Things like @Enabled, @Description, @ID (already there), etc. While it's inappropriate to apply specific tooling constructs to entities, it wouldn't be a bad idea to allow entities to expose commonly useful information to the tools/frameworks. I'm sure there will be plenty of debate on what is commonly useful and how to represent it.

                I suppose I'd support both. It's not always possible to modify your objects (third-party objects). So I'd start supporting the @Selectable annotation at the controller level. Maybe I'd then add support for some additional entity tags so that I could have the same @Selectable functionality without requiring the objects in my List to have a uniform interface.

                Thoughts?

                -Jim

                • 5. Re: @SelectItems and @SelectItemsSelection annotations?
                  Jim Hazen Expert

                  Upon further review of the code, @DataModelSelection and @DataModelSelectionIndex do use the value parameter to support multiple data models. This wasn't clear in the documentation, but does appear to be supported.

                  -Jim

                  • 6. Re: @SelectItems and @SelectItemsSelection annotations?
                    Jim Hazen Expert

                    Also, upon further reflection lets not get too generic with the intention of this annotation. If we're going to support a JSF construct, lets go with gusto. So I'm back to @SeletItems and @SelectItemsSelections (List of one or more, don't want to worry about whether the UI is selectOne or selectMany).

                    @Selectable may be more generic, but the parameters necessary to support things like SelectItemGroups would be odd in a @Selectable.

                    -Jim

                    • 7. Re: @SelectItems and @SelectItemsSelection annotations?
                      Jim Hazen Expert

                      I've finished my initial work on @Selectitems. It works like @DataModel. It will automatically convert an arbitrary List into a List that the JSF components expect (and publish into the appropriate scope).

                      I'll build in support for @SelectItems(labelMethod="", descriptionMethod=""...) later on today. For the time being the conversion is basic. value=object, label=object.toString().

                      My question is. Is anyone else interested in this functionality and would the Seam developers be interested in including this patch once complete? If not, what would be the best way for me to continue to benefit from Seam and this functionality without custom code in Component (custom interceptor)?

                      -Jim

                      • 8. Re: @SelectItems and @SelectItemsSelection annotations?
                        Gavin King Master

                        Submit a patch to JIRA. I don't promise to commit it, but I will give it due consideration.

                        • 9. Re: @SelectItems and @SelectItemsSelection annotations?
                          Jim Hazen Expert

                          Patch located here:
                          http://jira.jboss.com/jira/browse/JBSEAM-153

                          Currently includes support for @SelectItems and an enhanced registration example which demonstrates some of its functionality.

                          If accepted I wouldn't mind contributing additional functionality (additional field level annotations for individual items within data list, @SelectItemsSelection, etc) and documentation.

                          • 10. Re: @SelectItems and @SelectItemsSelection annotations?
                            Jason Long Master

                            It this functionality likly to be included? If so when?

                            • 11. Re: @SelectItems and @SelectItemsSelection annotations?
                              Pete Muir Master

                              I've been thinking about ways to do this. I'm currently stuck on one aspect:

                              To do this successfully a JSF converter is needed. The converter needs to do getAsObject, the way I've seen this done is

                              Object o = entityManager.find(Entity.class, id);
                              


                              but this requires a handle on the EntityManager (which is user definable, with possibly more than one defined within an application).

                              Does anyone have any suggestions/recommendations on how to get the 'correct' EntityManager - a configuration parameter? The default?

                              Thanks

                              Peter

                              • 12. Re: @SelectItems and @SelectItemsSelection annotations?
                                Gavin King Master

                                Get it from JNDI. Make sure you set jboss.entity.manager.jndi.name or whatever it is called in persistence.xml.

                                • 13. Re: @SelectItems and @SelectItemsSelection annotations?
                                  Pete Muir Master

                                  I've now written an implementation of this, but on my last CVS update I've noticed that there is now a DataBinder that will do this as well!

                                  Here it is but I think that Gavin's version is much more elegant! Only a couple of days wasted!

                                  http://jroller.com/resources/p/pmuir/selectable.patch.java

                                  • 14. Re: @SelectItems and @SelectItemsSelection annotations?
                                    Pete Muir Master

                                    Oh and is it planned for there to be explicit SelectItems support added to Seam or do we need to write it ourselves using the DataBinder stuff?

                                    1 2 3 Previous Next