<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jiramot.info &#187; sitemesh</title>
	<atom:link href="http://www.jiramot.info/tag/sitemesh/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jiramot.info</link>
	<description>me?.note.each{ println it }</description>
	<lastBuildDate>Fri, 30 Jul 2010 19:57:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple sitemesh tutorial</title>
		<link>http://www.jiramot.info/simple-sitemesh-totorial</link>
		<comments>http://www.jiramot.info/simple-sitemesh-totorial#comments</comments>
		<pubDate>Fri, 19 Dec 2008 09:58:41 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[sitemesh]]></category>

		<guid isPermaLink="false">http://www.jiramot.info/?p=150</guid>
		<description><![CDATA[Sitemesh ถ้าพูดง่ายๆก็คือ Template Engine ของภาษา Java นั่นเอง โดยหากย้อนกลับไปก่อนหน้านิด หลายๆคนอาจจะรู้จัก Velocity, FreeMaker เป็นต้น หรือว่าเอาให้ง่ายที่สุด sitemesh ก็คือ master page นั่นเอง เอาไว้ทำ layout ของเวปไซต์ของเรา โดยหลักการทำงาน สามารถดูจาก sitemesh

ตัวอย่างนี้จะเป็นการลองใช้ sitemesh กับ jsp
1. เริ่มต้นจากการ ดาวโหลด sitemesh จากนั้นทำการเพิ่ม .jar เข้าไปในไฟล์เดอร์ WEB-INF/lib
2. ทำการเพิ่ม sitemesh filter ในไฟล์ web.xml

1
2
3
4
5
6
7
8
9
10
  &#60;filter&#62;
    &#60;filter-name&#62;sitemesh&#60;/filter-name&#62;
    &#60;filter-class&#62;
      com.opensymphony.module.sitemesh.filter.PageFilter
 [...]]]></description>
			<content:encoded><![CDATA[<p>Sitemesh ถ้าพูดง่ายๆก็คือ Template Engine ของภาษา Java นั่นเอง โดยหากย้อนกลับไปก่อนหน้านิด หลายๆคนอาจจะรู้จัก <a href="http://jakarta.apache.org/velocity/">Velocity</a>, <a href="http://www.freemarker.org/index.html">FreeMaker</a> เป็นต้น หรือว่าเอาให้ง่ายที่สุด sitemesh ก็คือ master page นั่นเอง เอาไว้ทำ layout ของเวปไซต์ของเรา โดยหลักการทำงาน สามารถดูจาก <a href="http://www.jiramot.info/?p=46">sitemesh</a><br />
<span id="more-150"></span><br />
ตัวอย่างนี้จะเป็นการลองใช้ sitemesh กับ jsp<br />
1. เริ่มต้นจากการ <a href="http://www.opensymphony.com/sitemesh/download.action">ดาวโหลด </a>sitemesh จากนั้นทำการเพิ่ม .jar เข้าไปในไฟล์เดอร์ WEB-INF/lib<br />
2. ทำการเพิ่ม sitemesh filter ในไฟล์ web.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>sitemesh<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
      com.opensymphony.module.sitemesh.filter.PageFilter
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>sitemesh<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/filter-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>3. สร้างไฟล์ decorators.xml ไว้ที่ /WEB-INF/decorators.xml</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;decorators</span> <span style="color: #000066;">defaultdir</span>=<span style="color: #ff0000;">&quot;/WEB-INF/decorators&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;decorator</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;main&quot;</span> <span style="color: #000066;">page</span>=<span style="color: #ff0000;">&quot;main.jsp&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/*.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/decorator<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;decorators<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>ดังตัวอย่างนี้ เราจะสร้างไฟล์ decorator ชื่อว่า main.jsp เก็บไว้ยังโฟล์เดอร์ WEB-INF/decorators/ โดยจะใช้ไฟล์นี้เป็นตัวกำหนด layout ของทุกไฟล์ที่มีนามสกุลเป็น .jsp<br />
แต่หากว่าเราต้องการระบุเป็นเฉพาะไฟล์ไป สามารถทำได้โดยการเปลี่ยนเป็น</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/index.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/home.jsp<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>4. จากนั้นจะทำการสร้างไฟล์ main.jsp ไว้ที่ WEB-INF/decorators/ เพื่อเป็นไฟล์ที่กำหนด layout ของเรา</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;head&gt;
  &lt;title&gt;
    Lumidant.com - &lt;decorator:title default=&quot;SiteMesh Tutorial Example&quot; /&gt;
  &lt;/title&gt;
  &lt;style type=&quot;text/css&quot;&gt;@import &quot;css/global.css&quot;;&lt;/style&gt;
  &lt;decorator:head /&gt;
  &lt;body&gt;
    &lt;div id=&quot;header&quot;&gt;
      &lt;h2&gt;&lt;a href=&quot;http://www.lumidant.com/&quot;&gt;Lumidant.com&lt;/a&gt; Tutorials&lt;/h2&gt;
    &lt;/div&gt;
    &lt;div id=&quot;content&quot;&gt;
      &lt;decorator:body /&gt;
    &lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;</pre></div></div>

<p>ทำการสร้างไฟล์ main.jsp เพื่อเป็น layout ของเวป พร้อมทั้งใส่ <decorator:body /> เข้าไปในส่วนที่ต้องการนำไฟล์หลักเข้ามา mesh ลงใน template </p>
<p>ผลการทำงาน ฝั่ง server เมื่อได้รับ request จะทำการประมวลผล หน้าหลัก จากนั้นจะนำ code ส่วนของ body ของหน้าหลักมา แทนที่ <decorator:body /> ในไฟล์ template แล้วจึง return respanse กลับไปยัง web browser ของฝั่ง client</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jiramot.info/simple-sitemesh-totorial/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introduction to SiteMesh</title>
		<link>http://www.jiramot.info/introduction-to-sitemesh</link>
		<comments>http://www.jiramot.info/introduction-to-sitemesh#comments</comments>
		<pubDate>Fri, 14 Nov 2008 05:03:33 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Article]]></category>
		<category><![CDATA[sitemesh]]></category>

		<guid isPermaLink="false">http://www.jiramot.info/?p=46</guid>
		<description><![CDATA[เนื่องจากช่วงนี้กำลังศึกษาเจ้า Grails ซึ่งเป็น Web framework คล้ายๆ Rails โดยใช้ภาษา Script ที่ชื่อว่า Groovy ซึ่งเจ้า Groovy เองก็เป็นภาษาที่รันอยู่บน runtime ของ java ทำให้เราสามารถเขียนได้ทั้ง Java หรือ Groovy ได้ตามแต่ถนัด โดยมีข้อดีเหมือนกับภาษา Script ในลักษณะใหม่ๆ ทั่วไป ซึ่งผมจะขอเก็บไว้พูดคราวหลัง
โดย Grails ได้รวม Sitemesh ซึ่งเอาไว้เป็นส่วนหนึ่ง โดยทำหน้าที่จัดการ layout ของหน้าตาเวป โดยมีการทำงานดังนี้


Normal Page Rendering
โดยปกติแล้วการทำงานของ Browser เริ่มต้นจากการส่ง Request ไปยัง Web Server, จากนั้น Web Server จะส่งหน้าเวปเพจที่ Render แล้วกลับไป, Browser จะทำการแสดงผล



SiteMesh Page Rendering
หากใช้ SiteMesh จะต่างกันตรงที่ [...]]]></description>
			<content:encoded><![CDATA[<p>เนื่องจากช่วงนี้กำลังศึกษาเจ้า Grails ซึ่งเป็น Web framework คล้ายๆ Rails โดยใช้ภาษา Script ที่ชื่อว่า Groovy ซึ่งเจ้า Groovy เองก็เป็นภาษาที่รันอยู่บน runtime ของ java ทำให้เราสามารถเขียนได้ทั้ง Java หรือ Groovy ได้ตามแต่ถนัด โดยมีข้อดีเหมือนกับภาษา Script ในลักษณะใหม่ๆ ทั่วไป ซึ่งผมจะขอเก็บไว้พูดคราวหลัง</p>
<p>โดย Grails ได้รวม Sitemesh ซึ่งเอาไว้เป็นส่วนหนึ่ง โดยทำหน้าที่จัดการ layout ของหน้าตาเวป โดยมีการทำงานดังนี้</p>
<div style="text-align: center;">
<div class="imageframe centered" style="width: 500px;"><a title="Normal Page Rendering" rel="lightbox[pics46]" href="http://www.jiramot.info/wp-content/uploads/2008/11/sitemesh_fig1.gif"><img class="attachment wp-att-47" src="http://www.jiramot.info/wp-content/uploads/2008/11/sitemesh_fig1.gif" alt="Normal Page Rendering" width="500" height="189" /></a></p>
<div class="imagecaption">Normal Page Rendering</div>
<div class="imagecaption" style="text-align: left;">โดยปกติแล้วการทำงานของ Browser เริ่มต้นจากการส่ง Request ไปยัง Web Server, จากนั้น Web Server จะส่งหน้าเวปเพจที่ Render แล้วกลับไป, Browser จะทำการแสดงผล</div>
<div class="imagecaption" style="text-align: left;">
<div style="text-align: center;">
<div class="imageframe centered" style="width: 500px;"><a title="SiteMesh Page Rendering" rel="lightbox[pics46]" href="http://www.jiramot.info/wp-content/uploads/2008/11/sitemesh_fig2.gif"><img class="attachment wp-att-48" src="http://www.jiramot.info/wp-content/uploads/2008/11/sitemesh_fig2.gif" alt="SiteMesh Page Rendering" width="500" height="189" /></a></p>
<div class="imagecaption">SiteMesh Page Rendering</div>
<div class="imagecaption" style="text-align: left;">หากใช้ SiteMesh จะต่างกันตรงที่ เมื่อ Web Server ทำการ Render เพจเสร็จแล้ว เจ้า SiteMesh จะทำการเพิ่มข้อมูลลงในเพจ จากนั้นจะส่งกลับไปยัง Browser</div>
</div>
</div>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.jiramot.info/introduction-to-sitemesh/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
