3

I have the next url: http://host:port/page.xhtml?response=something

I want render a p:message if response==something

I have the next code:

 <h:panelGroup rendered="#{param.response == 'something'}">
            <h:outputText value="message" /> 
       </h:panelGroup>

this render a <div>message</div>

I want render a <p:messages /> or <p:growl /> and its value "message" if response==something

please help me to code this, and something else:

  • Do I need a bean managed to send value to p:messages or p:growl?
  • Do I need to call p:messages or p:growl from a <p:commandButton />?
  • I can't use <h:body onload="callFunction()"> 'cause h:body is on template xhtml <ui:insert name="content"></ui:insert> and my view is on <ui:composition ... <ui:define name="content" > in other xhtml, and h:body is common to several views

1 Answers1

1

You'd really need to use FacesContext#addMessage() to add a message to the context. On an initial request, your best bet is a

<f:metadata>
    <f:viewParam name="response" value="#{bean.response}"/>
    <f:event type="preRenderView" listener="#{bean.init}" />
</f:metadata>

with

private String response;

public void init() {
    if (response != null) { 
        FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(
            FacesMessage.SEVERITY_INFO, response, null));
    }
}

You can by the way also use a separate <p:messages globalOnly="true"> or <p:growl globalOnly="true"> to display only faces messages with a null client ID.

See also:

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
  • @BelusC it's call bean but doesn't show it! log : facesmessage(s) have been enqueued but may not have been displayed, did you see it sometime? –  Dec 13 '12 at 14:26
  • Did you really use `` as answered? This problem suggests that you actually used bean's constructor or `@PostConstruct` which may indeed be too late. – BalusC Dec 13 '12 at 14:29
  • thanks @BelusC! I forget put tag like you indicated http://stackoverflow.com/questions/10113498/jsf-facesmessages-not-displayed-back-instead-enqueued –  Dec 13 '12 at 14:50
  • It should also display without a `globalOnly="true"`. Apparently you had a `for` specified in your original one even though you mentioned in your question just `` and `` which are perfectly sufficient. – BalusC Dec 13 '12 at 14:51
  • I meant –  Dec 13 '12 at 14:54