Labels and messages

One the most annoying and tedious tasks of JSF programming is having to deal with labels and messages. AngularFaces takes the scare out of that.

Mind you, how often have you written something like this?

<prime:panel header="Who are you?">
  <prime:panelGrid columns="3">
    <prime:outputLabel value="last name" for="lastNameID" />
    <prime:inputText id="lastNameID" value="#{customer.lastName}" label="last name"/>
    <prime:message for="lastNameID" />
    <prime:outputLabel value="first name" for="firstNameID" />
    <prime:inputText id="firstNameID" value="#{customer.firstName}" label="first name"/>
    <prime:message for="firstNameID" />
  </prime:panelGrid>
</prime:panel>
    

To make the tabular layout visible, the examples on this page deliberately draw lines around the grid cells.

That's two input fields, but six JSF components. Before the invention of @next and @previous, you also had to add ids to assign the label and the message to the input field. In fact, you still have to do so unless you're using PrimeFaces. Among other things, the ids make copying and pasting input fields a pain.

AngularFaces automatically adds the label and the error message to input fields. The label attribute of the input field is taken as the label caption:

<prime:panel header="Who are you?">
  <prime:panelGrid columns="3">
    <prime:inputText value="#{customer.lastName}"  label="last name"/>
    <prime:inputText value="#{customer.firstName}" label="first name"/>
  </prime:panelGrid>
</prime:panel>
    

In many cases, the label can be derived automatically from the bean attribute name. If you omit the label attribute of the input field, AngularFaces assumes the bean attribute name is a camel case version of the label. That's a useful feature for rapid prototyping - and even beyond if you see to it to chose expressive variable names. For example, the next example is as simple as can be:

<prime:panel header="Who are you?">
  <prime:panelGrid columns="3">
    <prime:inputText value="#{customer.lastName}"/>
    <prime:inputText value="#{customer.firstName}"/>
  </prime:panelGrid>
</prime:panel>

How to prepare the project

As of AngularFaces 2.0, automatic addition of labels and messages requires a little preparation: