かずきのBlog

C#やJavaやRubyとメモ書き

目次

Blog 利用状況

ニュース

わんくまBlogが不安定になったため、前に書いてたはてなダイアリーにメインを移動します。
かずきのBlog@Hatena
技術的なネタは、こちらにも、はてなへのリンクという形で掲載しますが、雑多ネタははてなダイアリーだけに掲載することが多いと思います。
コメント
プログラマ的自己紹介
お気に入りのツール/IDE
プロフィール
経歴
広告
アクセサリ

書庫

日記カテゴリ

[Java][NetBeans]Visual Web JSFを使った一覧/更新画面作成

Woodstockコンポーネントが非常に使いにくいNetBeansのVisual Web JSFですが、標準のJSFのコンポーネントもついてきてるので、そっちを使った場合の画面の作り方を書いてみようと思う。
Woodstockのコンポーネントを使った例とかは、恐らく本家のほうにいっぱい?あると思うので。

因みに、使用しているNetBeansのバージョンは6.5のRC2です。
Windows Vista Business SP1の上では順調に動いてる。あんまり使ってないけど、普通に立ち上げて軽く使う分には問題なさそうな感じです。

プロジェクト作成

StdVWJEduという名前でWebアプリケーションを新規作成する。

  • アプリケーションサーバはGlassFish v2
  • 使用するフレームワークはVisual Web JSF

使用するDBは、sampleデータベースにする。テーブルはCustomerテーブルを使おうと思う。

エンティティの作成

JPAのエンティティを作成する。

  1. ソースパッケージにentitiesパッケージを作成する
    image
  2. 次にデータベースからのエンティティークラスを作成image
  3. データソースをjdbc/sampleにしてCUSTOMER表を選択した状態にして次へ
    image
  4. 持続性ユニットが無いといわれるのでボタンを押して作成する
    image
  5. ダイアログが出るが、そのまま完了。
  6. 完了をするとクラスが作成される。
    image

これでエンティティクラスの作成は完了。次は、画面の見た目を作っていこうと思う。

画面の作成

Page1.jspを作りこんで行く。
といっても、とりあえず画面にデータ表を貼り付けるだけ。
image

Javaのほうに移動してListDataModel型のdataModelという名前のプロパティを作成する。
ついでに、DBアクセスするときに使うEntityManagerのフィールドも作成しておく。

// DBアクセスに使うエンティティマネージャ
@PersistenceContext
private EntityManager em;

// 表に表示するためのデータの入れ物
private ListDataModel dataModel;
public ListDataModel getDataModel() {
    return dataModel;
}
public void setDataModel(ListDataModel dataModel) {
    this.dataModel = dataModel;
}

そうして、prerenderメソッドに下記の処理を追加する。

@Override
public void prerender() {
    if (dataModel == null) {
        // dataModelが存在しない場合はDBからデータを取得する
        List<Customer> customers = em.createQuery("select c from Customer c order by c.customerId").getResultList();
        dataModel = new ListDataModel(customers);
    }
}

このままだと、管理ビーンはRequestスコープなので毎回dataModelはnullに初期化されてしまう。なので、毎回DBにアクセスするはめになる。
ケースバイケースだけど、今回は毎回DBに行くよりも前回のデータをSessonに保持するようにした。

使用するのはinitメソッドとdestroyメソッド。initにSessionからのデータの取得。destroyにSessionへのデータの格納処理を書く。

@Override
public void init() {
    // 自動生成されるコードは省略

    // TODO - add your own initialization code here
    dataModel = (ListDataModel) getSessionMap().get("Page1.dataModel");
}
@Override
public void destroy() {
    getSessionMap().put("Page1.dataModel", dataModel);
}

これで、データが保持されるようになった。最後にdataModelと画面に置いたデータ表を関連付ける。
データ表の右クリックメニューで「表レイアウト」を選択する。
image

出てくる画面で、先ほど作成したdataProviderプロパティを指定する。

カラムを3つ追加する。
image

各カラムに対して以下の設定を行う。

column1

設定項目名
ヘッダーテキスト ID
フッターテキスト (未入力状態)
コンポーネントの種類 出力テキスト
#{currentRow.customerId}

column2の場合は、値の部分が#{currentRow.name}、ヘッダーテキストがNameに変わるだけのはず。column3は値を#{currentRow.zip}に、ヘッダーテキストをZipに設定する。

この時点で実行すると、データが表示される簡単な画面が出来上がっている。
image

これで一覧表示が出来た。見た目とかには拘らないし、たくさんデータがあるときの処理なども考慮してないけど。
次は、IDの列をアンカーにして、そこをクリックすると更新用の画面に移動させて更新をするようにしたいと思う。

