How to use the Primefaces p?

3

Set the nome field by using p:inputText to receive values, it is a field . How do I display a message showing that this field is required, using p:messages ? I'm also using JSF.

Follow my HTML:

<h:form>
        <p:messages/>

        <p:panelGrid columns="2">
            <f:facet name="header">
                Cadastro de Pessoas
            </f:facet>
            <h:outputLabel value="Nome" for="nome"/>
            <p:inputText id="nome" required="true"/>

            <f:facet name="footer">
                <p:commandButton value="Cadastrar" icon="ui-icon-disk"
                                 iconPos="right"/>
            </f:facet>
        </p:panelGrid>
    </h:form>

Follow the Image of the Form:

    
asked by anonymous 11.11.2015 / 20:16

2 answers

4

Have you ever tried to use a p:message only for the p:inputText component?

It would look like this:

<h:form>
    <p:messages/>

    <p:panelGrid columns="2">
        <f:facet name="header">
            Cadastro de Pessoas
        </f:facet>
        <h:outputLabel value="Nome" for="nome"/>
        <p:inputText id="nome" required="true"/>
        <p:message for="nome" />

        <f:facet name="footer">
            <p:commandButton value="Cadastrar" icon="ui-icon-disk"
                             iconPos="right"/>
        </f:facet>
    </p:panelGrid>
</h:form>

I believe this works.

Hugs.

    
12.11.2015 / 01:31
3

    

<p:panelGrid columns="2">
    <f:facet name="header">
        Cadastro de Pessoas
    </f:facet>
    <h:outputLabel value="Nome" for="nome"/>
    <p:inputText id="nome" required="true" requiredMessage="O campo nome é obrigatório"/>

    <f:facet name="footer">
        <p:commandButton value="Cadastrar" icon="ui-icon-disk"
                         iconPos="right" action="seuManagedBean.metodo()" update="@form"/>
    </f:facet>
</p:panelGrid>

With the "requiredMessage" attribute you can custom the message of each field. If you have 10 required fields and all are not filled, all of them will appear only in p: messages, so your error or alert messages are in one place.

    
12.11.2015 / 13:27