Oscar Castiblanco
Oscar Castiblanco

Reputation: 1646

p:message attached to a h:form

I have two forms in my page, in the first formulary are input fields with validation, and in the other a dataTable. The first formulary has a message area to show validation errors, and the second formulary has a message area to show problems with the retrieval of the data (this message area is updated from myController.search).:

    <h:form id="form1">
        <p:message id="messageForm1" for=":form1" />
        <p:inputText id="text1" value="#{myBean.data}" required="true" />
                    ....
        <p:commandButton value="Search" actionListener"#{myController.search}"
            update=":form2:dataTable :form2:messageForm2 :form1:messageForm1" process="text1, ..." />
    </h:form>

    <h:form id="form2">
        <p:message id="messageForm2" for="messageForm2" />
        <p:dataTable>
        ...
        </p:dataTable>
    </h:form>

The problem is that the messages in the form2 are working, but the validation messages in form1 are never shown

Upvotes: 0

Views: 1429

Answers (1)

Sebi
Sebi

Reputation: 2584

The description of the for attribute of the p:message tag says:

Id of the component whose messages to display.

So you can't specify the ID of the form. You have to specify the ID of a single form component. e.g. <p:message id="messageForm1" for="text1" />. But then you have to create one message element for every form component.

An alternative would be to use the p:messages tag. For examples see here: http://www.primefaces.org/showcase-labs/ui/messages.jsf

Upvotes: 2

Related Questions