我已经尝试过这段代码,用于在表格上提交出生日期字段:
<h:form>
<h2>JSF Registration App</h2>
<h4>Registration Form</h4>
<table>
<tr>
<td>First Name:</td>
<td>
<h:inputText label="First Name" id="fname" value="#{mybean.firstName}" required="true" />
<h:message for="fname" />
</td>
</tr>
<tr>
<td>
<h:inputText value="#{userBean.dob}" id="dob" required="true" >
<f:convertDateTime pattern="MM-dd-yy"/>
</h:inputText> (mm-dd-yy)
<h:message for="dob"/>
</td>
</tr>
</table>
<p>
<h:commandButton value="clique ici pour valider" action="Register" />
</p>
</h:form>
我将字段留空后收到此消息
(mm-dd-yy) j_idt5:dob : erreur de validation. Vous devez indiquer une valeur.
为什么消息中有jsf自动生成的id“j_idt5:dob”?
答案 0 :(得分:4)
只要您没有明确指定输入组件的label
属性,输入组件的客户端ID就会成为默认的转换/验证消息标签:
<h:inputText ... label="Date of birth" />
如果你这样做,那么消息将变为:
出生日期:erreur de validation。 Vous devez indiquer une valeur。
客户端ID中的j_idt5
来自<h:form>
。如果你给它一个固定的ID,如id="register"
(并省略输入组件的label
),那么消息就变为:
注册:dob:erreur de validation。 Vous devez indiquer une valeur。
如有必要,可以按validatorMessage
属性覆盖整个验证程序消息。
<h:inputText ... validatorMessage="Please enter date of birth." />
请输入出生日期。
同等地,来自<f:convertDateTime>
的转化错误消息可被converterMessage
属性覆盖。
<h:inputText ... converterMessage="Please enter date of birth in mm-dd-yy format." />
请以mm-dd-yy格式输入出生日期。