I've integrated jQuery Terminal Emulator in a JSF application with the aim of processing commands in a ManagedBean and not in jQuery. I've sucessfully sent commands to the bean which then sets the result in a callback param, but I can't figure out how to display this result in the terminal.
Here are the relevant code snippets :
terminal.xhtml
<h:form>
<p:remoteCommand name="sendRemoteCommand"
action="#{processCommand.rcAction}"
oncomplete="handleComplete(xhr, status, args)" />
</h:form>
<h:panelGroup id="term_demo" layout="block" />
<h:outputScript library="primefaces" name="jquery/jquery.js"
target="body" />
<h:outputScript library="js" name="jquery.terminal-min.js" />
<h:outputScript target="body">
$(document).ready(function() {
$('#term_demo').terminal(function(command, term) {
if (command !== '') {
try {
var result = sendRemoteCommand([ {
name : 'command',
value : command
} ]);
if (result !== undefined) {
term.echo(new String(result));
}
} catch (e) {
term.error(new String(e));
}
} else {
term.echo('');
}
}, {
greetings : 'Javascript Interpreter',
name : 'js_demo',
height : 200,
prompt : 'js> '
});
});
function handleComplete(xhr, status, args) {
// Need to find a way to return args.result
// to the terminal!
}
</h:outputScript>
ProcessCommand.java
@ManagedBean
@RequestScoped
public class ProcessCommand {
private String command;
public void rcAction() {
FacesContext context = FacesContext.getCurrentInstance();
Map map = context.getExternalContext().getRequestParameterMap();
command = (String) map.get("command");
RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.addCallbackParam("result", command + "_ok");
}
In the JS function handleComplete()
, variable args.result
is properly set to "[command]_ok", and I'd like to return it so that when the jQuery terminal function calls sendRemoteCommand
specified in the Primefaces' <p:remoteCommand>
tag, it is able to get the result returned by the latter
Many thanks in advance!
Edit : I'm using JSF 2.0 (Mojarra 2.2, Glassfish 4, Primefaces 4.0)