【发布时间】:2017-03-02 10:56:22
【问题描述】:
我正在学习 JSF,需要一些帮助。我正在尝试在页面中进行声明性验证,但是呈现的所需消息在 HTML 标记中出现了两次。
在我的托管 bean 中,我有一个 students 字段指向一个学生实体,该实体具有以下字段 firstName、otherNames、surName。
这就是 Managed Bean 的样子:
@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
}
然后在我的 JSF 页面中,我的 bean 中有一个 ui:repeat 指向 students,并在输入字段上进行了声明式验证;
<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>
问题, 我面临的问题是,为 HTML 标记中的每个输入字段生成两次所需的消息,如下所示:
<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
这是我的开发环境
- GlassFish 4.1.1
- JSF 2.2
- Primefaaces 6.0
- NetBeans IDE。
补充一点细节,commandButtion 动作指向的支持 bean 方法没有 FacesMessage,实体类中的字段也没有验证注释。
【问题讨论】:
标签: jsf primefaces jsf-2