I want to pass value to remoteCommand
from javascript. If this is possible, how can I do that and how can I receive them in the backing bean?
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- java.lang.NullPointerException at java.io.PrintWri
- java.lang.NullPointerException at java.io.PrintWri
If you want to call your own function, eg. a confirm dialog, your custom function must be compliant to the passing parameter style. eg:
The java script function
The remoteCommand tag
Combine @BalusC @Joel's post for a functional example
When you need to pass more than one parameter from javascript, the syntax is:
var param1 = ...;
var param2 = ...;
var param3 = ...;
remoteCommandFunction([{name:'param1', value:param1}, {name:'param2',value:param2}, {name:'param3',value:param3}]);
Yes, it is possible. How to do that depends on the PrimeFaces version. You can see it in PrimeFaces users guide. Before PrimeFaces version 3.3 the syntax is as follows (copypasted from 3.2 users guide):
It's available in the backing bean by usual means. E.g. in a request scoped bean:
or in method of a broader scoped bean:
This approach had however the disadvantage that you can't specify a single parameter with multiple values like as possible with normal HTML forms and HTTP request parameters (which is in real world used on e.g. multiple select dropdownlist and multiple select checkboxgroup).
Since PrimeFaces version 3.3 the syntax is as follows (copypasted from 3.3 users guide):
This way offers the possibility to specify multiple values on a single parameter name. Parameters with single values like above are available the same way as the old way:
(note: you can use
Integer
in Mojarra, but not in MyFaces, this is further completely unrelated to<p:remoteCommand>
)or in method of a broader scoped bean:
If you need to specify a parameter with multiple values, then you could do it as follows:
with in a request scoped bean:
or in method of a broader scoped bean:
Page:
JavaScript:
Bean: