1 2 3 4 5 Previous Next 61 Replies Latest reply on Sep 19, 2006 11:39 AM by cptnkirk Go to original post
      • 45. Re: @SelectItems and @SelectItemsSelection annotations?
        pmuir

        I've put my version here: http://bigbob.splendid.co.uk/selectitems.tar.gz. It works well but isn't well packaged (no examples etc.). If I get time to tidy it up I'll put it on the wiki.


        The attached files provide a @SelectItems databinder for Seam. It has a label attribute that is the name of a field/property on each object in the outjected list. If the label attribute is empty object.toString() is used. @SelectItems can be used for any Object.

        Also provided is an EntityConverter. This requires the objects specified in the <f:selectItems value="..." /> to have the Entity annotation. It should be set in your favourite way:

        • By Class (each class which requires this converter is specified in faces-config.xml)
        • By Id (specify in faces-config.xml, specify id in view)
        • Using EL (load from a function as an inner class)
        • Use facelets to set as default converter for selects (I place the h:selectXXX in a source tag file with an optional converter attribute (on the source tag), if the converter attribute is not set then load the EntityConverter, code available if needed)


          Corrections/queries are most welcome.


        See also: http://jroller.com/page/pmuir?entry=selectitems_for_seam

        • 46. Re: @SelectItems and @SelectItemsSelection annotations?

          Jason,

          I can see the desire for a "Pick one" default option to force a selection of a drop down, but why limit the availability to those using the Object strategy?

          If the DataBinder adds elements implicitly, it will make life harder on a selector as any lookup would possibly need to discount the selection of this element. It's workable but muddies the waters a bit. And then there's the question of whether or not a binder should be adding elements, or if that's the job of the application.

          This obviously works, but is it the best way? I don't know.

          -Jim

          • 47. Re: @SelectItems and @SelectItemsSelection annotations?

            I only made it work for the Object strategy, because that is all I am using currently.

            I also did consider adding the object myself and this might be better, but less automatic.

            I also thought that the message will not be internationalized.

            For my use case this does not matter currently, but for others it could be a requirement.

            My converter is handling the no selection.

            I am starting to wonder about my use of converters in general.

            Before with Struts I validated each form submit method individually as different actions had different validation requirements. I believe that this approach is more flexible. If I add validators or converters to elements it seems I will lose this flexibility because they have no knowledge of which button was clicked.

            Maybe this is a topic for a different thread. :)

            • 48. Re: @SelectItems and @SelectItemsSelection annotations?
              pmuir

              I'm just packaging my @SelectItems implementation to put it on the wiki. What package name is best to use? Something under org.jboss.seam? org.jboss.seam.extensions.selectitems perhaps?

              Also what namespace for taglib.xml. Seam's uses http://jboss.com/products/seam/taglib so perhaps http://jboss.com/products/seam/extensions/selectitems/taglib?

              • 49. Re: @SelectItems and @SelectItemsSelection annotations?

                All good questions Pete. I'll defer to the Seam Gods. org.jboss.* may be reserved and imply that these are official JBoss modules. Maybe contrib.seam.extensions? Or following with the seam package structure, contrib.seam.annotations, contrib.seam.databindings, etc

                • 50. Re: @SelectItems and @SelectItemsSelection annotations?
                  pmuir

                  I think that contrib is better than extensions. I'm pretty sure that the xml namespace must be a uri which limits choice somewhat.

                  Seam Gods, what say ye?

                  • 51. Re: @SelectItems and @SelectItemsSelection annotations?

                    Gavin won't be online until Sunday. Do you just want to go with

                    contrib.seam.*

                    and

                    http://jboss.com/products/seam/contrib/*

                    Tip of the hat or wag of the finger. I don't see much down side in moving ahead. Worst that happens is that we need to repackage and repost down the road. I need to repackage into something respectable anyway.

                    • 52. Re: @SelectItems and @SelectItemsSelection annotations?
                      theute

                      Go with org.jboss.seam.selectitems we will eventually include it in the codebase under src/extra or directly in the main with your agreement of course.

                      For the taglib go with:
                      http://jboss.com/products/seam/selectitems/taglib

                      Thanks for your contribution !

                      • 53. Re: @SelectItems and @SelectItemsSelection annotations?
                        trouby

                        Hey,

                        there's a parameter for the 'SelectItems' annotation named 'valueMethod' which accept as a parameter the method name to set the 'value' for each of the selections,


                        A little bug there, instead of using valueMethod, there's a user of labelMethod,



                        So, in class SelectItemsBinder, line 122:

                        instead of:
                        String methodName = ann.labelMethod();

                        should be:
                        String methodName = ann.valueMethod();


                        Hope it helps,

                        Cheers,

                        Asaf.

                        • 54. Re: @SelectItems and @SelectItemsSelection annotations?

                          Oops, you are correct. I've made the change and will put out a new package later today.

                          • 55. Re: @SelectItems and @SelectItemsSelection annotations?
                            pmuir

                            The @SelectItems component I've discussed above is done:

                            http://bigbob.splendid.co.uk/selectitems.zip

                            I still need to improve the example and add more documentation, but the component itself is done.

                            Some notes (which need tidying up): http://jroller.com/page/pmuir?entry=selectitems_revisited

                            It's also linked from the wiki.

                            • 56. Re: @SelectItems and @SelectItemsSelection annotations?

                              I've also updated my wiki packages to include that bug fix as well as reflect the new package structure.

                              http://www.jboss.com/wiki/Wiki.jsp?page=JBossSeam

                              Sooner or later a true component repo will need to be knocked out. I know a lot of people like Maven and its repository support. I'd at least like to know when code is modified (watcher) and have basic changelog support. Maybe I should create a new page for my component and keep that current. Right know folks just add to this topic to report issues and request features. I'm open to suggestions for improving that setup. It would be nice if JBoss would host Seam components as well as provide issue tracking. I guess a wiki page is the best solution for changelogs and binaries. Could there be a contrib/third-party component to Seam's JIRA project?

                              We already have two @SelectItems implementations in our repo. They both do very similar things, should there be an effort to consolidate, or is this futile? Variety is a blessing and a curse.

                              • 57. Re: @SelectItems and @SelectItemsSelection annotations?

                                I've created a wiki page that should be a more permanent home for my DataBinder and added it to the components section of the Seam wiki. Unfortunately I don't see a way to remove attachments from the wiki. I'll deal with the Seam home page clean up later.

                                http://wiki.jboss.org/wiki/Wiki.jsp?page=SelectItemsBinder

                                Future features planned:
                                * startLabel="Pick One..." support
                                * Utility to ease selected value -> original object lookup (until there's a proper @SelectItemsSelected)

                                • 58. Re: @SelectItems and @SelectItemsSelection annotations?
                                  pmuir

                                  Something I think would be useful would be a 'how to write components guide' - covering packaging, example writing, documentation, where to submit to ...

                                  I'm open to consolidation - as you say the binder side is very similar!

                                  • 59. Re: @SelectItems and @SelectItemsSelection annotations?

                                    Hi,
                                    I just had a few hours of nice debugging time with the @SelectItems stuff.

                                    This first one works ok:


                                    <h:selectOneListbox value="#{selector.selectedRegion}">
                                    <f:selectItems value="#{regions}"/>
                                    </h:selectOneListbox>


                                    but this doesn't

                                    <h:selectOneListbox value="#{region}">
                                    <f:selectItems value="#{selector.regions}"/>
                                    </h:selectOneListbox>




                                    "selector" is SFSB with get/setRegions, get/setSelectedRegion in local interface and

                                    @SelectItems
                                     public List getRegions() {
                                     List<Region> regions = (List<Region>) em
                                     .createQuery("from Region").getResultList();
                                     return regions;
                                    }
                                    


                                    Instead the second one gives the following exception:

                                    2006-09-19 15:14:57,367 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/tc3Web].[jsp]] Servlet.service() for servlet jsp threw exception
                                    java.lang.IllegalArgumentException: Collection referenced by UISelectItems with binding '#{selector.regions}' and Component-Path : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /kohteen_valinta.jsp][Class: javax.faces.component.html.HtmlForm,Id: _tc3Portlet_kohteen_valinta_WAR_TrueConcept__id0][Class: javax.faces.component.html.HtmlSelectOneListbox,Id: _tc3Portlet_kohteen_valinta_WAR_TrueConcept__id1][Class: javax.faces.component.UISelectItems,Id: _tc3Portlet_kohteen_valinta_WAR_TrueConcept__id2]} does not contain Objects of type SelectItem
                                     at org.apache.myfaces.util.SelectItemsIterator.next(SelectItemsIterator.java:182)
                                     at org.apache.myfaces.renderkit.RendererUtils.internalGetSelectItemList(RendererUtils.java:487)
                                     at org.apache.myfaces.renderkit.RendererUtils.getSelectItemList(RendererUtils.java:461)
                                     at org.apache.myfaces.renderkit.html.HtmlRendererUtils.internalRenderSelect(HtmlRendererUtils.java:272)
                                     at org.apache.myfaces.renderkit.html.HtmlRendererUtils.renderListbox(HtmlRendererUtils.java:235)
                                     at org.apache.myfaces.renderkit.html.HtmlListboxRendererBase.encodeEnd(HtmlListboxRendererBase.java:73)
                                     at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:331)
                                     at javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:349)
                                     at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:253)
                                     at org.apache.jsp.kohteen_005fvalinta_jsp._jspx_meth_h_selectOneListbox_0(kohteen_005fvalinta_jsp.java:254)
                                     at org.apache.jsp.kohteen_005fvalinta_jsp._jspx_meth_h_form_0(kohteen_005fvalinta_jsp.java:143)
                                     at org.apache.jsp.kohteen_005fvalinta_jsp._jspx_meth_f_view_0(kohteen_005fvalinta_jsp.java:102)
                                     at org.apache.jsp.kohteen_005fvalinta_jsp._jspService(kohteen_005fvalinta_jsp.java:64)
                                     at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
                                     at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
                                    


                                    So instead of the wrapped result the original List (of Regions) is passed to f:selectItems.

                                    Is this expected behaviour?