今日は、眠いのでここまで。

投稿日時 : 2008年11月3日 2:56

Feedback

# NetBeans 2009/11/07 21:16 ĿŪʥΥڡ PukiWiki plus! (PukiWiki/TrackBack 0.3)

NetBeans? &nbsp;С NetBeans IDE 6.7.1 &nbsp;Groovy ?Java?????GroovyΥ??????GroovyΥ??????ä? &nbsp;Visual JSF 6.7???ä...

# louis vuitton backpack 2012/10/28 3:09 http://www.louisvuittonbackpack2013.com/

Adoration, friendship, follow, tend not to link men or women over a regular hatred to find a thing.
louis vuitton backpack http://www.louisvuittonbackpack2013.com/

# louis vuitton outlet 2012/10/28 3:09 http://www.louisvuittonwallets2013.com/

Absolute camaraderie foresees the requirements of various in lieu of exalt it is usually have possession of.
louis vuitton outlet http://www.louisvuittonwallets2013.com/

# cheap louis vuitton purses 2012/10/28 3:09 http://www.louisvuittonoutletbags2013.com/

I like happened due to what you do, then again due to people who My corporation is while i are against you.
cheap louis vuitton purses http://www.louisvuittonoutletbags2013.com/

# louis vuitton diaper bag 2012/10/28 3:10 http://www.louisvuittonoutletdiaperbag.com/

The actual saddest route to ignore someone might be and also directly they always them all with the knowledge you'll‘h ask them to.
louis vuitton diaper bag http://www.louisvuittonoutletdiaperbag.com/

# cheap tie 2012/10/28 15:57 http://www.burberryoutletonlineshopping.com/burber

Enjoyed reading this, very good stuff, regards . "Curiosity killed the cat, but for a while I was a suspect." by Steven Wright.
cheap tie http://www.burberryoutletonlineshopping.com/burberry-ties.html

# Adidas Climacool Ride 2012/10/30 20:17 http://www.adidasoutle.com/adidas-shoes-adidas-cli

Some genuinely good posts on this internet site , thankyou for contribution.
Adidas Climacool Ride http://www.adidasoutle.com/adidas-shoes-adidas-climacool-ride-c-1_3.html

# clarisonic mia Sale 2012/10/30 21:18 http://www.clarisonicmia-coupon.com/

Wear‘testosterone strive so faithfully, the most impressive items arise if you the very anticipate those to.
clarisonic mia Sale http://www.clarisonicmia-coupon.com/

# Nike Free 3.0 2012/10/30 21:19 http://www.nikefree3runschuhe.com/

Adoration, acquaintance, respectfulness, never unite people as much as a standard hate meant for issue.
Nike Free 3.0 http://www.nikefree3runschuhe.com/

# womens shirts 2012/11/03 1:49 http://www.burberryoutletscarfsale.com/burberry-wo

I just couldn't go away your web site before suggesting that I really enjoyed the standard information an individual provide in your guests? Is gonna be again often to check out new posts.
womens shirts http://www.burberryoutletscarfsale.com/burberry-womens-shirts.html

# Women's Duvetica Coats 2012/11/03 3:43 http://www.supercoatsale.com/canada-goose-duvetica

I really enjoy looking through on this web site, it contains fantastic articles. "Beware lest in your anxiety to avoid war you obtain a master." by Demosthenes.
Women's Duvetica Coats http://www.supercoatsale.com/canada-goose-duvetica-womens-duvetica-coats-c-13_16.html

# bags mulberry 2012/11/04 4:42 http://www.bagmulberryuk.co.uk

Simply wanna remark on few general things, The website style is perfect, the written content is very fantastic : D.
bags mulberry http://www.bagmulberryuk.co.uk

# mulberry bag 2012/11/04 4:42 http://www.mulberrybagukoutlet.co.uk

Some genuinely wonderful info , Gladiolus I noticed this. "True success is overcoming the fear of being unsuccessful." by Paul Sweeney.
mulberry bag http://www.mulberrybagukoutlet.co.uk

# mulberry bags 2012/11/04 4:43 http://www.bagmulberry.co.uk

I got what you intend, regards for putting up.Woh I am happy to find this website through google. "Delay is preferable to error." by Thomas Jefferson.
mulberry bags http://www.bagmulberry.co.uk

# mulberry uk 2012/11/04 4:44 http://www.outletmulberryuk.co.uk

fantastic issues altogether, you just received brand new|a new} reader. What may you recommend in regards to your publish that you simply made a few days ago? Any certain?
mulberry uk http://www.outletmulberryuk.co.uk

