<?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>Welcome to XP Link Co., Ltd. &#187; Tapestry</title>
	<atom:link href="http://www.xp-link.com/category/tapestry/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xp-link.com</link>
	<description>XP Link Co., Ltd is a software consultant company specializes in Java Technology from Thailand.</description>
	<lastBuildDate>Tue, 10 Jan 2012 09:11:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>การใช้งาน Tapesty ร่วมกับ Spring Framework</title>
		<link>http://www.xp-link.com/2007/08/03/using_tapestry_with_spring/</link>
		<comments>http://www.xp-link.com/2007/08/03/using_tapestry_with_spring/#comments</comments>
		<pubDate>Fri, 03 Aug 2007 07:35:37 +0000</pubDate>
		<dc:creator>nuttarut</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[Tapestry]]></category>

		<guid isPermaLink="false">http://www.xp-link.com/2007/08/03/%e0%b8%81%e0%b8%b2%e0%b8%a3%e0%b9%83%e0%b8%8a%e0%b9%89%e0%b8%87%e0%b8%b2%e0%b8%99-tapesty-%e0%b8%a3%e0%b9%88%e0%b8%a7%e0%b8%a1%e0%b8%81%e0%b8%b1%e0%b8%9a-spring-framework/</guid>
		<description><![CDATA[&#160;&#160;&#160;Tapestry เป็นเฟรมเวิร์คสำหรับพัฒนาเว็บแอพพลิเคชั่นด้วยจาวาที่มีประสิทธิภาพมากเฟรมเวิร์คหนึ่ง ด้วยการทำงานในรูปแบบ Component-Centric ที่มีความสามารถหลักๆคือทำให้เราสามารถนำโค๊ดเก่ามาใช้ใหม่ได้ ง่าย และยังมี HiveMind ที่ทำให้สามารถใช้แนวคิด Inversion of Control (IoC)ในการพัฒนาได้อีกด้วย &#160;&#160;&#160;แต่การพัฒนาแอพพลิเคชั่นด้วยแนวคิดแบบ IoC ในปัจจุบันนั้น การใช้ Spring Framework จะเป็นที่นิยมแพร่หลายมากกว่า ฉะนั้นถ้าเราสามารถนำ Spring Framework มาใช้งานร่วมกับ Tapestry ได้ ก็จะเป็นประโยชน์มากทีเดียว &#160;&#160;&#160;โชคดีที่ทั้ง Spring Framework และ Tapestry นั้นมีสถาปัตยกรรมที่ค่อนข้างจะยืดหยุ่น ทำให้การนำเฟรมเวิร์คอื่นๆมาใช้งานร่วมด้วยนั้นสามารถทำได้ง่าย และมีประสิทธิภาพ โดยการนำ Spring Framework และ Tapestry มาใช้งานร่วมกันสามารถทำได้ดังนี้ การ config web.xml &#160;&#160;&#160;ก่อนอื่นเราจะต้องทำให้เว็บแอพลิเคชั่นที่พัฒนาด้วย Tapestryของเรานั้นหาไฟล์ config ของ Spring ให้เจอเสียก่อนโดยใช้ listener ที่ชื่อ ContextLoaderListener โดยทำการเพิ่ม config [...]]]></description>
			<content:encoded><![CDATA[<p><!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	-->             &nbsp;&nbsp;&nbsp;<a href="http://tapestry.apache.org/">Tapestry</a> เป็นเฟรมเวิร์คสำหรับพัฒนาเว็บแอพพลิเคชั่นด้วยจาวาที่มีประสิทธิภาพมากเฟรมเวิร์คหนึ่ง ด้วยการทำงานในรูปแบบ  Component-Centric ที่มีความสามารถหลักๆคือทำให้เราสามารถนำโค๊ดเก่ามาใช้ใหม่ได้ ง่าย และยังมี <a href="http://hivemind.apache.org/">HiveMind</a> ที่ทำให้สามารถใช้แนวคิด Inversion of Control (IoC)ในการพัฒนาได้อีกด้วย<br />
<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	-->   &nbsp;&nbsp;&nbsp;แต่การพัฒนาแอพพลิเคชั่นด้วยแนวคิดแบบ IoC ในปัจจุบันนั้น การใช้ <a href="http://www.springframework.org/">Spring Framework</a> จะเป็นที่นิยมแพร่หลายมากกว่า  ฉะนั้นถ้าเราสามารถนำ Spring Framework มาใช้งานร่วมกับ Tapestry ได้ ก็จะเป็นประโยชน์มากทีเดียว<br />
<br /><span id="more-29"></span><br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--></p>
<p>&nbsp;&nbsp;&nbsp;โชคดีที่ทั้ง Spring Framework และ Tapestry นั้นมีสถาปัตยกรรมที่ค่อนข้างจะยืดหยุ่น ทำให้การนำเฟรมเวิร์คอื่นๆมาใช้งานร่วมด้วยนั้นสามารถทำได้ง่าย และมีประสิทธิภาพ โดยการนำ Spring Framework และ Tapestry มาใช้งานร่วมกันสามารถทำได้ดังนี้<br />
</p>
<h4>การ config web.xml</h4>
<p>&nbsp;&nbsp;&nbsp;ก่อนอื่นเราจะต้องทำให้เว็บแอพลิเคชั่นที่พัฒนาด้วย Tapestryของเรานั้นหาไฟล์ config ของ Spring ให้เจอเสียก่อนโดยใช้ listener ที่ชื่อ ContextLoaderListener โดยทำการเพิ่ม config ใน web.xml ดังนี้<br />
<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--></p>
<pre class="code">
&lt;listener&gt;
    	&lt;listener-class&gt;
                 org.springframework.web.context.ContextLoaderListener
        &lt;/listener-class&gt;
&lt;/listener&gt;
</pre>
<p>
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--></p>
<p>
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
&nbsp;&nbsp;&nbsp;ในส่วนต่อไปจะเป็นการทำให้ ContextLoaderListener ทราบว่าจะเข้าไปหาไฟล์ config ของ Spring ได้ที่ไหน ถ้าไม่มีการกำหนดในส่วนนี้ไว้ ContextLoaderListener  จะเข้าไปหาใน /WEB-INF/applicationContext.xml แทน</p>
<p>
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--></p>
<pre class="code">
&lt;context-param&gt;
    	&lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
    	&lt;param-value&gt;/WEB-INF/applicationContext*.xml&lt;/param-value&gt;
&lt;/context-param&gt;
</pre>
<h4>การใช้ Dependency Injection เพื่อเรียกใช้ Spring Bean</h4>
<p>&nbsp;&nbsp;&nbsp;เรามาสารถเรียกใช้ Spring Bean จาก page object ของ Tapestry ได้โดยตรงเช่น<br />
<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--></p>
<pre class="code">
WebApplicationContext appContext = WebApplicationContextUtils.getApplicationContext(
    getRequestCycle().getRequestContext().getServlet().getServletContext());
SomeService someService = (SomeService) appContext.getBean("someService");
</pre>
<p><!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
<br />
&nbsp;&nbsp;&nbsp;แต่การทำแบบนี้จะทำให้แก้ไขลำบากในภายหลัง เพราะเราจะต้องแก้ทุก page object ที่เรียกใช้ Spring Bean และถึงแม้เราจะใช้รูปแบบการเขียนโค๊ดต่างๆ ที่จะสะดวกในการแก้ไขแล้วก็ตาม ตัว Servlet เองก็ไม่ควรเรียกใช้ Application Context โดยตรง หรือรู้ว่าถูกสร้างมาได้อย่างไร ตามหลักของ IoC<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
<br />
&nbsp;&nbsp;&nbsp;เราสามารถแก้ปัญหานี้ได้โดยใช้ไลบราลีที่ชื่อ <a href="http://sourceforge.net/projects/diaphragma">Tapestry-Spring</a> ซึ่งจะใช้ Annotation @InjectObject แทนการเรียกใช้แบบเดิมที่กล่าวไว้ข้างต้น ทำให้เราเรียกใช้ Spring Beanได้ง่ายและยืดหยุ่นมากยิ่งขึ้น โดยให้ทำการดาวน์โหลดไฟล์ไลบราลีมาใส่ไว้ร่วมกับไลบราลีอื่นๆ ที่เราใช้ในเว็บแอพพลิเคชั่น (ปกติจะเป็น /WEB-INF/lib) และทำการเรียกใช้ใน page object ดังนี้<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
</p>
<pre class="code">
@InjectObject("spring:someService")
public abstract SomeService getSomeService();
</pre>
<p><!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
<br />
&nbsp;&nbsp;&nbsp;สำหรับระบบที่ไม่ได้ใช้ Java5 จะต้องทำการเรียกใช้ Spring Bean ผ่านไฟล์ .page หรือ .jwc ของหน้าเว็บนั้นๆแทนดังนี้<br />
<!-- 		@page { size: 8.5in 11in; margin: 0.79in } 		P { margin-bottom: 0.08in } 	--><br />
</p>
<pre class="code">
&lt;inject property="someService" object="spring:someService"/&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.xp-link.com/2007/08/03/using_tapestry_with_spring/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

