0 Replies Latest reply on Dec 2, 2010 12:47 PM by fantaisie

    a4j:jsFunction and a4j:actionParam, problem passing js value to managedBean

    fantaisie
      hi all.
      I am facing a problem, of passing js values to jsf managed bean.
      Richfaces offers a <a4j:actionParam> which allows you to assign a js value to a bean value(using <a4j:actionParam: assignTo="#{valueInBean}">), but as I move to JSF2 and Primefaces(as Richfaces 4 is currently in develop, there is not <a4j:actionParam > in the latest milestone release.).
      the situation is:
      I want to call a actionlistener in managed bean from js, which can be done with primefaces remote command, but I also need this value in the actionlistener. so I have to somehow assign this value to a attribute in the managed bean before the js call the actionlistner. with Richfaces and jsf 1.2 I can do like this:
      <a4j:jsFunction name="test">
      <a4j:actionparam name="param" assignTo="#{testBean.jsVal}" actionListener="#{testBean.listener}"></a4j:actionparam>
      </a4j:jsFunction>
      <a4j:commandButton value="test" onclick="test('valueToAssign')"></a4j:commandButton>
      while I know I can do it by assign the value to a inputHidden in the page and then do submit, the problem is I can not submit the form(refresh the page), and there is no commandButton or link to execute.
      I took a look at the referece doc of primefaces,  Primefaces.ajax.ajaxrequest seems interesting, we can add params in the request. while I don't understand, if I pass a param in this request, how can I get the param value in the managedbean?
      I don't know if I have made myself clear because I am really lost right now....
      any suggestion guys?
      thx.

      hi all.

       

      I am facing a problem, of passing js values to jsf managed bean.

       

      the situation is:

       

      I want to call a actionlistener in managed bean from js, which can be done with primefaces remote command or richfaces jsFunction, but I also need a value from js(acutally a direction result from google maps api) in the actionlistener. so I have to somehow assign this js value to an attribute in the managed bean before the js call the actionlistner. with Richfaces and jsf 1.2 I can do like this:

       

      <a4j:jsFunction name="test">

      <a4j:actionparam name="param" assignTo="#{testBean.jsVal}" actionListener="#{testBean.listener}"></a4j:actionparam>

      </a4j:jsFunction>

      <a4j:commandButton value="test" onclick="test('valueToAssign')"></a4j:commandButton>

       

      but as I move to JSF2(as Richfaces 4 is currently in develop, there is not <a4j:actionParam > in the latest milestone release. so I have to think about something to replace).

       

      while I know I can do it by assign the value to a inputHidden in the page and then do submit, the problem is I can not submit the form(or refresh the page), and there is no commandButton or link to execute.

       

      Or I will do this all in js and use mutiple inputHidden and submit when everything finish..which means I have to change much code..

       

      I don't know if I have made myself clear because I am really lost right now....

       

      any suggestion guys?

       

      thx.