3 Replies Latest reply on Feb 3, 2011 4:30 PM by yahawari

    Really need a solution to this problem (dynamically adding entries)

    nraf

      I've been using Seam for about a month and it's been pretty good. The more I've learned, the more impressed I've become.


      However there's one problem that I've been struggling to deal with for a while and no solution has worked.


      To paint a picture of what I'm trying to achieve, look at Facebook. When somebody posts a new message, that message is appending to the top of the list. I can like that, reply to it, etc and only that message will be updated. There's no need for me to refresh the entire page or the entire list of messages.


      The same goes with loading more messages. When I click to load older messages, the messages currently displayed are refreshed. Rather, the new messages are appended to the end of the list.


      This sort of functionality is what I've been struggling to implement in Seam for a long while now and it just isn't working.


      I want a way to add new entries using ajax (updating an existing entry is extremely easy in comparison). At the moment I'm using RichFaces however the repeat or datatable components don't seem able to perform this task (which has me confused, given that this seems like quite basic functionality).


      Has anyone dealt with a similar case before? The solution doesn't need to be related to RichFaces. I'm just after anything that works elegantly (or even not all that elegantly) at this point.


      Any suggestions will be highly appreciated!

        • 1. Re: Really need a solution to this problem (dynamically adding entries)
          monkeyden

          Maybe I'm misunderstanding you but, are you using something like this:


          [take input]
          <h:inputText id="username" value="#{myBean.newMessage}">
              <a4j:support event="onblur"/>
          </h:inputText>
          <a4j:commandButton ajaxSingle="true" action="#{myBean.addMessage}" reRender="myDataTable">
          
          [display messages]
          <rich:dataTable id="myDataTable" value="#{myBean.messages}" var="message">
          ... 
          </rich:dataTable>
          



          to perform the action?  Note the reRender attribute.  As for the latest message on top, that's just a matter of sorting by date on the (re)query or, if you're trying to keep real-time queries to a minimum, the top of the list.

          • 2. Re: Really need a solution to this problem (dynamically adding entries)
            nraf

            reRender will re-display the entire list, or a subset if using ajaxKeys. It can't add a new row to the datatable, howeve with an entire redraw. If I have 10 messages displayed on screen and the user enters a 11th, I don't want to have to rerender all 10 messages - I want to append that 11th to the screen dynamically without having to do anything (at least on the server-side) to any existing message.

            • 3. Re: Really need a solution to this problem (dynamically adding entries)
              yahawari

              when u need this fine level of control, u are better off using javascript and seam remoting.


              in richfaces, there is ajaxKeys attribute for data iteration components which reRender certain rows rather than the whole table. for ur usecase, i am not sure what components will do it.


              as i said, javascript is good for this scenario :) !