SeamFramework.orgCommunity Documentation
Seam には Seam での作業に便利な JSF コントロールがいくつか含まれています。これらは組み込み JSF コントロールと他のサードパーティライブラリのコントロールの機能補完を目的としています。 Seam と併用する際は、JBoss RichFaces、Apache MyFaces Trinidad タグライブラリの使用を推奨します。 Tomahawk タグライブラリの使用はお薦めできません。
これらのタグを使用するには、 以下のように使用するページで "s
" 名前空間を定義します (facelets 固有)。
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
>
UIサンプル(examples/ui)ではいくつかのタグの使用例を示しています。
詳細
対話の伝搬を制御するアクションの起動をサポートするボタンです。 フォームはサブミットしません。
属性
value
— ラベル。
action
— アクションリスナーを指定する値バインディング。
view
— リンクする JSF view id 。
fragment
— リンクするフラグメント ID 。
disabled
— リンクが無効かどうか
propagation
— 対話の伝播方式の指定 : begin
, join
, nest
, none
または end
。
pageflow
— 開始するページフロー定義 (propagation="begin"
または propagation="join"
の場合のみ有効)。
使い方
<s:button id="cancel"
value="Cancel"
action="#{hotelBooking.cancel}"/>
<s:link />
には、 view
と action
の両方が指定可能です。 この場合、指定されたビューへのリダイレクトが発生した時点でアクションが呼ばれます。
<s:button />
ではアクションリスナー(デフォルトのJSFアクションリスナーも含む)の使用はサポートされません。
詳細
対話の伝搬を制御するアクションの起動をサポートするリンクです。 フォームはサブミットしません。
<s:link />
ではアクションリスナー(デフォルトのJSFアクションリスナーも含む)の使用はサポートされません。
属性
value
— ラベル。
action
— アクションリスナーを指定する値バインディング。
view
— リンクする JSF view id 。
fragment
— リンクするフラグメント ID 。
disabled
— リンクが無効かどうか
propagation
— 対話の伝播方式の指定 : begin
, join
, nest
, none
または end
。
pageflow
— 開始するページフロー定義 (propagation="begin"
または propagation="join"
の場合のみ有効)
使い方
<s:link id="register" view="/register.xhtml"
value="Register New User"/>
<s:link />
には、 view
と action
の両方が指定可能です。 この場合、指定されたビューへのリダイレクトが発生した時点でアクションが呼ばれます。
詳細
コマンドリンクやボタン (または同様の JSF コントロール) に対する対話の伝搬をカスタマイズします。 Facelets 固有です。
属性
対話の伝播方式を指定します : begin
、join
、nest
、none
または end
pageflow
— 開始するページフロー定義 (propagation="begin"
または propagation="join"
の場合のみ有効)
使い方
<h:commandButton value="Apply" action="#{personHome.update}">
<s:conversationPropagation type="join" />
</h:commandButton
>
詳細
enterキーでフォームをサブミットしたときに実行するデフォルトアクションを指定します。
今のところ、ボタン (例えば<h:commandButton />
、<a:commandButton />
または <tr:commandButton />
)の中にネストすることのみできます。
元となるアクションにはIDを指定しなければいけません。フォームには一つのデフォルトアクションしか持てません。
属性
なし
使い方
<h:commandButton id="foo" value="Foo" action="#{manager.foo}">
<s:defaultAction />
</h:commandButton
>
詳細
Seam タイムゾーン内でデータ変換または時刻変換を行います。
属性
なし
使い方
<h:outputText value="#{item.orderDate}">
<s:convertDateTime type="both" dateStyle="full"/>
</h:outputText
>
詳細
エンティティコンバータを現在のコンポーネントに割り当てます。 ラジオボタンコントロールおよびドロップダウンコントロールに役立ちます。
コンバータは管理されたどのようなエンティティとも動作します。単純なエンティティでも複合エンティティでも同様です。フォームのサブミット時にコンバータはJSFコントロールで宣言された項目を見つけることができるべきです。さもなければバリデーションエラーを受け取ることになるでしょう。
属性
なし
設定
<s:convertEntity />
は Seam管理トランザクション (Seam managed transaction) ( 項9.2. 「Seam 管理トランザクション」 参照) とともに使う必要があります。
管理された永続コンテキスト (Managed Persistence Context) が entityManager
と呼ばれていないならば、 components.xmlで設定する必要があります:
<components xmlns="http://jboss.com/products/seam/components" xmlns:ui="http://jboss.com/products/seam/ui"> <ui:jpa-entity-loader entity-manager="#{em}" />
管理された Hibernate セッション を使用するならば、components.xmlで設定する必要があります:
<components xmlns="http://jboss.com/products/seam/components" xmlns:ui="http://jboss.com/products/seam/ui"> <ui:hibernate-entity-loader />
管理された Hibernate セッション (Managed Hibernate Session) が session
と呼ばれていないならば、components.xmlで設定する必要があります:
<components xmlns="http://jboss.com/products/seam/components" xmlns:ui="http://jboss.com/products/seam/ui"> <ui:hibernate-entity-loader session="#{hibernateSession}" />
ひとつ以上のエンティティマネージャをエンティティコンバータと使いたい場合、components.xml
でそれぞれのエンティティマネージャに対してエンティティコンバータのコピーを作成することができます。エンティティコンバータがどのようにエンティティローダに永続化処理を委譲するのか注意してください:
<components xmlns="http://jboss.com/products/seam/components" xmlns:ui="http://jboss.com/products/seam/ui"> <ui:entity-converter name="standardEntityConverter" entity-loader="#{standardEntityLoader}" /> <ui:jpa-entity-loader name="standardEntityLoader" entity-manager="#{standardEntityManager}" /> <ui:entity-converter name="restrictedEntityConverter" entity-loader="#{restrictedEntityLoader}" /> <ui:jpa-entity-loader name="restrictedEntityLoader" entity-manager="#{restrictedEntityManager}" />
<h:selectOneMenu value="#{person.continent}"> <s:selectItems value="#{continents.resultList}" var="continent" label="#{continent.name}" /> <f:converter converterId="standardEntityConverter" /> </h:selectOneMenu >
使い方
<h:selectOneMenu value="#{person.continent}" required="true">
<s:selectItems value="#{continents.resultList}" var="continent"
label="#{continent.name}"
noSelectionLabel="Please Select..."/>
<s:convertEntity />
</h:selectOneMenu
>
詳細
enum コンバータを現在のコンポーネントに割り当てます。 おもにラジオボタンコントロールおよびドロップダウンコントロールに役立ちます。
属性
なし
使い方
<h:selectOneMenu value="#{person.honorific}">
<s:selectItems value="#{honorifics}" var="honorific"
label="#{honorific.label}"
noSelectionLabel="Please select" />
<s:convertEnum />
</h:selectOneMenu
>
詳細
java.util.concurrent.atomic.AtomicBoolean
のための javax.faces.convert.Converter
です。
属性
なし
使い方
<h:outputText value="#{item.valid}"> <s:convertAtomicBoolean /> </h:outputText >
詳細
java.util.concurrent.atomic.AtomicInteger
のための javax.faces.convert.Converter
です。
属性
なし
使い方
<h:outputText value="#{item.id}"> <s:convertAtomicInteger /> </h:outputText >
詳細
java.util.concurrent.atomic.AtomicLong
のための javax.faces.convert.Converter
です。
属性
なし
使い方
<h:outputText value="#{item.id}"> <s:convertAtomicLong /> </h:outputText >
詳細
Tag to nest inside an input control to validate that its parent's value is equal (or not equal!) to the referenced control's value.
属性
for
— 検証の対象となるコントロールのID
message
— 失敗時に表示されるメッセージ
messageId
— 失敗時に表示するメッセージID
operator
— What operator to use when comparing the values Valid operators are:
equal
— Validates that value.equals(forValue)
not_equal
— Validates that !value.equals(forValue)
greater
— Validates that ((Comparable)value).compareTo(forValue)
> 0
greater_or_equal
— Validates that ((Comparable)value).compareTo(forValue)
>= 0
less
— Validates that ((Comparable)value).compareTo(forValue) <0
less_or_equal
— Validates that ((Comparable)value).compareTo(forValue) <= 0
使い方
<h:inputText id="name" value="#{bean.name}"/> <h:inputText id="nameVerification" > <s:validateEquality for="name" /> </h:inputText >
詳細
非視覚的なコントロールです。 Hibernate Validator を使用してバウンドプロパティに対して JSF 入力フィールドを確認します。
属性
なし
使い方
<h:inputText id="userName" required="true"
value="#{customer.userName}">
<s:validate />
</h:inputText>
<h:message for="userName" styleClass="error" />
詳細
非視覚的なコントロールです。 Hibernate Validator を使ってそのバウンドプロパティに対しすべての子 JSF 入力フィールドを確認します。
属性
なし
使い方
<s:validateAll>
<div class="entry">
<h:outputLabel for="username"
>Username:</h:outputLabel>
<h:inputText id="username" value="#{user.username}"
required="true"/>
<h:message for="username" styleClass="error" />
</div>
<div class="entry">
<h:outputLabel for="password"
>Password:</h:outputLabel>
<h:inputSecret id="password" value="#{user.password}"
required="true"/>
<h:message for="password" styleClass="error" />
</div>
<div class="entry">
<h:outputLabel for="verify"
>Verify Password:</h:outputLabel>
<h:inputSecret id="verify" value="#{register.verify}"
required="true"/>
<h:message for="verify" styleClass="error" />
</div>
</s:validateAll
>
詳細
検証に失敗した場合または required="true"
が設定されている場合、 JSF 入力フィールドを "装飾" します。
属性
template
— コンポーネントを装飾するためのfaceletテンプレート
enclose
— if true, the template used to decorate the input field is enclosed by the element specified with the "element" attribute. By default this is a div element.
element
— the element to enclose the template used to decorate the input field. By default, the template is enclosed with a div element.
#{invalid}
と #{required}
が s:decorate
の内部で利用可能です; 入力コンポーネントを入力必須として装飾した場合、#{required}
は true
と評価されます。また、検証エラーが起こった場合、 #{invalid}
は true
と評価されます。
使い方
<s:decorate template="edit.xhtml">
<ui:define name="label"
>Country:</ui:define>
<h:inputText value="#{location.country}" required="true"/>
</s:decorate
>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.com/products/seam/taglib">
<div
>
<s:label styleClass="#{invalid?'error':''}">
<ui:insert name="label"/>
<s:span styleClass="required" rendered="#{required}"
>*</s:span>
</s:label>
<span class="#{invalid?'error':''}">
<s:validateAll>
<ui:insert/>
</s:validateAll>
</span>
<s:message styleClass="error"/>
</div
>
</ui:composition
>
詳細
HTML <div>
をレンダリングします。
属性
なし
使い方
<s:div rendered="#{selectedMember == null}">
Sorry, but this member does not exist.
</s:div
>
詳細
HTML <span>
をレンダリングします。
属性
title
— span のタイトル
使い方
<s:span styleClass="required" rendered="#{required}" title="Small tooltip"
>*</s:span
>
詳細
レンダリングされないコンポーネントです。その子要素のレンダリングを有効化/無効化するのに便利です。
属性
なし
使い方
<s:fragment rendered="#{auction.highBidder ne null}">
Current bid:
</s:fragment
>
詳細
JSF入力フィールドをラベルで "装飾" します。ラベルはHTMLでは <label>
タグで配置され、最も近いJSF入力コンポーネントと関連づけられます。 よく <s:decorate>
とともに使用されます。
属性
style
— コントロールのスタイル。
styleClass
— コントロールのスタイルクラス。
使い方
<s:label styleClass="label">
Country:
</s:label>
<h:inputText value="#{location.country}" required="true"/>
詳細
Produces a random token that is inserted into a hidden form field to help to secure JSF form posts against cross-site request forgery (XSRF) attacks. Note that the browser must have cookies enabled to submit forms that include this component.
属性
requireSession
— indicates whether the session id should be included in the form signature, hence binding the token to the session. This value can be set to false if the "build before restore" mode of Facelets is activated (the default in JSF 2.0). (default: false)
enableCookieNotice
— indicates that a JavaScript check should be inserted into the page to verify that cookies are enabled in the browser. If cookies are not enabled, present a notice to the user that form posts will not work. (default: false)
allowMultiplePosts
— indicates whether to allow the same form to be submitted multiple times with the same signature (as long as the view does not change). This is a common need if the form is perform Ajax calls but not rerendering itself or, at the very least, the UIToken component. The preferred approach is to have the UIToken component rerendered on any Ajax call where the UIToken component would be processed. (default: false)
使い方
<h:form>
<s:token enableCookieNotice="true" requireSession="false"/>
...
</h:form>
詳細
enum の値から SelectItem
を作成します。
属性
enumValue
— 列挙値の文字列表現
label
— SelectItem
をレンダリングする際に使用するラベル
使い方
<h:selectOneRadio id="radioList"
layout="lineDirection"
value="#{newPayment.paymentFrequency}">
<s:convertEnum />
<s:enumItem enumValue="ONCE" label="Only Once" />
<s:enumItem enumValue="EVERY_MINUTE" label="Every Minute" />
<s:enumItem enumValue="HOURLY" label="Every Hour" />
<s:enumItem enumValue="DAILY" label="Every Day" />
<s:enumItem enumValue="WEEKLY" label="Every Week" />
</h:selectOneRadio
>
詳細
List、 Set、 DataModel または Array から List<SelectItem>
を作成します。
属性
value
— List<SelectItem>
に格納されるデータを指定するEL式。
var
— 繰り返し中、現在のオブジェクトを保持するローカル変数の名前を定義します。
label
— SelectItem
をレンダリングする際に使用するラベル。 var
変数を参照できます。
itemValue
— この選択肢が選ばれたときにサーバへ送信する値。この指定はオプションです。デフォルトでは var
オブジェクトが使用されます。var
変数を参照できます。
disabled
— true の場合、 SelectItem
はレンダリングされません。var
変数を参照できます。
noSelectionLabel
— リストの最初に表示される (オプションの) ラベルを指定します ( required="true"
も指定されている場合、この値を選択すれば検証エラーになるでしょう) 。
hideNoSelectionLabel
— true の場合、値が選択されているときは noSelectionLabel
は隠されます。
使い方
<h:selectOneMenu value="#{person.age}"
converter="ageConverter">
<s:selectItems value="#{ages}" var="age" label="#{age}" />
</h:selectOneMenu
>
詳細
ファイルアップロードコントロールをレンダリングします。 このコントロールはエンコーディングタイプ multipart/form-data
を使用してフォーム内で使用する必要があります。
<h:form enctype="multipart/form-data"
>
マルチパート要求の場合、 Seam Multipart サーブレットフィルタも web.xml
内で設定しなければなりません。
<filter>
<filter-name
>Seam Filter</filter-name>
<filter-class
>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name
>Seam Filter</filter-name>
<url-pattern
>/*</url-pattern>
</filter-mapping
>
設定
components.xml では、 次のようなマルチパート要求用の設定オプションが設定できます。
createTempFiles
— true の場合、アップロードされたファイルはメモリではなく一時ファイルに保存されます。
maxRequestSize
— ファイルアップロード要求の最大サイズです。単位はバイトです。
例:
<component class="org.jboss.seam.web.MultipartFilter">
<property name="createTempFiles"
>true</property>
<property name="maxRequestSize"
>1000000</property>
</component
>
属性
data
— この値バインディングはバイナリのファイルデータを受け取ります。受け取るフィールドは byte[]
または InputStream
として宣言されている必要があります(必須)。
contentType
— この値バインディングはファイルのコンテントタイプを受け取ります (オプション)。
fileName
— この値バインディングはファイル名を受け取ります (オプション)。
fileSize
— この値バインディングはファイルサイズを受け取ります (オプション)。
accept
— 受け入れるコンテントタイプの、カンマ区切りのリストです。ブラウザによってサポートされないかもしれません。 例: "images/png,images/jpg"
、 "images/*"
。
style
— コントロールのスタイル。
styleClass
— コントロールのスタイルクラス。
使い方
<s:fileUpload id="picture" data="#{register.picture}"
accept="image/png"
contentType="#{register.pictureContentType}" />
詳細
JBoss Cache を使用してレンダリングされるページフラグメントの Cache です。 <s:cache>
は実際には組み込みの pojoCache
コンポーネントで管理される JBoss Cache のインスタンスを使用するので注意してください。
属性
key
— レンダリングされたコンテンツをキャッシュするキーです。値式を使うことが多いです。例えばドキュメントを表示するページフラグメントをキャッシュする場合、 key="Document-#{document.id}"
のように使います。
enabled
— キャッシュを使うべきかどうか決定する値式。
region
— 使用する JBoss Cache のノード(ノード毎に異なる有効期限ポリシーを持つことができます)。
使い方
<s:cache key="entry-#{blogEntry.id}" region="pageFragments">
<div class="blogEntry">
<h3
>#{blogEntry.title}</h3>
<div>
<s:formattedText value="#{blogEntry.body}"/>
</div>
<p>
[Posted on 
<h:outputText value="#{blogEntry.date}">
<f:convertDateTime timezone="#{blog.timeZone}" locale="#{blog.locale}"
type="both"/>
</h:outputText
>]
</p>
</div>
</s:cache
>
詳細
A tag that acts a file download provider. It must be alone in the JSF page. To be able to use this contol, web.xml must be set up as follows.
設定
<servlet>
<servlet-name>Document Store Servlet</servlet-name>
<servlet-class>org.jboss.seam.document.DocumentStoreServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Document Store Servlet</servlet-name>
<url-pattern>/seam/docstore/*</url-pattern>
</servlet-mapping>
属性
data
— Data that should be downloaded. May be a java.util.File, an InputStream or a byte array.
fileName
— Filename of the file to be served
contentType
— content type of the file to be downloaded
disposition
— disposition to use. Default is inline
使い方
Here is an example on how to use the tag:
<s:resource xmlns="http://www.w3.org/1999/xhtml"
xmlns:s="http://jboss.com/products/seam/taglib"
data="#{resources.data}"
contentType="#{resources.contentType}"
fileName="#{resources.fileName}" />
The bean named resources
is some backing bean that given some request parameters servers a specific file, see s:download
.
詳細
Builds a RESTful link to a <s:resource>
. Nested f:param
build up the url.
src
— Resource file serving files.
属性
<s:download src="/resources.xhtml">
<f:param name="fileId" value="#{someBean.downloadableFileId}"/>
</s:download>
Will produce something like: http://localhost/resources.seam?fileId=1
詳細
拡張された <h:graphicImage>
で、Seamコンポーネント内で画像を作成することを許可します。 さらに画像の変換も適用できます。
<h:graphicImage>
のすべての属性がサポートされている他、 以下もサポートされています。
属性
value
— 表示する画像です。パスを表す String
(クラスパスからロードされます)、byte[]
、java.io.File
、java.io.InputStream
または java.net.URL
が指定可能です。現在サポートされる画像フォーマットは image/png
、image/jpeg
と image/gif
です。
fileName
— 指定しなかった場合、画像は生成されたファイル名を持ちます。ファイルに名前を付けたい場合、ここで指定してください。この名前は一意である必要があります。
変換
イメージに変換を適用するには、 適用する変換を指定するタグをネストさせます。 Seam は現在、 次のような変換をサポートしています。
<s:transformImageSize>
width
— 画像の幅を指定します。
height
— 画像の高さを指定します。
maintainRatio
— true
が指定され、かつ width
と height
の 片方 が指定された場合、指定されなかった側をアスペクト比を維持するよう計算し、画像をリサイズします。
factor
— 与えられた係数で画像を拡大縮小します。
<s:transformImageBlur>
radius
— 与えられた半径でコンボリューションブラーを実行します。
<s:transformImageType>
contentType
— 画像のタイプを image/jpeg
または image/png
に変更します。
変換を自作するのは簡単です - org.jboss.seam.ui.graphicImage.ImageTransform
を実装する UIComponent
を作成します。 applyTransform()
メソッド内で image.getBufferedImage()
を使って元の画像を取得し、image.setBufferedImage()
で変換した画像をセットします。変換はビューに指定された順序で適用されます。
使い方
<s:graphicImage rendered="#{auction.image ne null}"
value="#{auction.image.data}">
<s:transformImageSize width="200" maintainRatio="true"/>
</s:graphicImage
>
詳細
Seam Remoting を使うのに必要な Javascript のスタブを生成します。
属性
include
— コンポーネント名 (または完全修飾クラス名)のカンマ区切りのリストです。これらの Seam Remoting の Javascript スタブを生成します。詳しくは 章 25. リモーティング を参照してください。
使い方
<s:remote include="customerAction,accountAction,com.acme.MyBean"/>
Seamはさらに、SeamコンポーネントをJSFコンバータやバリデータとして使えるようにするアノテーションを提供します:
@Converter
@Name("itemConverter")
@BypassInterceptors
@Converter
public class ItemConverter implements Converter {
@Transactional
public Object getAsObject(FacesContext context, UIComponent cmp, String value) {
EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
entityManager.joinTransaction();
// Do the conversion
}
public String getAsString(FacesContext context, UIComponent cmp, Object value) {
// Do the conversion
}
}
<h:inputText value="#{shop.item}" converter="itemConverter" />
SeamコンポーネントをJSFバリデータとして登録します。ここで例に挙げたのは、値をそのオブジェクト表現に変換する際に、JTAトランザクション内でJPAエンティティマネージャにアクセスするようなコンバータです。
@Validator
@Name("itemValidator")
@BypassInterceptors
@org.jboss.seam.annotations.faces.Validator
public class ItemValidator implements javax.faces.validator.Validator {
public void validate(FacesContext context, UIComponent cmp, Object value)
throws ValidatorException {
ItemController ItemController = (ItemController) Component.getInstance("itemController");
boolean valid = itemController.validate(value);
if (!valid) {
throw ValidatorException("Invalid value " + value);
}
}
}
<h:inputText value="#{shop.item}" validator="itemValidator" />
SeamコンポーネントをJSFバリデータとして登録します。ここで例に挙げたのは、別のSeamコンポーネントをインジェクトし、インジェクトされたコンポーネントが値を検証するようなバリデータです。