输出类的标签包括了outputLabel、outputLink、outputFormat与 outputText,分别举例说明如下:
产生<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">
产生<a> HTML标签,例如:
<h:outputLink value="../index.jsp"/> value所指定的内容也可以是JSF EL绑定。
产生指定的文字讯息,可以搭配<f:param>来设定讯息的参数以格式化文字讯息,例如:
<f:loadBundle basename="messages" var="msgs"/> <h:outputFormat value="#{msgs.welcomeText}"> <f:param value="Hello"/> <f:param value="Guest"/> </h:outputFormat> 如果您的messages.properties包括以下的内容: welcomeText={0}, Your name is {1}. 则{0}与{1}会被取代为<f:param>设定的文字,最后显示的文字会是: Hello, Your name is Guest. 另一个使用的方法则是: <h:outputFormat value="{0}, Your name is {1}."> <f:param value="Hello"/> <f:param value="Guest"/> </h:outputFormat>
简单的显示指定的值或绑定的讯息,例如:
<h:outputText value="#{user.name}"/> |