# burberry 2012/11/05 6:03 http://www.burberryoutletlocations.com

Absolutely composed subject matter, thankyou for entropy.
burberry http://www.burberryoutletlocations.com

# burberry sale 2012/11/05 6:03 http://www.burberrysalehandbags.com

You are my intake , I own few web logs and very sporadically run out from to brand.
burberry sale http://www.burberrysalehandbags.com

# burberry scarf 2012/11/05 6:03 http://www.burberryoutlethandbags.com/accessories/

I'll right away snatch your rss as I can not in finding your e-mail subscription hyperlink or e-newsletter service. Do you have any? Kindly let me recognise in order that I could subscribe. Thanks.
burberry scarf http://www.burberryoutlethandbags.com/accessories/burberry-scarf.html

# scarf 2012/11/05 6:03 http://www.burberrysalehandbags.com/burberry-scarf

Utterly composed written content, regards for information. "The last time I saw him he was walking down Lover's Lane holding his own hand." by Fred Allen.
scarf http://www.burberrysalehandbags.com/burberry-scarf.html

# burberry scarf 2012/11/05 6:03 http://www.burberryoutletscarfsale.com/accessories

I like this post, enjoyed this one thanks for posting .
burberry scarf http://www.burberryoutletscarfsale.com/accessories/burberry-scarf.html

# scarf 2012/11/05 6:03 http://www.burberryoutletonlineshopping.com/burber

Somebody essentially help to make significantly posts I might state. This is the first time I frequented your website page and so far? I amazed with the analysis you made to make this particular publish amazing. Great activity!
scarf http://www.burberryoutletonlineshopping.com/burberry-scarf.html

# 偽物 2017/06/22 18:29 jvrgrofag@ezweb.ne.jp

革新的で優雅な超歓迎店舗超特価!
『激安価格』本物保証!
【正規品】激安専門店.
エルメス新作超特価SALE!
市場!
【最安値開催中】全品無料!
セット組み合わせ!
100%新品!
割引【超特価】信用第一!
【大特価!】100%本物保証!
2017【品質保証書】全国送料無料!
限定SALE手ごろなお値段!
【限定特価】史上最も激安い!
専門店【新入荷】
激安通販,配送のアイテムは返品送料無料
偽物 http://www.ginza66.com

# 激安コピーブランド 2017/10/28 15:44 untrkupgzfr@softbank.jp

大変迅速丁寧な対応で、とても良い買い物が出来ました。
商品も美品で梱包もとても丁寧でしたので、機会が有りましたらまた利用したいショップの一つです。
激安コピーブランド http://www.msnwatchs.com

# ブランド コピー 2017/10/29 5:16 pmihqzwivza@excite.co.jp

お盆期間中という事で手元に届くまで少し時間を要した点が...とは思いますが、商品の程度は商品詳細通りでした。梱包などしっかりしていてきちんとした対応をしていただける雰囲気を感じる良心的なお店だと感じました。
【送料無料】コーチ 時計をセール価格で販売中♪コーチ 時計 シグネチャー レキシントン シルバーダイアル ステンレススチール クォーツ レディース 新品 ウォッチ COACH
多少の小キズ、使用感はありましたが、良品でした。
ブランド コピー http://www.yamamo78.com/web/louis-b001.htm

# ルイヴィトンショルダーコピー 2017/12/25 6:01 ooiiyno@hotmail.co.jp

時計,バッグ,財布,ルイヴィトンコピー,エルメスコピー
弊店に主要な販売する商品は時計,バッグ,財布,ルイヴィトンコピー,エルメスコピー,
シャネルコピー,グッチコピー,プラダコピー,ロレックスコピー,カルティエコピー,オメガコピー,
ウブロ コピーなどの世界にプランド商品です。
2006年に弊社が設立された、
弊社は自社製品を世界中に販売して、高品質な製品と優れたアフターサービスで、

# ウブロコピー 2019/02/20 9:58 xiuvdnvgqw@excite.co.jp

ルイヴィトン - N級バッグ、財布 専門サイト問屋
弊社は販売ルイ・ヴィトン) バッグ、財布、 小物類などでございます。
弊社は「信用第一」をモットーにお客様にご満足頂けるよう、
送料は無料です(日本全国)! ご注文を期待しています!
下記の連絡先までお問い合わせください。
是非ご覧ください!
激安、安心、安全にお届けします.品数豊富な商
商品数も大幅に増え、品質も大自信です
100%品質保証!満足保障!リピーター率100%!

タイトル
名前
Url
コメント