我目前正在尝试使用 required="true" 进行简单验证
<h:form>
<h:messages globalOnly="true"/>
<h:panelGrid>
<h:panelGrid columns="3">
<f:facet name="header">
Login Application Sample
</f:facet>
<h:outputLabel for="UserId" value="User Id" />
<h:inputText id="UserId" value="#{userBean.userId}" required="true" />
<h:message for="UserId"/>
<h:outputLabel for="Password" value="Password" />
<h:inputSecret id="Password" value="#{userBean.password}" required="true" />
<h:message for="Password" />
<f:facet name="footer">
<h:commandButton value="Login" action="#{userBean.login}"/>
<h:commandButton type="reset" value="Reset"/>
</f:facet>
</h:panelGrid>
</h:panelGrid>
</h:form>
将字段留空,然后单击登录按钮,这些错误消息将显示在每个字段的右侧:
j_idt7:UserId:验证错误:需要值。
j_idt7:密码:验证错误:需要值。
这是我所期望的,但我不想显示“j_idt7:”的表单 ID 前缀。我阅读书籍示例,它们不输出表单 id 前缀。我想要的是:
UserId:验证错误:值是必需的。
密码:验证错误:需要值。
我应该怎么做才能跳过在组件特定消息中显示表单 ID 前缀?
我目前正在 glassfish v3 中测试 JSF 2。