1

I am using primefaces 6, I want to call primefaces remote command with Javascript, and I want to pass parameters to it.

The remote command code is as the following

<h:form>
    <p:remoteCommand name="dummyAction" 
                 actionListener="#{usedController.exec}"/>
</h:form>

Then i tried to call the remote command in an accordionpanel like the following

<p:accordionPanel onTabClose="dummyAction([{name1:'value1', 
name2:'value2'}]); "

and i added this method in the Managedbean

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

I started debugging and i found that the values of the string name1 and name2 are always null, as the map doesn't contain its key, how could i fix this so i could get the proper values?

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
abdo_mah90
  • 83
  • 1
  • 7
  • Sorry, but these were working using primefaces 3 not 6, no answer found for the same issue on primefaces 6 – Heba A. Jun 14 '18 at 08:50

1 Answers1

1

You are not passing the parameters correctly:

<p:accordionPanel onTabClose="dummyAction([{name1:'value1', name2:'value2'}]); "

It should be:

<p:accordionPanel onTabClose="dummyAction([{'name':'name1', 
'value':'name1Value'},{'name':'name2','value':'name2value'}]); "

You have to be sure that the attributes names are ALWAYS "name" and "value". For example, if you are passing one parameter it should be:

[{'name':yourParamName, 'value': yourParamterValue}]

If you are passing two parameters, it should be:

[
 {'name':yourFirstParamName, 'value': yourFirstParamterValue}, 
 {'name':yourSecondParamName, 'value': yourSecondParamterValue}
]

Good luck!

Jalal Kiswani
  • 738
  • 5
  • 11
  • Like mentioned in the second 'real' duplicate in the comments above – Kukeltje Sep 01 '18 at 06:46
  • Kukeltje, I don't think the previous answers clearly addressing this explanation presented in this answer. – Jalal Kiswani Sep 01 '18 at 14:07
  • That is subjective then, since for me it does. IF others mark this question as a duplicate. And if the other answer is not all that clear in your opinion, you are encouraged to edit and improve it instead of creating a new answer on a different question. Stackoverflow tries to prevent fragmentation like this by allowing edits and being a real QA site and not a discussion forum. Cheers – Kukeltje Sep 02 '18 at 09:17
  • I agree with you Kukeltje, this could be subjective! – Jalal Kiswani Sep 03 '18 at 18:05