11 Replies Latest reply on Dec 17, 2007 4:27 AM by djfjboss

    @DataModel s:link h:commandButton h:dataTable

      I'm very puzzled regarding the behaviour and interaction of the above components. I have used them successfully in some contexts, but am having problems with them in other contexts but can't see any pattern.

      My understanding was that s:link is to be preferred over the non-Seam h:commandButton but things do not seem to be quite that simple as this simple example demonstrates:

      <rich:panel>
       <f:facet name="header">Why Doesn't This Work?</f:facet>
       <h:form>
       <h:dataTable value="#{accountService.things}" var="thing">
       <h:column>
       <f:facet name="header">Name</f:facet>
       <h:outputText id="name" size="10" required="true"
       value="#{thing.name}">
       </h:outputText>
       </h:column>
       <h:column>
       <f:facet name="header">Size</f:facet>
       <h:outputText id="size" size="10" required="true"
       value="#{thing.size}">
       </h:outputText>
       </h:column>
       <h:column>
       <s:link value="Select"
       action="#{accountService.selectThing(thing)}" />
       </h:column>
       <h:column>
       <h:commandButton value="Select"
       action="#{accountService.selectThing(thing)}" />
       </h:column>
       <h:column>
       <s:link value="Select (dsm)"
       action="#{accountService.selectThing()}" />
       </h:column>
       <h:column>
       <h:commandButton value="Select (dsm)"
       action="#{accountService.selectThing()}" />
       </h:column>
       </h:dataTable>
      
       <h:commandButton value="Show Choices"
       action="#{accountService.getThings()}" />
       </h:form>
       </rich:panel>
      



      and the corresponding service class:

       @DataModel
       private List<Thing> things;
      
       @DataModelSelection("things")
       private Thing selectedThing;
      
       public List<Thing> getThings() {
       ThingRepository repository = new ThingRepository();
       things = repository.getThings();
       return things;
       }
      
       public String selectThing() {
       log.info("### DJF Selected: " + selectedThing);
       return null;
       }
      
       public String selectThing(Thing thing) {
       selectedThing = thing;
       log.info("### DJF Selected: " + selectedThing);
       return null;
       }
      


      (yes I know I should use a static for the repository ...)

      The repository spits out:
      One_1
      Two_22
      Three_333
      Four_4444
      Five_55555
      Size_666666

      I then select the second, third, fourth and fifth lines (in that order) with the following surprising (to me at least) results:

      16:54:43,322 INFO [AccountService] ### DJF Selected: null
      16:54:44,665 INFO [AccountService] ### DJF Selected: Three_333
      16:54:45,931 INFO [AccountService] ### DJF Selected: One_1
      16:54:47,353 INFO [AccountService] ### DJF Selected: One_1

      One out of four is correct! Why null? Why does it incorrectly select the first element when I have selected a different element?


        • 1. Re: @DataModel s:link h:commandButton h:dataTable
          pmuir

          RTFM - commandButton submits the form, s:button doesn't.

          • 2. Re: @DataModel s:link h:commandButton h:dataTable

            RTFM - this kind of arrogance really 'F' ing annoys me.

            I am trying to get to grips with a technology that does not appear to always live up to its claims. I have read the documentation, not end to end but enough to begin to dabble. I then created a simple example that blows the "principle of least surprise" (are you familiar with this?) away completely and the best this forum can offer is this kind of rudeness. You need to do better than this.

            Aside from any confusions regarding s:link and h:commandButton, the handling of the argument and the bound variable is also not what the innocent might expect.

            I resubmit my question in the hope that someone less arrogant and more helpful than Mr Muir might be more tolerant of those of us who don't have time to sit down and read the source code.

            • 3. Re: @DataModel s:link h:commandButton h:dataTable

              Do you know how many times this has been asked on this forum?

              I personally have every forum post sent to my email and I review it there.

              It used to be mostly constructive suggestions or intelligent questions.

              I am extremely tired of reading though all of these newbie questions that have been answered 100 times already.

              Remember this is free software, and no ones owes you anything.

              Try asking new questions that will help Seam move forward instead of hammering the developers the same old tired questions.

              • 4. Re: @DataModel s:link h:commandButton h:dataTable

                While I have no desire to engage in a stream of personal abuse, that is what I have received so far. This forum seems to be populated by either 'stupid newbies' such as myself or arrogant people such as yourself.

                In answer to your question do I have any idea how often that question has been posted I have to state 'no'. But that is not for want of looking - before submitting my ignorant newbie question I did a search to see if the answer was already there but found nothing. I personally do not have the time to read every forum post - nor would I have thought do most people - that's a completely unreasonable expectation.

                Stepping back a little and trying to me more constructive, it seems to me that there is a lack of adequate documentation (an opportunity for someone). The books that are currently available are (mostly) ok up to a point but do provide only a superficial explanation of some of the underlying concepts and associated details where the devil really does reside. This forum no doubt contains a wealth of information but it also contains a lot of noise (no doubt much of it created by people such as myself). Would it be possible for some moderator to extract what golden nuggets appear and collate and index them so that these common questions can more quickly and less frustratingly be directed to the appropriate answers? Some post-processing of the content of this forum would most definitely be useful.

                • 5. Re: @DataModel s:link h:commandButton h:dataTable
                  pmuir

                   

                  "djfjboss" wrote:
                  This forum no doubt contains a wealth of information but it also contains a lot of noise (no doubt much of it created by people such as myself). Would it be possible for some moderator to extract what golden nuggets appear and collate and index them so that these common questions can more quickly and less frustratingly be directed to the appropriate answers? Some post-processing of the content of this forum would most definitely be useful.


                  This would be superb! I suggest you use a wiki (e.g. the jboss wiki), and post the link here. We can make it sticky then.

                  • 6. Re: @DataModel s:link h:commandButton h:dataTable
                    damianharvey

                    The people on this forum really are very friendly and extremely helpful. It just needs a reciprocal amount of effort - which starting a Wiki page would be a good example of. Maybe start with something like "Understanding Seam DataModels" and use this thread as a basis?

                    Regarding your question though; From the manual:

                    27.10.1. Annotations for use with dataTable

                    @DataModel
                    Outjects a property of type List, Map, Set or Object[] as a JSF DataModel into the scope of the owning component (or the EVENT scope if the owning component is STATELESS).

                    In your Bean you declare your DataModel as
                    @DataModel
                    private List<Thing> things;

                    This outjects a DataModel context variable called 'things' into the same scope (eg. Event, Session) as your Bean.

                    But in your datatable you refer to
                    <h:dataTable value="#{accountService.things}" var="thing">
                    which is just a list and not a DataModel. Try changing it to
                    <h:dataTable value="#{things}" var="thing">

                    Hope this helps.

                    Cheers,

                    Damian.


                    • 7. Re: @DataModel s:link h:commandButton h:dataTable

                      Damian

                      Many thanks for your reply - I could have RTFMd many times over and still not have spotted my error. I assumed that I could access the variable via the #{a.b} notation - it never occurred to me to try #{b} unless I'd already defined @Name("b") somewhere. This style of reference is not one that comes naturally to me.

                      With this small but very important change both s:link and h:commandButton work - the issue regarding submitting the form does not seem relevant, but maybe it is!

                      Unfortunately, this success leads to another newbie question!
                      I'm more than happy to contribute this to the pot and looked at the Wiki page to see how to do it. I created a new entry under Tips (DataModel/DataSelection easy when you know how) which takes me to an undefined page that I then provided some content for and saved it. But when I returned the content had all gone! Kindly indulge my ignorance a little further and I'll put the material on the Wiki.

                      Thanks again,
                      David

                      • 8. Re: @DataModel s:link h:commandButton h:dataTable
                        damianharvey

                        No worries. I think that the '/' in your Wiki title is the problem there.

                        Cheers,

                        Damian.

                        • 9. Re: @DataModel s:link h:commandButton h:dataTable

                          I have created a new Tip on the Seam Wiki that describes my traumas with DataModel, and Damian's valuable insight that fixed it.

                          I hope this will be of use to others in the future. However, I still think that active separation of wheat from chaff by a knowledgeable moderator would be very useful - though I do understand that it may be an unacceptable burden on those already under quite a heavy load.

                          Please let me know if the content is acceptable.

                          Thanks.

                          • 10. Re: @DataModel s:link h:commandButton h:dataTable

                            Sorry, I was hard or you.

                            I still recommend scanning all of the forum posts through email. It may take time, but it will prevent problems.

                            You will avoid problems and also know what the latest tips and tricks are.

                            There are about 80-100 posts a day. After a while you will be able to weed out newbie ones and only consider 10 or so for more than 10 sec.

                            It takes about 15-30 minutes a day to run through them, and it is worth it in the long run.

                            This project is moving so fast that this is the best way to keep on top of it.

                            • 11. Re: @DataModel s:link h:commandButton h:dataTable

                              No problem - I can understand the frustration you feel from your side of the fence as well!

                              Thanks for the suggestion.

                              David