webtier@glassfish.java.net

[JSF 2] Problem with CommandLinks in ajax-updated list

From: <webtier_at_javadesktop.org>
Date: Tue, 16 Mar 2010 08:48:41 PDT

Hi,

I have some serious problems getting AJAX to work properly in my JSF2 application. In that application, I have a list of comments for a photo. That list should be managed by either adding new entries via a form or removing existing entries by clicking a link next to that entry.
Adding new entries works perfectly now, the list gets updated and everything's fine. What also works is removing one single entry.

However, as soon as there has been an update to the list, be it either an add or a remove, the command links inside the list stop working properly. The ajax request still goes off, but the list returned is completely empty (JS debug revealed the returned result: <ul></ul>). Also, the action listener defined for the remove link is not fired on the server.
If I add another entry, the list is refreshed correctly again (with the newly added entry), but, of course, as the action listener was not fired, the entry to be deleted before is still there. Completely refreshing the page shows up the page correctly and lets me delete one entry again before things start over.
Here is the according code snippet:

<h:panelGroup id="comments">
                        <ul>
                                <ui:repeat var="comment" value="#{ScopedPhoto.entry.comments}">
                                        <li>
                                                <h:form>
                                                        <h3>#{comment.title}</h3>
                                                        <p>#{comment.comment}</p>
                                                        <p>(created @#{comment.created})
                                                                <h:commandLink actionListener="#{comment.commitDelete}" value="X">
                                                                        <f:ajax render=":comments" execute="@form"/>
                                                                </h:commandLink>
                                                        </p>
                                                </h:form>
                                        </li>
                                </ui:repeat>
                        </ul>
                </h:panelGroup>

<h:form>
                                                
                        <h2>Add a comment</h2>
                        <dl>
                                <dt>Title:</dt>
                                <dd>
                                        <h:inputText value="#{ScopedPhoto.entry.newComment.title}">
                                                
                                        </h:inputText>
                                </dd>
                                <dt>Comment:</dt>
                                <dd>
                                        <h:inputText value="#{ScopedPhoto.entry.newComment.comment}" required="true">
                                                
                                        </h:inputText>
                                </dd>
                        </dl>
                        <h:commandButton value="Add Comment" actionListener="#{ScopedPhoto.entry.newComment.commitInsert}" >
                                <f:ajax render=":comments" execute="@form"/>
                        </h:commandButton>
                </h:form>


So I hope anyone has an idea how to fix this =)
[Message sent by forum member 'jf7' (javafrog_at_javafrog.de)]

http://forums.java.net/jive/thread.jspa?messageID=392185