Terminal is an Ajax based terminal in the browser. Each command is sent to the server and handled by the commandHandler method, which receives the command name and its arguments and returns the response. "greet {text}" and "date" are sample commands.
<div class="card">
<h:form>
<p:focus for="terminal"/>
<p:terminal id="terminal" ref="term" commandHandler="#{terminalBasicView.handleCommand}"
welcomeMessage="Welcome to PrimeFaces Terminal"/>
<p:commandButton type="button" value="Clear" icon="pi pi-trash" onclick="PF('term').clear()" styleClass="mt-3" />
</h:form>
</div>
package org.primefaces.showcase.view.misc.terminal;
import java.io.Serializable;
import java.util.Date;
import jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
@Named("terminalBasicView")
@ViewScoped
public class BasicView implements Serializable {
public String handleCommand(String command, String[] params) {
if ("greet".equals(command)) {
if (params.length > 0) {
return "Hello " + params[0];
}
else {
return "Hello Stranger";
}
}
else if ("date".equals(command)) {
return new Date().toString();
}
return command + " not found";
}
}