1

im currently creating a litte application with spring boot and primefaces and have the problem, that i cant create a error message in my website if there went something wrong. Here some code of the xhtml:

<h:form id="form">
<p:growl id="msgs" showDetail="true"/>
...
<p:commandButton id="btnStartManualCopy" styleClass="pollUpdate" async="true" value="Start" disabled="#{daqScriptController.isProcessing()}" action="#{daqScriptController.startManualCopy}" />
</h:form>

note that async is true so the page does not block while the called method 'startManualCopy' is processing.
inside the method 'startManualCopy' i also handle errors if there are any while processing and want to display specified messaged on the page - within the growl.
What i have tried so far:

FacesMessage msg = new FacesMessage(FacesMessage.SEVERITY_ERROR, "Error:", "Some cool text); FacesContext.getCurrentInstance().addMessage(null, msg);

or:

PrimeFacesContext.getCurrentInstance().addMessage(null, msg);
PrimeFaces.current().ajax().update(":msgs");

or:

final RequestContext context = RequestContext.getCurrentInstance();
context.update(":msgs");

note: i tried for the ids some other combinations like :form:msgs and so on - so i can be sure that the right component is adressed. but in the network observer the response never really had an update inside.

what i found out while debugging was, that the responewriter is null in the facescontext inside the async called method. i added a listener, which adds a message to the growl on a tabclose event and this works just fine.

public void onTabClose(TabCloseEvent event) {
    FacesMessage msg = new FacesMessage("Tab Closed", "Closed tab: " + event.getTab().getTitle());
    FacesContext.getCurrentInstance().addMessage(null, msg);
}

so any idea how i can display the error messages from my usecase?

thanks

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
white91wolf
  • 400
  • 4
  • 18
  • 1
    Start reading here: https://stackoverflow.com/questions/3787514/how-can-server-push-asynchronous-changes-to-a-html-page-created-by-jsf – Kukeltje Aug 27 '19 at 11:43

1 Answers1

0

You need update="msgs" in your commandButton to tell it to update the msgs component after the AJAX return.

<p:commandButton async="true" 
    value="Start"  
    action="#{daqScriptController.startManualCopy}" 
    update="msgs" />
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Melloware
  • 10,435
  • 2
  • 32
  • 62
  • 2
    Wouldn't all this in the question fail too when not using async? Since a missing update does not update anything? (I mislead by the async part) – Kukeltje Aug 28 '19 at 11:20
  • ya thanks.. that did the job. but i was pretty sure i had this in my first attempt but seems like i had a litte other misstake there. – white91wolf Aug 28 '19 at 20:46
  • @white91wolf so most likely it is not async related. Next time pay good attention when creating questions – Kukeltje Aug 28 '19 at 21:49