Shale Clay Plugin その2
前回,簡単にサンプルを動かすところまで終了しました.
設定ファイルが多いですね...
web.xml
Clayを使用するために,web.xmlに以下の設定をしました.
<!-- Clay Common Configuration Resources --> <context-param> <param-name> org.apache.shale.clay.COMMON_CONFIG_FILES </param-name> <param-value>/WEB-INF/clay-config.xml</param-value> </context-param> <!-- Clay Configuration Listener --> <listener> <listener-class> org.apache.shale.clay.config.ClayConfigureListener </listener-class> </listener> <!-- JavaServer Faces Servlet Mapping for Clay HTML Full View --> <servlet-mapping> <servlet-name>faces</servlet-name> <url-pattern>*.html</url-pattern> </servlet-mapping>
org.apache.shale.clay.COMMON_CONFIG_FILES
Clayの設定ファイルを指定します.
複数ある場合は,カンマで指定します.
以前は,clay-config-filesというパラメータで指定していましたが,
現在はdeprecatedとなっており,COMMON_CONFIG_FILESを使用するのが推奨とされているようです.
org.apache.shale.clay.config.ClayConfigureListener
コンテキストの起動時,終了時に処理を行うListenerです.
各種設定の適用を行っています.
<context-param> <param-name>org.apache.shale.clay.HTML_TEMPLATE_SUFFIX</param-name> <param-value>.xhtml</param-value> </context-param>
web.xmlに上記の設定を行うと,テンプレートのサフィックスを設定することが出来ます.
上記の例では,テンプレートのサフィックスに'.xhtml'を適用しています.
HTML_TEMPLATE_SUFFIXの設定を行わないと,ディフォルトで'.html'が設定されます.
最後にservlet-mappingによって,'.html'を処理させます.
上記設定は,Shale FrameworkのHPにも設定が載っていますが,間違っていますので...
faces-config.xml
faces-config.xmlは,通常のJSFと同様の記述をします.
managed-bean要素でバッキングビーンを登録します.
navigation-rule要素でページナビゲーションを設定します.
chain-config.xml
<!-- This command is only needed for full clay html views with myfaces --> <command className="org.apache.shale.clay.faces.ClayViewHandlerCommand" />
HTML Viewや,XML Viewを使用する際,上記の設定が必要となります.
<!-- This filter command wakes up the watchdog monitoring the Clay configuration files for change. --> <command className="org.apache.shale.clay.config.beans.ConfigDefinitionsWatchdogFilter" includes="\S*\.faces,\S*\.html,/index\.jsp,\S*\.xml" />
上記の設定を行うと,ファイルの修正や変更を即時に反映します.
clay-config.xml
Clayのコンポーネントを定義します.
<component jsfid="name" extends="outputText" allowBody="false"> <attributes> <set name="value" value="#{@managed-bean-name.name}" /> </attributes> </component>
上記の例では,'name'という名前で登録しています.
extends属性でClayコンポーネントの'outputText'を継承しています.
'outputText'は,Clayの定義で,以下のように定義されています.
<component jsfid="outputText" componentType="javax.faces.HtmlOutputText" extends="baseHtml"> <description>Render readonly text.</description> <attributes> <set name="value" bindingType="VB"> <description></description> </set> <set name="escape" bindingType="VB"> <description></description> </set> </attributes> </component>
@managed-bean-name
は,Clayによって,自動的に差し替えられます.
@managed-bean-nameは,faces-config.xmlのmanaged-bean-name要素にマッピングされます.
例えば,'/hello.html'なら,'html'を取り除いた物が探しだされます.'/sample/hoge.html'なら,'sample$hoge'にマッピングされます.
このルールは,また今度説明します.(Shale View Controllerにも関連があります)
前回例に挙げたhello.htmlの上記コンポーネントは,以下のようにも書くことが出来ます.
<span jsfid="name">sample</span>
↓
<span id="outName" jsfid="outputText" allowBody="false" value="#{@managed-bean-name.name}">sample</span>
この際,clay-config.xmlは記述する必要がありません.
html
HTML テンプレートについて説明します.
HTML Viewを使用する際に,以下の要素については'jsfid'をつけなくても,Clayが勝手に置き換えてくれます.
・<a></a> ・<form></form> ・<input type=text> ・<input type=checkbox> ・<input type=radio> ・<input type=submit> ・<label></label> ・<select></select> ・<select multiple></select> ・<option> ・<textarea></textarea>
これ以外の要素に関しては,Clayのコンポーネントに置き換える際に'jsfid'が必要になります.
次回は,もう少しClayコンポーネントを使ってみます.