0

p:terminal does not have a update attribute.

Does it support any kind of ajax event?

how do I update another jsf component as a response to a terminal command?

Leo
  • 6,480
  • 4
  • 37
  • 52

2 Answers2

2

It does not have any ajax events as can be seen in the documentation and/or the source. But in the implementation of commands for the terminal that you implement yourself, you can do anything you want. Including using the RequestContext to update other components.

At least that is what I expected (and did not explicitly test, sorry). Updating from the commandHandler does not work since the commandHandler is called during the render response phase and you cannot add updates to components in that phase.

See also the comment on the answer here: Can I update a JSF component from a JSF backing bean method?.

So the actual good answer is the one from the @Leo himself (although this answer helped a little ;-))

Community
  • 1
  • 1
Kukeltje
  • 12,223
  • 4
  • 24
  • 47
  • sorry for my ignorance but how exactly could I update another component this way? – Leo Oct 01 '15 at 20:59
  • Ignorance is not a problem, but not using a search engine to get some more information is (or the primefaces showcase or the primefaces docs or the 'related' in Stackoverflow) :-) ... http://stackoverflow.com/questions/11365094/can-i-update-a-jsf-component-from-a-jsf-backing-bean-method – Kukeltje Oct 01 '15 at 21:33
  • so actually, here what happened.... I had to add a p:remoteCommand to update the components and from inside the p:terminal commandHandler I call it via javascript like this => context.execute("rc();"); -- if I try to update it like context.update("form:terminal"); [yes, this is the notation, no first :] it simply does not work probably because commandHandler is called AFTER the rendering phase – Leo Oct 02 '15 at 00:13
1

Here what worked for me

    <p:terminal
        id="terminal"
        widgetVar="term"
        prompt="Lab >> "
        commandHandler="#{labMB.handleCommand}"
        welcomeMessage="Welcome to Lab" />

    <p:remoteCommand
        name="rc"
        update="history" />

    <p:dataTable
        id="history"(...)

and

public String handleCommand(String command, String[] params) {
        RequestContext context = RequestContext.getCurrentInstance();
        //(do things here)
        context.execute("rc();");
}

it seems that just calling

context.update("form:history");
Leo
  • 6,480
  • 4
  • 37
  • 52
  • It actually happens IN the rendering phase. I'm debugging now to see why the update does not work and if it is to be expected to not work. Please unaccept my answer and accept yours for now – Kukeltje Oct 02 '15 at 10:04
  • I've updated my answer to point to yours, but please still unaccept mine and improve yours a little to start with why the context.update does not work (see my edited answer) – Kukeltje Oct 02 '15 at 10:44
  • I think I'm gonna keep yours, since that was the real starting point :-) but I will also keep my answer because it just provides something that works. Maybe someone else can come with a better answer, since my solution seems like a little hack to me. – Leo Oct 02 '15 at 12:04
  • Well, it is not a 'hack' since it is the only solution given how the PrimeFaces terminal component works. So the only other solution someone can come up with is a 'patch' for the terminal component which I doubt anyone is interested in making. – Kukeltje Oct 02 '15 at 13:04