Terminal commands are handled by a server side listener. "greet {text}" and "date" are sample commands.
<div class="card">
<h:form>
<p:focus for="terminal"/>
<p:terminal id="terminal" widgetVar="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 jakarta.faces.view.ViewScoped;
import jakarta.inject.Named;
import java.io.Serializable;
import java.util.Date;
import io.quarkus.runtime.annotations.RegisterForReflection;
@Named("terminalBasicView")
@ViewScoped
@RegisterForReflection(serialization = true)
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";
}
}