JSF 2のpanelGridの例

JSF 2 panelGridの例

JSFでは、「h:panelGrid」タグを使用してHTMLテーブルタグを生成し、JSFコンポーネントを行と列のレイアウトに左から右、上から下に配置します。

たとえば、JSFコンポーネントを次のようなHTMLテーブルタグでグループ化するために使用しました。

HTML

Enter a number :

h:panelGrid」タグを使用すると、HTMLテーブルタグを入力しなくても、上記と同じテーブルレイアウトを取得できます。

h:panelGrid



    Enter a number :

    
        
    

    

Note
「column」属性はオプションであり、JSFコンポーネントのレイアウトに必要な列数を定義します。デフォルトは1です。

h:panelGridの例

h:panelGrid」タグを使用してコンポーネントを適切にレイアウトする方法を示すJSF2.0の例。

1. マネージドBean

デモ用のダミーBean。

package com.example;

import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;

@ManagedBean(name="dummy")
@SessionScoped
public class DummyBean implements Serializable{

    int number;

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

}

2. JSFページ

h:panelGrid」タグを使用してJSFコンポーネントを3列のレイアウトに配置するJSFXHTMLページ。



    

        

JSF 2 panelGrid example

Enter a number :

次のHTML結果を出力します。





    

JSF 2 panelGrid example

Enter a number :

3. Demo

この例のスクリーンショット。

jsf2-panelGrid-Example-1

jsf2-panelGrid-Example-2

ソースコードをダウンロード

ダウンロード–JSF-2-PanelGrid-Example.zip(9KB)