Search code examples
javajsfprimefacesfacelets

primefaces p:message outside the components form


I'm using JSF 2.0 and Primefaces 3.2.

I'm using Facelets for templating, and I've built a 3-column layout:

Left column - mainContent column - Right column. Each column got it's own template xhtml file with ui:composition which I insert in a mainTemplate.

In the mainContent column I've got a info-button (p:commandButton):

<h:form id="mainForm">
<p:commandButton id="infoButton" value="Info" actionListener="#{faceletsAttachment.addInfo}"/> 
</h:form>

But I want the info to show in the right column, with a

<h:form id="rightColumnForm">
<p:message for="infoButton">
</h:form>

This obviously does not work, because does not find the infoButton. Any idea how I can make this work? I tried

<p:message for="mainForm:infoButton"> 

too, but no cigar.

The reason I want to use a p:message is that I want the message to position itself on the y-position the infoButton has. If you got an alternative solution to how I can do this, I would also appreciate it.


Solution

  • If you are adding messages manually from server side you can do the following

    <p:message id="myInfoButton" for="myInfoButton" />

    and send messages from server to myInfoButton like this

    FacesContext.getCurrentInstance.addMessage("myInfoButton ", new FacesMessage("My Message", "Some Text goes here..."));
    

    also add :rightColumnForm id to update of the <p:commandButton id="infoButton"