< h:messages>是什么?在JSF中做? [英] What does <h:messages> do in JSF?
问题描述
我正在学习JSF,并且碰到了这条线:
I am learning JSF and came across this line:
<h:messages layout="table"></h:messages>
在示例应用程序中?
不确定这行是做什么的吗?从代码中删除该行时,我没有出现任何错误,并且能够运行它并获得相同的输出?
Am not sure what does this line do? I get no error when removing the line from the code, and am able to run it and get the same output ?
推荐答案
h:messages
标记呈现当前JSF视图中未被h:message
覆盖的所有消息(在末尾标注缺失的"s")标签.消息可以由您的支持bean(FacesContext.addMessage
)显式生成,也可以由JSF隐式生成.
The h:messages
tag renders all messages for the current JSF view which are not covered by a h:message
(remark the missing 's' at the end) tag. Messages can be generated explicitly by your backing beans (FacesContext.addMessage
) or implicitly by JSF.
例如如果您已将输入值标记为必需,并且用户在提交表单时未填写必需值,则会向该视图添加错误消息.如果将h:message
标签绑定到相关组件,则将在此处呈现该消息,否则将通过您视图中的全局h:messages
标签(如果有)呈现该消息.
E.g. if you have marked an input value as required and the user submits the form without filling in the required value, an error message will be added to the view. If a h:message
tag is bound to the relevant component, the message will be rendered there, otherwise it will be rendered by the global h:messages
tag in your view (if any).
layout
属性指定要生成的HTML代码的外观. table
布局(在您的示例中使用)使用HTML表显示消息,而list
布局使用项目符号列表(HTML ul
标记).
The layout
attribute specifies what the HTML code to be generated should look like. The table
layout (used in your example) uses an HTML table to display messages, while the list
layout uses a bulleted list (HTML ul
tag).
如果您不在视图中指定一个h:messages
标记,并且也没有指定h:message
标记,则不会通知用户错误.因此,最佳做法是为视图的每个输入组件包括一个h:message
标记,为整个视图包括一个h:messages
标记,以确保所有消息对用户可见.
If you do not specify a h:messages
tag in your view and also no h:message
tags, the user will not be informed about errors. Therefore, it is best practice to include a h:message
tag for each input component of your view and a h:messages
tag for your whole view to ensure that all messages are visible to the user.
您可以在 JSF工具箱中找到紧凑的JSF标记引用.
You will find a compact JSF tag reference at JSF Toolbox.
这篇关于< h:messages>是什么?在JSF中做?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!