How to set a value to a bean property from a JavaScript async callback

111 Views Asked by At

I need to get data from a Javascript function (Facebook sdk) from <p:commandLink>

My code is:

<p:commandLink action="#{faceController.getStatuses()}" update="afterLoads" oncomplete="getInfo();">
<h:outputText value="PRUEBA" />
</p:commandLink>

My Script is:

<h:panelGroup id="afterLoads">
 <h:outputScript>
    function getInfo() {
        FB.api('/me', 'GET', {fields:  'first_name,last_name,name,email,id,picture.width(150).height(150)'},  function(response) {
                var a=response.email;
               alert(#{faceController.dato=response.email});

    });

    }

   </h:outputScript>
</h:panelGroup>

My bean is:

@ManagedBean
@ViewScoped
public class FaceController {
     public String dato="";
        public void getStatuses() {
           System.out.println("dato> "+dato);
        }
}

I get null data. What is the problem? Help me please!!

Reference: Getting backing bean value with Javascript

0

There are 0 best solutions below