I am learning JSF and need some help. I am trying to do a declarative validation in a page, the rendered required message however appears twice in the HTML markup.
In my managed bean i have a students
field pointing to a student entity which has the following fields firstName
, otherNames
, surName
.
this is how the Managed Bean looks like:
@ViewScoped
public Class FormController implements Serializeble{
private List<Student> students = new ArrayList<>();
@PostConstruct
public void init(){
students.add(new Student());
students.add(new Student());
}
//getters and setters
}
then in my JSF Page, I have a ui:repeat
that points to students
in my bean with declarative validation on the input fields;
<h:form>
<table>
<ui:repeat value="#{formController.students}" var="student">
<tr>
<td><p:outputLabel value="first name:"/></td>
<td><p:inputText value="#{student.firstname}"
required="true"
requiredMessage="field cannot be blank"/></td>
<td><p:messages/></td>
</tr>
<!--other input fields omitted to make code cleaner-->
</ui:repeat>
</table>
<p:commandButton value="submit"
action="#{formController.saveStudents()}"/>
</h:form>
The Problem, I am facing hereof is that, the required message are generated twice for each input field in the HTML markup like this:
<span class="bf-message">
<span class="bficon bficon-error-circle-o bf-message-icon" aria-hidden="true</span>
<span class="bf-message-detail">this feild cant be left blank</span></span><br /><span class="bf-message">
<span class="bficon bficon-error-circle-o bf-message-icon" aria-hidden="true"></span>
<span class="bf-message-detail">this feild cant be left blank</span></span>
//repeated likewise for all other input field required message,omitted to save space
This is my development Enviroment
- GlassFish 4.1.1
- JSF 2.2
- Primefaaces 6.0
- NetBeans IDE.
To add a little more details,the backing bean method that the commandButtion action points to has no FacesMessages, neither do the Field in the Entity Class have validation annotations.