user777
user777

Reputation: 896

How would I call a JavaScript function from a JSF Bean using RichFaces?

For example in PrimeFaces there is

RequestContext.getCurrentInstance().execute("alert(123)")

And in OmniFaces there is

Ajax.onComplete("alert(123)") 

I tried the pure JSF options I got from:

but neither of them works with Richfaces, specifically I'm either getting no alert in the response (using the first two options), or (using the last option) only the alert and an otherwise empty response with the follwing error in the browser console:

JSF AJAX Error:
description: "An empty response was received from the server. Check server error logs.",
responseCode: 200,
responseText: "<?xml version='1.0' encoding='UTF-8'?>?<partial-response><changes><eval><![CDATA[alert(123);]]></eva??l>",
responseXML: null

How can I just pass some JavaScript to the browser from Java code using RichFaces?

Thanks

Upvotes: 0

Views: 1767

Answers (1)

Makhiel
Makhiel

Reputation: 3884

Do you need to directly call JavaScript from a bean?

RichFaces components have @oncomplete, it lets you set code to be executed when the request comes back from the server.

Upvotes: 1

Related Questions