a4j:repeat - Dynamically appending a new element

2019-07-29 10:10发布

问题:

I'm trying to implement (as part of a larger system) a feature where a user is able to post a message. When the user clicks the post button, I'm using RichFaces and a4j to retrieve the generated post using ajax.

I'd rather not have the post show up automatically as soon as the response is returned. Rather, I'd like to add an output panel inside a hidden div. When the user clicks on the post button, that output panel will be populated but obviously hidden from the user.

What I would like to do afterward is move the new element from the hidden div to it's correct position using jQuery.

Anyway, the issue here is I'm using the ajaxKeys property of a4j:repeat to update a single row when an action is taken against it. For example, if somebody gives the row a rating of 5, I want to rerender only that row (by setting the correct key on the server-side).

If I use this method, whilst moving the ajax-created element to be besides the other posts will work fine initially, if a user takes an action against that row, I don't believe a4j:repeat will be able to work with it given that it didn't generate it itself.

Is this correct? If so, is there any workarounds anyone can suggest?

Facebook are able to achieve a similar thing. You can create or remove a post as well as comment on a post and only have that object updated. I'm starting to think that a4j:repeat may not be the best way to approach this issue. Thoughts?

回答1:

I've had a similar problem some time ago. I tried tried and was not able to make it work.

Eventually I decided to use javascript and Seam Remoting which allowed me to have more control about what was happening. I managed to make it work with that approach.