转自:https://wenku.baidu.com/view/82b84b255901020207409c87.html
:https://blog.csdn.net/qq_36411874/article/details/78337462
JSF标签详解(全)
actionListener
f:actionListener标签为h:commandLink,h:commandButton等指定自定义的事件侦听类。
f:actionListener使用:
JSP:
<h:commandButton id="regist"value="Regist">
<f:actionListenertype="mypackage.ActionListenerImpl"></f:actionListener>
</h:commandButton>
attribute
f:attribute标签用来设置父标签的属性。
f:attribute标签使用例:
JSP:
<h:graphicImage url="/images/picture.jpg">
<f:attribute name="height"value="20"/>
<f:attribute name="width"value="10"/>
</h:graphicImage>
convertDateTime
f:convertDateTime标签用来转换日期格式。
示范代码:
<h:outputTextvalue="#{bean.outputDate}">
<f:convertDateTime
pattern="yyyy年MM月dd日"/>
</h:outputText>
converter
JSF可以使用 f:converter简单地调用指定onverter-id的JSFConverter实现(实现javax.faces.convert.Converter接口的类)对JSF组件组件的输入输出值加以变换。
示范代码:
<h:inputTextvalue="123456">
<f:converterconverterId="myConverterId" />
</h:inputText>
convertNumber
f:convertNumber用来对数字,通货等等进行格式转换
示范代码:
<h:inputText value="123456">
<f:convertNumber type="currency" currencySymbol="$"/>
</h:inputText>
facet
f:facet标签用来为包含f:facet标签的父组件与被f:facet标签所包含的子组件之间申明一种特殊的关系。常与h:panelGrid,h:dataTable等标签连用,申明组件为标题或页脚。
示范代码:
<f:facetname="header">
<h:outputText value="Title"/>
</f:facet>
loadBundle
f:loadBundle是JSF提供的一个支持JSP本地化(多语言支持)操作的标签。
示范代码:
<f:loadBundlebasename="com.test.resource.Messages" var="msg" />
param
f:param 用于向组件添加参数。一般用法主要有2种:
<h:outputLinkvalue="/someUrl">
<f:param name="id"value="#{bean.id}"/>
<f:param name="name"value="#{bean.name}"/>
</h:outputLink>
或<h:outputFormatvalue="You have {0} items in your shopping cart.">
<f:paramvalue="#{SessionBean1.cart.itemCount}"/>
</h:outputFormat>
selectItem
f:selectItem 指定 UISelectOne 或UISelectMany 组件的一个项目,用来为h:selectOneMenu等选择性组件设置选择数据项。
示范代码:
<h:selectOneMenu
value="#{bean.selectedItemValue}">
<f:selectItem itemLabel="Label1"value="0" />
<f:selectItem itemLabel="Label2"value="1" />
</h:selectOneMenu>
selectItems
f:selectItems用于指定 UISelectOne 或UISelectMany 组件的多个项目,
与f:selectItem标签一样,用来为
- h:selectManyCheckbox
- h:selectManyListbox
- h:selectManyMenu
- h:selectOneListbox
- h:selectOneMenu
- h:selectOneRadio
等设置数据项。
subview
可以使用f:subview包含指定的JSF页面,或者其他JSF组件。
使用f:subview包含JSF页面时,被包含的页面里只能包含有JSF组件,所有非JSF组件元素必须用f:verbatim标签进行转换。
示范代码:
<f:subviewid="id3">
<%@ include file="subpage.jsp" %>
</f:subview>
validateDoubleRange
f:validateDoubleRange可以对所有输入类型的组件的输入值加以验证。
f:validateDoubleRange必须被包含在上述输入组件之内。例:
<h:inputText id="amount" value="#{mybean.amount}"required="true">
<f:validateDoubleRange maximum="2500.8"minimum="0.00"></f:validator>
</h:inputText>
validateLength
示范代码:
<h:inputTextid="userId" value="#{mybean.userId}"required="true">
<f:validateLength maximum="16" minimum="8"/>
</h:inputText>
validateLongRange
f:validateLongRange可以对所有输入类型的组件的输入值加以验证。
f:validateLongRange必须被包含在上述输入组件之内。例:
<h:inputText id="amount" value="#{mybean.amount}"required="true">
<f:validateLongRange maximum="2500" minimum="800"/>
</h:inputText>
valueChangeListener
valueChangeListener 向父组件注册值变更监听器。
示范代码:
<h:selectBooleanCheckboxid="sbc_operate" value="#{pc_Attribute.selected}"
valueChangeListener="#{pc_Attribute.onOperateSelectedChange}"
οnclick="submit();">
verbatim
简单说来就是,标签里包含什么,就在网页上输出什么。
示范代码:
<f:verbatim><li/></f:verbatim>
view
view用于 创建顶层视图。
使用样例:
<html>
<body>
<f:view>
<h:column>
<h:outputText value="#{user.name}"/>
</h:column>
</f:view>
</body>
</html>
· JSF Form
column
<h:dataTable>配合<h:column>来以表格的方式显示数据,<h:column>中只能包括 JSF组件或者是<f:facet>,JSF支援两种facet:header与footer。
示范代码:
<h:dataTable value="#{tableBean.userList}" var="user">
<h:column>
<f:facet name="header">
<h:outputText value="Name"/>
</f:facet>
</h:column>
</h:dataTable>
commandButton
commandButton
显示一个命令按钮,即输出<input> HTML标签,其type属性可以设定为button、submit或reset,预设是submit,按下按钮会触发 javax.faces.event. ActionEvent,使用例子如下:
<h:commandButton value="提交"action="#{user.verify}"/>
commandLink
commandLink
产生超链接,会输出<a> HTML标签,而href属性会有'#'。
示范代码:
<h:commandLinkvalue="#{msgs.commandText}"
action="#{user.verify}"/>
dataTable
很多数据经常使用表格来表现,JSF提供<h:dataTable>标签让您得以列举数据并使用表格方式来呈现。
示范代码:
<h:dataTable value="#{tableBean.userList}" var="user">
<h:column>
<h:outputText value="#{user.name}"/>
</h:column>
<h:column>
<h:outputText value="#{user.password}"/>
</h:column>
</h:dataTable>
form
<h:form>和HTML里面的form,用于表单数据提交。
graphicImage
<h:graphicImage>
这个标签会绘制一个HTML <img>标签,value可以指定路径或图片URL,路径可以指定相对路径或绝对路径,例如:
<h:graphicImage value="/images/logowiki.jpg"/>
inputHidden
inputHidden
隐藏输入框,即输出<input> HTML标签,其type属性设定为hidden,隐藏输入框的值用于保留一些于客户端,以在下一次发送表单时一并提交,例如:
<h:inputHidden value="#{user.hiddenInfo}"/>
inputSecret
inputSecret
显示密码输入框,即输出<input> HTML标签,其type属性设定为password,
例如:
<h:inputSecret value="#{user.password}"/>
您可以设定redisplay属性以决定是否要显示密码栏目的值,预设是false。
inputText
inputText显示单行输入框,即输出<input> HTML标签,其type属性设定为text。
例如:
<h:inputText value="#{user.name}"/>
inputTextarea
inputTextarea
显示多行输入文字区域,即输出<textarea> HTML标签,例如:
<h:inputTextarea value="#{user.command}"/>
message
显示一个组件的最近使用的消息,
示范代码:
<h:inputTextid="inp2" />
<h:message for="inp2" showSummary="false"showDetail="true" />
messages
h:messages用于显示所有消息。
使用示范代码:
<h:messages id="messageAll" showDetail="true" showSummary="true"/>
outputFormat
outputFormat
产生指定的文字,可以搭配<f:param>来设定的参数以格式化文字,
例如:
<f:loadBundle basename="messages" var="msgs"/>
<h:outputFormat value="#{msgs.welcomeText}">
<f:param value="Hello"/>
<f:param value="Guest"/>
</h:outputFormat>
outputLabel
outputLabel
产生<label> HTML标签,使用for属性指定组件的client ID,例如:
<h:inputText id="user" value="#{user.name}"/>
<h:outputLabel for="user" value="#{user.name}"/>
这会产生像是以下的标签:
<input id="user" type="text" name="user"value="guest" />
<label for="user">
outputLink
outputLink
产生<a> HTML标签,例如:
<h:outputLink value="../index.jsp">
<h:outputText value="Link to Index"/>
<f:param name="name" value="MyName"/>
</h:outputLink>
你可搭配<f:param>帮链结加上参数,所有的参数都会变成 name=value 的类型附加在链接后。
value所指定的内容也可以是JSF EL绑定。
outputText
outputText
简单的显示指定的值或绑定的,例如:
<h:outputText value="#{user.name}"/>
panelGrid
<h:panelGrid>
这个标签可以用来作简单的组件排版,它会使用HTML表格标签来绘制表格,并将组件置于其中,主要指定columns属性。
例如:
<h:panelGridcolumns="2">
<h:outputText value="Username"/>
<h:inputText id="name" value="#{userBean.name}"/>
。。。。</h:panelGrid>
panelGroup
<h:panelGroup>
这个组件用来将数个JSF组件包装起来,使其看来像是一个组件,例如:
<h:panelGroup>
<h:commandButton value="submit" action="login"/>
<h:commandButton value="reset" type="reset"/>
</h:panelGroup>
selectBooleanCheckbox
<h:selectBooleanCheckbox>在视图上呈现一个复选框。
例如:
我同意 <h:selectBooleanCheckboxvalue="#\{user.aggree\}"/>
value所绑定的属性必须接受与传回boolean类型
selectManyCheckbox
这个标签提供使用者复选项目的功能
例子如下:
<h:selectManyCheckbox layout="pageDirection"
value="#{user.preferColors}">
<f:selectItem itemLabel="红" itemValue="false"/>
<f:selectItem itemLabel="黄" itemValue="false"/>
<f:selectItem itemLabel="蓝" itemValue="false"/>
</h:selectManyCheckbox>
selectManyListbox
这个标签提供使用者复选项目的功能
例子如下:
<h:selectManyListbox layout="pageDirection"
value="#{user.preferColors}">
<f:selectItem itemLabel="红" itemValue="false"/>
<f:selectItem itemLabel="黄" itemValue="false"/>
<f:selectItem itemLabel="蓝" itemValue="false"/>
</h:selectManyListbox>
selectManyMenu
这个标签提供使用者复选项目的功能。
例子如下:
<h:selectManyMenu layout="pageDirection"
value="#{user.preferColors}">
<f:selectItem itemLabel="红" itemValue="false"/>
<f:selectItem itemLabel="黄" itemValue="false"/>
<f:selectItem itemLabel="蓝" itemValue="false"/>
</h:selectManyMenu>
selectOneListbox
selectOneListbox为单选列表框。
使用示范代码:
<h:selectOneListboxlayout="pageDirection" value="#{user.education}">
<f:selectItem itemLabel="高中" itemValue="高中"/>
<f:selectItemitemLabel="大學" itemValue="大學"/>
<f:selectItem itemLabel="研究所以上" itemValue="研究所以上"/>
</h:selectOneListbox>
selectOneMenu
selectOneMenu 为下拉框,,和HTML的下拉框一样。
使用示范代码:
<h:selectOneMenulayout="pageDirection" value="#{user.education}">
<f:selectItem itemLabel="高中" itemValue="高中"/>
<f:selectItemitemLabel="大學" itemValue="大學"/>
<f:selectItem itemLabel="研究所以上" itemValue="研究所以上"/>
</h:selectOneMenu>
selectOneRadio
selectOneRadio为单选按钮集,类似网页的<input type="radio" ....
使用示例如下:
<h:selectOneRadiovalue="#{user.education}">
<f:selectItem itemLabel="高中"itemValue="高中"/>
<f:selectItem itemLabel="大学"itemValue="大学"/>
<f:selectItem itemLabel="研究所以上"itemValue="研究所以上"/>
</h:selectOneRadio>