0

I have a javascript in my html page.What I need to do is I have a var in javascript and I need to pass that var as the parameter for a back bean method.I do not have any jsf commandButtons.I need to call this back bean parameterized method inside my javascript by passing var as the parameter

Ex: I want to pass value as the parameter to the parameterizedMethod().Now I am using it like bellow.But it does not work.("knowlade_content" is the id of a <p></p> tag)

<script>
var value = 25;
document.getElementById("knowlade_content").innerHTML = "#{myBean.parameterizedMethod(value)}";

</script>

<div>
<p id="knowlade_content"></p>
</div>
chinthi
  • 87
  • 2
  • 11
  • @balusc I refered that link preveously.But what I need is to call parameterized bean class method inside the javascript as I mentioned in the question.So please try to understand the question before you mark it as duplicate. – chinthi Jun 28 '16 at 09:13
  • @balusc "does not work" means I could not call the bean class method by using the above code."Does not work" means no results were there and no error either.So I need to know a way to achieve this task. – chinthi Jun 28 '16 at 09:18

1 Answers1

0
<h:form id="formId">
    <h:inputHidden id="x" value="#{bean.x}" />
     <p:remoteCommand name="rc" update="msgs" actionListener="#{managedBean.execute}" />
</h:form>

and from JS

function getValue() {
  document.getElementById("formId:x").value = x;
}

and from script just call remote command

 <script>
  rc();

</script>

you can call remote command on init of the form if it is landing page to your application or you can any other event.

techipank
  • 432
  • 4
  • 17
  • thanks but I want this bean method to be called inside javascript not in other commandButtons or remoteCommand.The method should have a parameter as well.Please read the question and be specific. – chinthi Jun 28 '16 at 06:13
  • Sometimes things don't go like you want... A bean cannot be "called" from javascript. All things to be done to generate an ajax call which may call the bean and possibly returns values or exceptions are ready made in remoteCommand. rc() is exactly what you have to call in your javascript. Btw. in your code you are inserting a JSF EL-expression via javascript as a HTML-content. The EL-expression is server-side, the rest is client-side. – Holger Jun 28 '16 at 11:21