4

My application lets the user to type text in the message field and when he is typing, at htat time it has to allow the admin to see what is being typed in a different console.

for this I need to send data periodically to the 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 I process them in process() method of the clockBean managed 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

currently I have my bean scope as ViewScopedand I am getting null values for the 2 fields when the poll runs every 20 seconds. How can I get the name and msg property values when the poll runs in a given time interval? is there any better approach to resolving this issue?

Sanath
  • 4,774
  • 10
  • 51
  • 81

2 Answers2

4

The session scope is only visible for the current user. Thus if you will try to get #{clockBean} in the admin's page you'll actually end up with a brand new bean. In order to make this information available to the admin user as well, you will need to persist this information and read it.

Update: I wouldn't do it with polling since polling does the request every time even if the data doesn't change. I would do it with onchange events, a queue and a request delay. If a4j:poll doesn't submits the form (bug in richfaces maybe?), you can implement this easily with a4j:function and just create a js function and call it with setInterval() from js.

bogdan.mustiata
  • 1,725
  • 17
  • 26
  • yes I am going to persisting them..my real problem is how I could send data periodically to the business layer via the managedBean. how cn I peridically do an ajax submit based on poll functionality in richfaces? – Sanath Jun 20 '11 at 07:40
  • I wouldn't do it with polling since polling does the request every time even if the data doesn't change. I would do it with onchange events, a queue and a request delay. If `a4j:poll` doesn't submits the form (bug in richfaces maybe?), you can implement this easily with `a4j:function` and just create a js function and call it with `setInterval()` from js. – bogdan.mustiata Jun 20 '11 at 10:22
  • btw I notice that you have `binding="#{clockBean.msg}"` as binding for your `a4j:poll`. You probably might want to remove that since bindings are needed only in rare cases where you need to manually access the data of the component itself for some obscure reason. – bogdan.mustiata Jun 20 '11 at 10:25
  • yes bogdan..binding is wrong.. I have removed my binding code part from the jSF markup. in my clockBean I have @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 – Sanath Jun 21 '11 at 05:35
2

got the answer to my issue .. I have not added

 execute="@form" 

property to my poll tag..so the values that were related to the input fields were not getting into the request properly.. all the input was highly appreciated.

Sanath
  • 4,774
  • 10
  • 51
  • 81