0

I have this function in ManageBean class :

public String myname()
{
    return employeeManagedBean.I().getUser_name();
}

I want to call this function in a JavaScript function and catch the returned value from Myname function. I tried this :

<h:form>
   <p:remoteCommand name="myname" actionListener="#{employeeManagedBean.myname()}"  />
    <script type="text/javascript">
        function handleMessage() {
            var m = myname();
            console.log(m);
        }
    </script>    
</h:form>

but the value of m that printed in the console was undefined. Is there any way to do that ?

devlin carnate
  • 8,309
  • 7
  • 48
  • 82
Sawan
  • 162
  • 1
  • 10
  • `myname` is not defined because JavaScript is not JSF. JSF is a server sided language. You'll have to use XHR to get that value into JS. http://stackoverflow.com/questions/16784322/java-method-call-from-javascript-in-jsp-page – Sterling Archer May 19 '16 at 14:38
  • 1
    Please ignore the link in above comment of Sterling. JSF != JSP. – BalusC May 19 '16 at 14:43
  • I know JavaScript is not a server side ,but I read that primefaces support this feature by "remoteCommand " tag – Sawan May 19 '16 at 15:22
  • Note : when I wrote "var m = myname() " that mean I want to call the name of remoteCommand which has an action to call myname function in server side . – Sawan May 19 '16 at 15:27
  • I am working on JSF server not jsp and i want to call managed bean function not to pass properties , Why does my question marked as duplicate ? @SterlingArcher – Sawan May 19 '16 at 16:32

0 Answers0