我已经集成在与处理命令的一个ManagedBean目的JSF应用程序jQuery Terminal Emulator,而不是在jQuery的。 我已经成功地将命令发送给bean,然后将结果设置为回调参数,但我无法弄清楚如何在终端中显示此结果。发送命令输出从JSF managedBean将jQuery终端
下面是相关的代码段:
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");
}
在JS功能handleComplete()
,可变args.result
设置正确到“[command] _ok”,而我' d想要返回它,以便当jQuery终端函数调用sendRemoteCommand
标签中指定的Primefaces的<p:remoteCommand>
标签时,它能够获得后者返回的结果
非常感谢!
编辑:我使用JSF 2.0(钻嘴鱼科2.2,Glassfish的4,Primefaces 4.0)