I have something like:
<h:commandButton>
<h:ajax event="click" listener="#{controller.onLog}" onchange="onLogProcess" />
....
</h:commandButton>
I send a post to the server, do some stuff in the listener function. Then I would like to return a string / message (respond) to the client back and catch it with javascript in “onLogProcess” to show to the user a customize string.
I’m looking into it, but I haven’t found anything yet…
Is there any way that I can do this with JSF?
I’m using JSF 2.1 / Mojarra 2.1.2
Thanks in advance!
Let
<f:ajax>(not<h:ajax>!) conditionally render a<h:outputScript>.Where
#{controller.log}is your string which you’d like to pass to the JS function. Make sure that it doesn’t contain JS special characters like', linebreaks, etc. Use if necessary Apache Commons LangStringEscapeUtils#escapeJavaScript()for this.