I need to close my messages dialog without using the built in close button. An embedded "CLOSE" button within the message needs to fire of a method in the backing bean, and when finished, the message box should close.
My code calls the actionListener, but I am unable to clear the message box on submission. In my last attempt, I tried to do it from the Backing Bean, but the box refuses to go away.
Below is sample test code.
<h:form id="form1">
<h:panelGroup id="myPanel" layout="block" class="scap-block"
rendered="#{not chartView.acknowledged}">
<p:messages id="banner" showSummary="true" showDetail="false"
autoUpdate="true" closable="true" escape="false">
</p:messages>
<p:commandButton widgetVar="acceptContinue"
style-class="align right" value="Close" type="ajax"
actionListener="#{chartView.close}" render="myPanel" />
</h:panelGroup>
</h:form>
<f:event type="preRenderView" listener="#{chartView.init}" />
</h:body>
Bean:
@ManagedBean(name = "chartView")
@ViewScoped
public class ChartView implements Serializable {
private boolean acknowledged = false;
public void init() {
log.debug("preRender init() method");
String detail = "PrimeFaces Rocks."
+"<button aria-disabled='false' id='form1:j_idt5' name='form1:j_idt5' "
+ "class='ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only' "
+ "onclick='PrimeFaces.ab({s:"form1:j_idt5"});return false;' type='ajax'>"
+ "<span class='ui-button-text ui-c'>Close</span></button>";
FacesContext.getCurrentInstance().addMessage("banner",
new FacesMessage(FacesMessage.SEVERITY_ERROR, detail, "Some details"));
}
public void close() {
System.err.println("Acknowledged");
log.debug("###Close called###");
setAcknowledged(true);
RequestContext context = RequestContext.getCurrentInstance();
context.update(":form1:myParent");
}