Primefaces javascript RemoteCommand parameters

 

From BalusC:
Since PrimeFaces version 3.3 the syntax is as follows (copypasted from 3.3 users guide):

3.81 RemoteCommand

Passing Parameters

Remote command can send dynamic parameters in the following way;

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

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:

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

(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:

Map<String,String> params = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap();
int x =Integer.valueOf(params.get("x"));
int y =Integer.valueOf(params.get("y"));

If you need to specify a parameter with multiple values, then you could do it as follows:

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

with in a request scoped bean:

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

or in method of a broader scoped bean:

Map<String,String[]> paramValues = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterValuesMap();
String[] foos = paramValues.get("foo");

 

Callback Parameters

You can add as many callback parameters as you want with addCallbackParam API.

Each parameter is serialized as JSON and accessible through args parameter so pojos are also supported just like primitive values. Following example sends a pojo called User that has properties like firstname and lastname to the client in addition to isValid boolean value.
public void validate() {
//isValid = calculate isValid
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.addCallbackParam(“isValid”, true or false);
requestContext.addCallbackParam(“user”, user);
}
<script type=”text/javascript”>
function handleComplete(xhr, status, args) {
var firstname = args.user.firstname;
var lastname = args.user.lastname;
}
</script>
By default validationFailed callback parameter is added implicitly if validation fails.

 

Fileuploader only uploads first file if an BlockUI component is in the same view, Primefaces

Environment:
I´m using common Primefaces 3.5. with JSF 2.1 and JDK 1.7.
Application server is glassfish 3.

Problem:
If i use an UIBlock component in the same view as the fileuploader, 
the fileuploader only processes the first file.
Testet with different commons-io and commons-fileuploader libs.
Testet on single view with only these two components in it.

Workaround:
After removing the UIBlock Element the fileuploader is working fine again.

Greetings

Martin


Jul 10, 2013

#1 dpearson…@gmail.com

Check out the last post in this topic. 
I had a block UI file upload problem even when they weren't in the same dialog. 
It seems they are incompatible. This fixed my issue so maybe yours is related.

http://forum.primefaces.org/viewtopic.php?f=3&t=23008

I overloaded the function in my own primefaces control javascript file with
Primefaces.widget.BlockUI.prototype.bindTriggers = function {
code from that post
}

Being able to do this is pretty handy b/c you don’t have to break open the primefaces
source and update it yourself.
I’ve had to do this for a few other issues as well that just needed some if checks.

 

The post:

I had the same problem. I think it is related to the fileUpload more than blockUI cause the ajaxComplete triggered has no parameter in it…Anyway i resolved this with a patch to the primefaces.js modifying the blockUI widget bindTriggers method like this:

Code:
bindTriggers:function(){var a=this,b=this.cfg.triggers.split(",");$(document).bind("ajaxSend",function(d,f,c){if(c){if($.inArray(c.source,b)!=-1){a.show()}}});$(document).bind("ajaxComplete",function(d,f,c){if(c){if($.inArray(c.source,b)!=-1){a.hide()}}})}
bindTriggers:function(){
var a=this,b=this.cfg.triggers.split(",");
$(document).bind("ajaxSend",function(d,f,c){if(c){if($.inArray(c.source,b)!=-1){a.show()}}});
$(document).bind("ajaxComplete",function(d,f,c){if(c){if($.inArray(c.source,b)!=-1){a.hide()}}})
}