Richfaces sending data to server using ajax

My application allows the user to enter text in the message field, and when he types, at htat time, he should let the administrator see what is being dialed in another console.

for this I need to periodically send data to a managed bean and from there to the business layer.

<h:form> Name : <h:inputText id="name" value="#{clockBean.name}"/> Message: <h:inputText id="age" value="#{clockBean.msg}"/> <a4j:poll id="poll" interval="20000" enabled="#{clockBean.enabled}" action="# {clockBean.process}" render="clock,counter"/> <a4j:log/> </h:form> 

I have managedBean properties for name and msg, and I need to access the name and msg properties and send them to the business layer when processing them in process () of the clockBean method controlled by Bean.

 @ManagedBean @ViewScoped public class ClockBean implements Serializable{ private string msg; private string name; private boolean enabled; public void process(){ System.out.println("timer event calling *** - msg is "+msg+" : name is "+name); } //getters setters & rest of the code 

I currently have a bean scope like ViewScopedand. I get zero values ​​for two fields when polling is done every 20 seconds. How can I get the values ​​of the name and msg properties when the polling is done at a given time interval? Is there a better approach to solving this problem?

+4
source share
2 answers

The session area is visible only to the current user. Thus, if you try to get #{clockBean} on the admin page, you will actually get a completely new bean. To make this information available to the administrator user, you will need to save this information and read it.

Update: I would not do this with a poll, since the poll makes a request every time, even if the data does not change. I would do this with onchange events, queue and request delay. If a4j:poll does not submit the form (maybe an error in richfaces?), You can easily implement this with a4j:function and just create a js function and call it using setInterval() from js.

+3
source

received the answer to my question .. I did not add

  execute="@form" 

for my survey tag. The values ​​associated with the input fields did not get into the query correctly. The entire entrance was highly appreciated.

+1
source

All Articles