0

I have several <p:messages> elements that ought to handle different types of errors produced by a single bean. Now the clientID I get from my browser for one element is always the same, since there are no generated ids inside (that is 3 IDs altogether).

No matter which clientID I pass to FacesContext.addMessage(), I will always end up displaying all error messages on every <p:messages> element.

One clientID as in browser: regelDetailAccordion:duoDlgForm2:regelDetail
another clientID as in browser: regelDetailAccordion:duoDlgForm1:messagesNeuerFehler
Bean code: FacesContext.getCurrentInstance().addMessage(X, new FacesMessage(...));
where X is clientID (not) preceded by : and/or only regelDetail with and without : in front. Tried all :(

Dialog-Include:

<ui:insert name="insertDuo"><ui:include src="/includes/duoRegelStmt.xhtml" />
</ui:insert>

Dialog that displays all my messages:

    <p:dialog widgetVar="newDuoDialog" id="newDuoDlg" modal="true">
        <p:layout id="layout">
            <p:layoutUnit position="west">
                <ui:insert name="insertDetailStmt">
                    <h:form id="stmtDetailForm">
                        <ui:include src="/includes/stmtDetail.xhtml" /> <!-- left side -->
                    </h:form>
                </ui:insert>
            </p:layoutUnit>

            <p:layoutUnit position="center">
                <ui:insert name="insertDetailRegel">
                    <ui:include src="/includes/regelDetail.xhtml"/> <!-- right side -->
                </ui:insert>
            </p:layoutUnit>
        </p:layout>
    </p:dialog>

Right side of the dialog that displays 2 of my 3 messages:

<ui:composition>
    <h:panelGrid id="unterheaderUndAccordion">
        <h:panelGrid rendered="#{...}" id="regelUnterheader"/>
        <p:accordionPanel multiple="true" activeIndex="0,1" id="regelDetailAccordion" rendered="#{...}">
            <p:tab>
                <h:form id="duoDlgForm1">
                    <ui:insert name="neuerFehler">
                        <ui:include src="/includes/neuerFehler.xhtml" />
                    </ui:insert>

                    <h:selectOneMenu value="#{regelBean.selectedFehlerCode}" id="selFCode"
                        onChange="submit()" process="@this" valueChangeListener="#{regelBean.changeFehlerCode}">
                        <p:ajax event="change" update="duoDlgForm1" />
                        <f:selectItems ... />
                    </h:selectOneMenu>
                </h:form>
            </p:tab>
            <p:tab>
                <h:form id="duoDlgForm2">
                    <h:panelGrid>
                        <p:messages id="regelDetail" showDetail="true" closable="true"/>
                    </h:panelGrid>
                </h:form>
            </p:tab>
        </p:accordionPanel>
    </h:panelGrid>
</ui:composition>

neuerFehler contains a messages that is defined like this

<p:messages id="messagesNeuerFehler" showDetail="true" closable="true"/>

In my thinking, when I enter the correct value for X, only the proper messages field will display a message, even if other messages are updated. If that is true, what is the correct clientID I have to enter? Big thanks in advance, I'm at wit's end :(

Screeny

dasLort
  • 1,264
  • 1
  • 13
  • 28

2 Answers2

1

If I understand the problem correctly you may prevent certain components from being updated using Primefaces Selectors like this:

<h:form>
    <h:inputText ... />
    <h:inputText ... />
    <h:inputText ... styleClass="noupdate" />
    <h:inputText ... />
    <h:inputText ... />
    <p:commandButton ... update="@(form :not(.noupdate))"/>
</h:form>

Original answer by BalusC here.

If this doesen't help, can you use the for-attribute on the messages component? Seems to me that you expect the clientid in the FacesMessage to be the identifier of the messages component, when it is the identifier for the component with error. Sorry if I misunderstand.

Community
  • 1
  • 1
Jaqen H'ghar
  • 4,305
  • 2
  • 14
  • 26
0

Try using

FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Your message"));

and add a update="elementId" attribute to the component, which triggers your managed bean action.

"elementId", of course, is the coresponding id of your <p:messages> element.

For me this way it works fine. Maybe it also solves your issue.

LarsBauer
  • 1,539
  • 18
  • 23
  • but what if my buttons that update already update a bigger scope which contains more than one `messages` ? – dasLort Jun 17 '14 at 15:49
  • That will be a problem, because all components inside your update component will be updated. You could try to update only needed ones. Could be a lot but you can separate them by spaces in your update attribute. I don't know if this will work for you. Can you provide the code with your buttons, too? – LarsBauer Jun 17 '14 at 15:54
  • I understand your point but I somehow doubt this is the way to go, although it might work. I mean, obviously `X` is not supposed to be `null` – dasLort Jun 18 '14 at 07:50
  • I didn't say that this is the definitve way to go. I just tell you how it is described in the PrimeFaces documentation and the way I handle this issue. – LarsBauer Jun 18 '14 at 08:50
  • I know you didnt say that ;) What part of the documentation are you talking about? – dasLort Jun 18 '14 at 09:16
  • Well, everytime they use `` or `` they set this parameter `null` and add a `update="id"` attribute instead. – LarsBauer Jun 18 '14 at 10:58