Home > Web Front-end > JS Tutorial > How to Pass Parameters to p:remoteCommand from JavaScript?

How to Pass Parameters to p:remoteCommand from JavaScript?

Mary-Kate Olsen
Release: 2024-10-24 11:41:02
Original
614 people have browsed it

How to Pass Parameters to p:remoteCommand from JavaScript?

Passing Parameters to p:remoteCommand from JavaScript

Question:

Is it possible to pass values to the p:remoteCommand component from JavaScript? If so, how can these values be received in the backing bean?

Answer:

Yes, passing parameters to p:remoteCommand from JavaScript is possible. The approach depends on the PrimeFaces version being used.

PrimeFaces 3.3 or Newer

For PrimeFaces 3.3 and newer, use the following syntax:

increment([{name:'x', value:10}, {name:'y', value:20}]);
Copy after login

This allows for multiple values with the same parameter name. Parameters with single values can be accessed in the backing bean as request-scoped properties:

@ManagedProperty("#{param.x}")
private int x;

@ManagedProperty("#{param.y}")
private int y;
Copy after login

PrimeFaces 3.2 or Older

For PrimeFaces 3.2 or older, use the following syntax:

increment({param1:'val1', param2:'val2'});
Copy after login

These parameters can be accessed in the backing bean using the RequestParameterMap:

Map<String, String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
String param1 = params.get("param1");
String param2 = params.get("param2");
Copy after login

Passing Parameters with Multiple Values

To pass parameters with multiple values, use the following syntax (PrimeFaces 3.3 or newer):

functionName([{name:'foo', value:'one'}, {name:'foo', value:'two'}, {name:'foo', value:'three'}]);`
Copy after login

This can be accessed in the backing bean as a managed property with the paramValues attribute:

@ManagedProperty("#{paramValues.foo}")
private String[] foos;
Copy after login

Additional Resources

  • [Dependency Inject Request Parameter with CDI and JSF2](https://stackoverflow.com/questions/2644660/dependency-inject-request-parameter-with-cdi-and-jsf2)
  • [How to invoke a JSF managed bean on a HTML DOM event using native JavaScript?](https://stackoverflow.com/questions/1840238/how-to-invoke-a-jsf-managed-bean-on-a-html-dom-event-using-native-javascript)

The above is the detailed content of How to Pass Parameters to p:remoteCommand from JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

source:php
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template