Dashboard > JAVA EE > ... > JSF入門 > 輸出類標籤
JAVA EE Log In   View a printable version of the current page.
輸出類標籤
Added by cheetah, last edited by magic on Jan 01, 2006  (view change)
Labels: 
(None)

資料來源: From PmWiki@caterpillar
作者: caterpillar

  輸出類的標籤包括了outputLabel、outputLink、outputFormat與 outputText,分別舉例說明如下:

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

  產生<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綁定。

outputFormat

  產生指定的文字訊息,可以搭配<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>

outputText

  簡單的顯示指定的值或綁定的訊息,例如:

<h:outputText value="#{user.name}"/>

Site powered by a free Open Source Project / Non-profit License (more) of Confluence - the Enterprise wiki.
Learn more or evaluate Confluence for your organisation.
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.1.5a Build:#411 Mar 16, 2006) - Bug/feature request - Contact Administrators