0

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

Community
  • 1
  • 1
Maicoly Morocho
  • 149
  • 1
  • 14
  • if i understand you are trying to set a value to a bean property from your javascript function. Take a look to [this](https://www.mkyong.com/jsf2/how-to-pass-new-hidden-value-to-backing-bean-in-jsf/) page there are some good examples there. – David Florez Jan 03 '17 at 02:53
  • HI!!! @David I saw the link but I can't make it work. The problem is that I can't send data from **function(response)**, which is inside the **function getInfo()**. Any suggestions!! – Maicoly Morocho Jan 03 '17 at 04:14
  • add a ``, and a remote command ``, inside your callback function asign ´response.email´ to ´dato´ an then call `processDato();`. like this `document.getElementById("yourForm:dato").value = response.email; processDato();` – David Florez Jan 03 '17 at 14:05

0 Answers0