primefaces - How to pass bean object/value to a jsf(xhtml) page? -


i using tomcat , primefaces in current available versions.

i'm facing problem, i'm not able send value managed bean xhtml page asynchronously.
code fragment xhtml page:

<p:inputtextarea id="transcriptionresult" rows="4" cols="120"                     value="#{transcriptiontabview.currenttranscritpion}" /> 

this method called asynchronously re-/set object/value within managedbean "transcriptiontabview". contains object called transcription currenttranscription.

@override public void trascriptionready(transcription t) {   this.currenttranscription = t; } 

i thought enough reset view, nothing happened.

i solved problem push functionality of primefaces. hint of balusc, read userguide of primefaces chapter 9. primefaces push pdf , watched video tutorial. these steps have done solve problem.

step 1: added following method within transcriptiontabview-bean:

public void pushmessage() {     eventbus eventbus = eventbusfactory.getdefault().eventbus();     eventbus.publish("/resultreceiver", result);     system.out.println("message sent @ " + new date()); } 

step 2. created receiver-bean receive pushed messages:

 @pushendpoint(value = "/resultreceiver")  public class transcriptionresultreceiver {      @onmessage(encoders = { jsonencoder.class })     public string onmessage(string message) {        return message;     }  } 

step 3. added <p:inputtextarea>component jsf display message: <p:inputtextarea rows="6" cols="60" id="transcriptionresult" value="#{transcriptiontabview.result}"> </p:inputtextarea>

step 4. add socket jsf waits incoming messages: <p:socket channel="/resultreceiver" onmessage="handlemessage"></p:socket>

make sure channel same in receiver-bean mentioned @pushendpoint annotation.

step 5. add following javascript method jsf called socket tag, when message pushed transcriptiontabview-bean.

    <script type="text/javascript">       function         handlemessage(data){             document.getelementbyid(<generated_id of inputtextarea>).value=data;          }      </script>   

as understood reading userguide , watching youtube video, method pushmessage in transcriptiontabview opens channel jsf , send message using eventbus.publish("/resultreceiver", message); on client side socket tag waits incoming message on given channel , if onmessageevent occurs, javascript method handlemessage called incoming data.

please correct me if i'm wrong. i'm new this.


Comments