1

i have a jquery file that have comfirm dialog if user chose yes i need to call method from jsf

thats where i need to call jsf managed bean in jquery :

 jConfirm('item '+ui.item.context.id+'you want continu ?', 'alerte', function(r) {     
                  if(r)          
                  {
              // i want to call the addmember methode here
             addmember(ui.sender.attr('id'));// i need the right way to call it this is wrong way
                   }
                    else
                    {
                    $(ui.sender).sortable('cancel'); // refuse element to be dropped
                    }

and in the jsf managed bean "Managedbeanmembers" i have :

void addmember(String name)
{
  listmembers.add(name);
}

Edit 1:

i wil try this time to be more clear to explain to you what i need :

i have a method in jsf managed bean that get the value and insert in the database :

    public void exec() {
    FacesContext context = FacesContext.getCurrentInstance();
    Map map = context.getExternalContext().getRequestParameterMap();
    String name1 = (String) map.get("name1");
    String name2 = (String) map.get("name2");

    manageTesttable.persist(name1);   
}

in Jsf i include it with :

 <p:remoteCommand name="remoteCommandFunctionName"   
                  actionListener="#{gestionduplanning.exec()}"/>

and in my Javascript file :

jConfirm('item '+ui.item.context.id+' capacite Cuisson epuise vous voulez continue comme meme ?', 'alerte', function(r) {     
                  if(r)          
                  { 

                  remoteCommandFunctionName({name1:'value1', name2:'value2'});

                   }
                    else
                    {
                    $(ui.sender).sortable('cancel'); // refuse element to be dropped
                    }

but when i insert i have null value why name1 and name2 are null ??

marouanoviche
  • 253
  • 4
  • 11
  • 28

1 Answers1

1

One possibility - create a hidden button and click it like @SJuan76 suggested - here's an example.

Another possibility - if you are using richfaces try the jsFunction - see here.

Edit: In case of Primefaces - there is p:remoteCommand providing a similar functionality.

dratewka
  • 2,104
  • 14
  • 15
  • i need to add argument in my function in jquery before send it to the server how i can do that ?? – marouanoviche May 28 '13 at 10:18
  • Are you using richfaces or not? – dratewka May 28 '13 at 10:19
  • In this case you can use `p:remoteCommand` to simplify thigs. A similar [question](http://stackoverflow.com/questions/7497750/how-do-you-pass-parametersfrom-javascript-into-remotecommand-then-send-it-to) showing how to pass parameters. – dratewka May 28 '13 at 10:27
  • i followed the example and i can call the function inside the managed bean but the problem i can get the value of parametres passed :remoteCommandFunctionName({name1:'value1', name2:'value2'}); when i try to get them with FacesContext context = FacesContext.getCurrentInstance(); Map map = context.getExternalContext().getRequestParameterMap(); String name1 = (String) map.get("name1"); String name2 = (String) map.get("name2"); i have nothing – marouanoviche May 28 '13 at 10:51
  • Try `remoteCommandFunctionName([{name1:'value1', name2:'value2'}]); ` – dratewka May 28 '13 at 10:56
  • You probably use an old primefaces version - in such case pass the [parameter using an ` – dratewka May 28 '13 at 11:38
  • and how we can get in Javascript the value returned by method called in javascript ? – marouanoviche May 28 '13 at 12:30
  • Directly you can't as the call is asynchronous. You can however use a callback function passed to the `oncomplete` attribute of `p:remoteCommand` – dratewka May 28 '13 at 12:35