JSFとStruts

目次

目的

個人的には、今の開発現場がstruts1を使っているっていう事情があるので、struts1中心にしらべています。

開発の最短の手順の調査として、JSFの表作製を使った場合のメンテナンス性について考察することに留意しながらまとめております。

StrutsとJSFを統合するライブラリ「Struts-faces」

本家

http://struts.apache.org/1.x/struts-faces/

本体のダウンロード

http://struts.apache.org/download.cgi

struts1の取説

http://struts.apache.org/1.x/userGuide/index.html

struts2は別物であるという意見

http://d.hatena.ne.jp/ryoasai/20101014/1287063322

サンプルコード

下記のURLでサンプルが紹介されている http://struts.apache.org/1.x/struts-apps/index.html

Faces Example 1

Struts の古典的なメールリーダのrenditionでJSFが使えるようになっている。

Faces Example 2

さらにTilesも使っているのが、Example2である。

キャッシュに残らないように

開発時にキャッシュに残っていると、原因の特定を妨げるケースが多々ある 下記のようにキャッシュをためないように実装する必要がある。 ただし、開発時のみ

<% 
response.setHeader("Pragma","no-cache"); 
response.setHeader("Cache-Control","no-cache"); 
response.addHeader("Cache-Control","no-store"); 
response.setDateHeader("Expires",0); 
%> 

XMLを出力

%@ page language="java" contentType="text/xml; charset=UTF-8" %>

%@ page language="java" contentType="application/xml; charset=UTF-8" %>

?xml version="1.0" encoding="UTF-8"?>

JavascriptでXMLをリクエスト

XMLHttpRequest?を生成する

http://www.gesource.jp/programming/javascript/20060501.html

リクエストを送信してXMLを受信する

http://www.gesource.jp/programming/javascript/20060507.html

JQueryでリクエストを送信

http://allabout.co.jp/gm/gc/24214/

xxxtagligb.tldのタグ定義を作る

サンプルを見ると中身はXMLで記述された定義ファイルである。このファイルをJSPが呼んでいて、このファイルから、Classが呼ばれている。という仕組みらしい。

   <tag>
	<description>Outputs Hello, World</description>
       <name>helloWorld</name>
	<tag-class>jsp2.examples.simpletag.HelloWorldSimpleTag</tag-class>
	<body-content>empty</body-content>
   </tag>

タグクラスを作る

public class HelloWorldSimpleTag extends SimpleTagSupport {
   public void doTag() throws JspException, IOException {
	getJspContext().getOut().write( "Hello, world!" );
   }
}

タグをJSPで使う

<%@ taglib prefix="mytag" uri="/WEB-INF/jsp2/jsp2-example-taglib.tld" %>
<mytag:helloWorld/>
トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS