开发者

JSF: Partially adding text to component from AJAX call [duplicate]

开发者 https://www.devze.com 2023-03-07 18:47 出处:网络
This question already has an answer here: 开发者_运维百科 How to monitor asynchronous/background thread status and get notifications in a JSF component
This question already has an answer here: 开发者_运维百科 How to monitor asynchronous/background thread status and get notifications in a JSF component (1 answer) Closed 6 years ago.

I want a inputTextarea to display lines appended to some text file. I imagine it like this: The user clicks a commandButton that does a AJAX call.

My problem is: The text will only be rendered when the action returns. However, my action should look like this:

while(true) {
  String newData = getSomeMoreDataFromServer();
  // append the new data to a textarea and the user should see it immediately
  if(blabla) { break; } 
}

Is this even possible? The part that's commented out is the part that bothers me.

Can the user even set the break condition in the form somehow?

I'm using JSF 2 (MyFaces) + Tomahawk.


That's not possible from inside the backing bean action method. Also having a while(true) is very CPU-inefficient, you'd rather like to avoid that in a multi-user environment. What you're looking for is ajax poll/push. This is not provided in the standard JSF implementation and also not in Tomahawk. PrimeFaces for example, supports ajax poll/push components <p:poll> and <p:push>.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号