DWR (Direct Web Remoting)
DWR (Direct Web Remoting)
- DWRÀº Direct Web Remoting ÀÇ ¾àÀڷμ ajax¸¦ ±â¹ÝÀ¸·Î ÇÏ¿© client side ÀÇ javascript ·Î server side ÀÇ Java BeansÀ» interactiveÇÏ°Ô Á¶ÀÛÇÒ ¼ö ÀÖ´Â framework ÀÔ´Ï´Ù.
- ÇöÀç stable version Àº 1.1 ÀÌ°í dwr.dev.java.net ¿¡¼ development versionÀÎ 2.0 ¼Ò½º¸¦ checkout ÇÒ ¼ö ÀÖ½À´Ï´Ù. ƯÈ÷ 2.0 ¿¡¼´Â rajax (reverse ajax)¶ó´Â °³³äÀ¸·Î ¿ªÀ¸·Î Java Beans¿¡¼ client side ÀÇ javascript¸¦ Á¶ÀÛ°¡´ÉÇϵµ·Ï ±¸ÇöµÇ¾î ÀÖ½À´Ï´Ù.
- ¶ÇÇÑ Struts, Spring, Webwork, JSF µî web framwork ¿ÍÀÇ ¿¬µ¿À» À§ÇÑ libraries ¸¦ Á¦°øÇÏ°í ÀÖ½À´Ï´Ù.
- Å×½ºÆ®¸¦ À§ÇÑ sample ¼Ò½º¸¦ 82¼¹öÀÇ °³¹ßcvs repository ¿¡ 'dwr_ex' module ·Î µî·ÏµÇ¾î ÀÖÀ¸¹Ç·Î checkout ¹Þ¾Æ Å×½ºÆ®ÇÒ ¼ö ÀÖ½À´Ï´Ù.
- °³¹ßÀÚÀÎ Joe Walker°¡ ¿î¿µÁßÀÎ »çÀÌÆ® http://getahead.ltd.uk/dwr/ ¿¡¼ online manual°ú ¸¹Àº Á¤º¸¸¦ ±¸ÇÒ ¼ö ÀÖ½À´Ï´Ù.
DWR Architecture
- DWRÀº ajax ¿Í °áÇÕµÈ Client side, DWRServlet, Server side JavaBeans ¸¦ °¡Áö´Â MVCÆÐÅÏ°ú À¯»çÇÑ ±¸Á¶ÀÔ´Ï´Ù. ÀÌ´Â Javascript ·Î DWREngine(ajax engine)À» ÅëÇØ view page °»½Å¾øÀÌ ½Ç½Ã°£ ¼ºñ½º¸¦ È£ÃâÇÏ¿© dhtml·Î ȸéÀ» Á¶ÀÛÇÒ ¼ö ÀÖ´Â ±â´ÉÀ» Á¦°øÇÕ´Ï´Ù.
- Client side ÀÎ view page´Â javascript + html ¸¸À¸·Îµµ ÃæºÐÈ÷ °³¹ß°¡´ÉÇϳª ÆäÀÌÁö ·Îµù ½Ã ¼¹ö¿¡¼ °¡Á®¿Â µ¥ÀÌÅ͸¦ ¸®½ºÆ® ¶Ç´Â »ó¼¼³»¿ªÀ¸·Î º¸¿©ÁÖ¾î¾ß ÇÒ ¶§´Â JSP ÆäÀÌÁö¸¦ »ç¿ëÇÏ¿©¾ß ÇÕ´Ï´Ù.
- DWRServletÀÇ °æ¿ì controller ÀÇ ¿ªÇҷνá /dwr/engine.js, /dwr/util.js, /dwr/interface/TestObject.js ÀÇ ¿äûÀÌ µé¾î¿À¸é(uri-mapping) dwr.xml ¿¡ µî·ÏµÈ TestObjectÀ» ÂüÁ¶ÇÏ¿© Javascript¸¦ »ý¼ºÇØÁÖ´Â ¿ªÇÒÀ» ¼öÇàÇÕ´Ï´Ù.
- JavaBeanÀÎ TestObjectÀÇ °æ¿ì Business LayerÀÇ component¸¦ »ý¼ºÇÏ¿© ¼ºñ½º¸¦ È£ÃâÇÒ ¼ö ÀÖ´Â ¸Þ¼Òµå¸¦ Javascript ¿¡¼ »ç¿ëÇÒ ¼ö ÀÖµµ·Ï Á¦°øÇØÁÖ¾î¾ß ÇÕ´Ï´Ù.
- À§ ±×¸²¿¡ ´ëÇÑ ¼³¸íÀº ´ÙÀ½°ú °°½À´Ï´Ù.
- 1] Init ¼öÇà
ÆäÀÌÁö ·Îµù ½Ã /dwr/engine.js, /dwr/util.js, /dwr/interface/TestObject.js ÀÇ ¿äûÀÌ µé¾î¿À¸é DWRServletÀº dwr.xml¸¦ ·ÎµùÇÏ¿© TestObject ¿¡ ´ëÇÑ ¸Þ¼Òµå¸¦ Javascript·Î È£ÃâÇÒ ¼ö ÀÖµµ·Ï »ý¼ºÇØ ÁÝ´Ï´Ù. À̷νá TestObject¸¦ Javascript¿¡¼ Á¶ÀÛ°¡´ÉÇÏ°Ô µË´Ï´Ù.
- 2] call method ¼öÇà
Init ¼öÇà ÈÄ TestObject.getList() È£Ã⠽à DWREngine À» È£ÃâÇÏ¿© ¼¹öÂÊ TestObject JavaBeanÀÇ getList() ¸Þ¼Òµå¸¦ È£ÃâÇÏ°Ô µË´Ï´Ù. ¸¸¾à getList() ¸Þ¼Òµå¿¡ return value°¡ Á¸ÀçÇÑ´Ù¸é callback function À» ´ÙÀ½°ú °°ÀÌ Á¤ÀÇÇÏ¿©¾ß ÇÕ´Ï´Ù.
1] callback function ºÐ¸® : // TestObject ÀÇ getList() ¸Þ¼Òµå È£Ãâ. TestObject.getList(getListCallback); function getListCallback(data) { // returned value ó¸® }; 2] anonymous function À¸·Î ±¸Çö : // TestObject ÀÇ getList() ¸Þ¼Òµå È£Ãâ. TestObject.getList( { callback : function(data) { // returned value ó¸® }, errorHandler : function(message, exception) { // server message, error ó¸® } });
- À§¿Í °°ÀÌ call method ÀÌÈÄ returned value ¼Õ½±°Ô combo box ¹× table¿¡ ÀÚµ¿ ¼ÂÆÃÇÒ¼ö ÀÖµµ·Ï util.js ³»¿¡ DWRUtil À» Á¦°øÇÕ´Ï´Ù.
dwr libraries ¼³Ä¡
- dwr ¶óÀ̺귯¸®´Â dwr.jar ÇϳªÀ̸ç ÂüÁ¶ÇÏ´Â ¶óÀ̺귯¸®µµ ÇÔ²² ¼³Ä¡µÇ¾î¾ß ÇÕ´Ï´Ù.
- ÃÖ¼Ò ¼³Ä¡ libraries :
- dwr.jar : dwr core library
- bsf-2.3.jar : Bean Scripting Framework library ( http://jakarta.apache.org/bsf/index.html )
- bsh-2.0b4.jar : Bean Shell Framework library ( http://www.beanshell.org/ )
- commons-logging-1.0.4.jar : Jakarta Common Logging library ( http://jakarta.apache.org/commons/logging/ )
- commons-validator-1.1.4.jar : Jakarta Common Validator library ( http://jakarta.apache.org/commons/validator/ )
- jakarta-oro-2.0.8.jar : Jakarta ORO library ( http://jakarta.apache.org/oro/ )
- log4j-1.2.12.jar : log4j library ( http://logging.apache.org/log4j/docs/index.html )
- web framework ¿Í ¿¬µ¿Çϱâ À§ÇÑ ¼±ÅÃÀûÀÎ libraries :
- spring.jar : Spring Framework http://www.springframework.org/
- struts.jar : Struts Framework http://struts.apache.org/
- hibernate3.jar : hibernate Framework http://www.hibernate.org/
- webwork.jar : webwork Framework http://www.opensymphony.com/webwork/
- jsf-api.jar, jsf-impl.jar : JSF Framework http://java.sun.com/javaee/javaserverfaces/reference/docs/index.html
µîÀÌ ÇÊ¿äÇÕ´Ï´Ù.
DWRServlet ¼³Á¤ - web.xml
- dwr_ex ¸ðµâ ³» WebContent/WEB-INF/web.xml ¸¦ ÂüÁ¶ÇϽʽÿä.
- ±âº»ÀûÀÎ DWRServlet ¼³Á¤
<servlet> <servlet-name>dwr-invoker</servlet-name> <display-name>DWR Servlet</display-name> <description>Direct Web Remoter Servlet</description> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping>
- dwr.xml À» ¾÷¹«º°·Î ³ª´©¾î »ç¿ëÀÌ °¡´ÉÇÕ´Ï´Ù. http://getahead.ltd.uk/dwr/server/servlet/multiconfig À» ÂüÁ¶ÇϽʽÿä.
- dwr-user.xml, dwr-admin.xml µÎ°³ÀÇ ¼³Á¤ÆÄÀÏÀ» »ç¿ëÇÏ°íÀÚ ÇÏ´Â °æ¿ì DWRServlet À» dwr-user-invoker, dwr-admin-invoker µÎ °³ ¼³Á¤, °¢°¢ÀÇ dwr.xmlÀ» ¼³Á¤ÇÕ´Ï´Ù.
<servlet> <servlet-name>dwr-user-invoker</servlet-name> <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class> <init-param> <param-name>config-user</param-name> <param-value>WEB-INF/dwr-user.xml</param-value> </init-param> </servlet> <servlet> <servlet-name>dwr-admin-invoker</servlet-name> <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class> <init-param> <param-name>config-admin</param-name> <param-value>WEB-INF/dwr-admin.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr-admin-invoker</servlet-name> <url-pattern>/dwradmin/*</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>dwr-user-invoker</servlet-name> <url-pattern>/dwruser/*</url-pattern> </servlet-mapping>
dwr.xml ÀÛ¼º
- dwr.xml Àº Javascript ·Î Á¶ÀÛÇÒ Server side ÀÇ JavaBean À» ¼³Á¤ÇÏ´Â ÆÄÀÏ·Î½á ´ÙÀ½°ú °°Àº ³»¿ëµéÀ» ¼³Á¤ÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÚ¼¼ÇÑ ¼³¸íÀº http://getahead.ltd.uk/dwr/server/dwrxml À» ÂüÁ¶ÇϽʽÿä.
- dwr.xml¿¡ javascript °´Ã¼·Î Á¶ÀÛÇÒ JavaBean À» ¼³Á¤ÇÔ
- ÇØ´ç JavaBean¿¡ ´ëÇÑ Life scope ÁöÁ¤ÀÌ °¡´É (page, script, request, session, application)
- JavaBean¿¡¼ »ç¿ëÇؾßÇÒ ¸Þ¼Òµå filtering : include, exclude method ÁöÁ¤
- Value object(JavaBean) »ç¿ëÇϱâ À§ÇÑ °¢Á¾ converter Á¦°ø
- ajax ¿äûÀ» °¡·Îä´Â Filter ¼³Á¤
- ´ÙÀ½Àº DwrTestÀ» Javascript ¿¡¼ »ç¿ëÇϱâ À§ÇÑ ¼³Á¤ÀÔ´Ï´Ù.
- Foo °´Ã¼ÀÇ °æ¿ì updateFoo(Foo foo), deleteFoo(Foo foo) ¸Þ¼Òµå È£Ã⠽à ÆĶó¹ÌÅÍÀÇ Value Object ·Î½á »ç¿ëÇϱâ À§ÇØ bean converter ·Î ¼³Á¤µÇ¾î ÀÖÀ½
<dwr> <init> ... </init> <allow> ¡¦ <create creator="new" javascript="DwrTest" scope="request"> <param name="class" value="fullbox.dwr.test.DwrTest"/> </create> <convert match="fullbox.dwr.test.Foo" converter="bean"/> ¡¦ </allow> </dwr>
client page ÀÛ¼º
- client page ³»¿¡´Â ´ÙÀ½À» ¹Ýµå½Ã ÀÛ¼ºÇÏ¿©¾ß ÇÕ´Ï´Ù.
- DwrTest.js ´Â µ¿ÀûÀ¸·Î »ý¼ºµÇ´Â ½ºÅ©¸³Æ®·Î½á DwrTest °´Ã¼¸¦ Á¶ÀÛÇϱâ À§Çؼ´Â ¹Ýµå½Ã ¾Æ·¡¿Í °°ÀÌ ÀÛ¼ºÇØ ÁÖ¾î¾ß ÇÔ.
- engine.js ´Â DWREngine ÀÌ Á¤ÀÇµÈ ½ºÅ©¸³Æ®ÀÓ
- util.js ´Â DWRUtil ÀÌ Á¤ÀÇµÈ ½ºÅ©¸³Æ®ÀÓ
- example (dwr_ex.html ÂüÁ¶)
<html> <head> ... <script language="javascript" src="/dwr/interface/DwrTest.js"></script> <script language="javascript" src="/dwr/engine.js"></script> <script language="javascript" src="/dwr/util.js"></script> </head> <body> </body> </html>
dwr_ex ¸ðµâ Å×½ºÆ®
- 82¼¹ö °³¹ß cvs ¿¡¼ dwr_ex ¸ðµâÀ» checkout ¹Þ½À´Ï´Ù.
- tomcatÀÇ web context ·Î 'dwr_ex'¸¦ ¼³Á¤ÇÏ¿© tomcatÀ» ±âµ¿ÇÕ´Ï´Ù.
- eclipse wtp¸¦ »ç¿ëÇÏ¿© web context·Î µî·ÏÇϸé tomcat ¿¡ ´ÙÀ½°ú °°ÀÌ ¼³Á¤µË´Ï´Ù.
<Context docBase="dwr_ex" path="/dwr_ex" reloadable="true" source="org.eclipse.jst.j2ee.server:dwr_ex"/>
- http://localhost:8080/dwr_ex/ ÀÔ·ÂÇÏ¿© page °¡ Á¤»óÀûÀ¸·Î Ç¥½ÃµÇ´Â Áö È®ÀÎÇÕ´Ï´Ù.
- http://localhost:8080/dwr_ex/test/marshalling.html ¿¡¼ DWR ¸ðµâ µ¿ÀÛ¹æ½ÄÀ» È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.
- http://localhost:8080/dwr_ex/index.html ¿¡¼ 'configuration/test pages' ¶ó´Â ¸µÅ©¸¦ ¼±ÅÃÇϸé dwr.xml ¿¡ µî·ÏµÈ °´Ã¼µéÀ» Å×½ºÆ®ÇÒ ¼ö ÀÖ½À´Ï´Ù.
- http://localhost:8080/dwr_ex/dwr_ex.html ¿¡¼ DWR¿Í RICO¸¦ ¿¬µ¿ÇÑ °£´ÜÇÑ ¿¹Á¦¸¦ Å×½ºÆ®ÇÒ ¼ö ÀÖ½À´Ï´Ù.
- http://localhost:8080/dwr_ex/dwr_ex01.html~dwr_ex06_spring.html ¿¡¼ ¾Æ·¡ ¼³¸íµÈ ¿¹Á¦¸¦ Å×½ºÆ® ÇÒ ¼ö ÀÖ½À´Ï´Ù.
dwr example °³¹ß
¿¡·¯ ¸Þ½ÃÁö Çڵ鷯 ±¸Çö
- 'dwr_ex' ¸ðµâ ³» WebContent/dwr_ex01.html À» ÂüÁ¶ÇϽʽÿä.
- Javascript ·Î Á¶ÀÛÇϱâ À§ÇÑ DwrExample Ŭ·¡½º¸¦ ´ÙÀ½°ú °°ÀÌ Á¤ÀÇÇÕ´Ï´Ù.
package fullbox.dwr.test; import java.util.Date; public class DwrExample { public String getData1() { throw new NullPointerException("NullPointerException occurred!"); } }
- DwrExample Ŭ·¡½º¸¦ dwr.xml ¿¡ ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÕ´Ï´Ù. scope À» 'session' À¸·Î ¼³Á¤ÇÏ¿´À¸¹Ç·Î DwrExample »ý¼º ÈÄ HttpSession ¿¡ ÀúÀåµË´Ï´Ù.
<create creator="new" javascript="DwrExample" scope="session"> <param name="class" value="fullbox.dwr.test.DwrExample"/> </create>
- dwr_ex01.html Àº ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÕ´Ï´Ù.
- ¸Þ½ÃÁö ó¸® ¹æ¹ýÀº DWREngine ÀÇ setErrorHandler(), setWarningHandler() ¸Þ¼Òµå¿¡ ÀÇÇØ Á¤Àǵ˴ϴÙ.
- ÀÚ¼¼ÇÑ ³»¿ëÀº http://getahead.ltd.uk/dwr/other/errors À» ÂüÁ¶ÇϽʽÿä.
- ¸ÕÀú ¿©·¯ °³ÀÇ ErrorHandler function À» ÁöÁ¤ÇÕ´Ï´Ù. ÀÌ function µéÀº error message ¸¦ ´Ù¾çÇÏ°Ô Ç¥½ÃÇϱâ À§ÇÑ ·ÎÁ÷À» Æ÷ÇÔÇÏ°í ÀÖ½À´Ï´Ù. ¾Æ·¡´Â °£´ÜÈ÷ ¸Þ½ÃÁö¸¸ ´Ù¸£°Ô ÇÏ¿© ¼·Î ´Ù¸¥ ErrorHandler function À» ±¸ÇöÇÑ ¿¹Á¦ÀÔ´Ï´Ù.
// Global ErrorHandler ¸¦ ÁöÁ¤ÇÏ´Â function. function eh0(msg) { alert("Global ErrorHandler : " + msg); } // »õ·Î¿î ErrorHandler ¸¦ ÁöÁ¤ÇÏ´Â function 1). function eh1(msg) { alert("Applied New ErrorHandler : " + msg); } // »õ·Î¿î ErrorHandler ¸¦ ÁöÁ¤ÇÏ´Â function 2). function eh2(msg, ex) { // FunkyException ¿¡ Á¸ÀçÇÏ´Â getWhen() ¸Þ¼Òµå¸¦ ex.when À¸·Î È£Ãâ. alert(msg + ", date=" + ex.when); }
- ÇÑ ÆäÀÌÁöÀÇ ¸ðµç ¸Þ½ÃÁöÀÇ Ã³¸®¸¦ µ¿ÀÏÇÏ°Ô Ç¥½ÃÇÏ·Á¸é bodyű×ÀÇ onLoad() ½Ã init()À» ½ÇÇàÇϵµ·Ï ÇÕ´Ï´Ù. init() function Àº ¸ÕÀú Global ErrorHandler function ÀÎ eh0 À» ¼³Á¤ÇÕ´Ï´Ù.
// body onLoad() ¿¡¼ ÃʱâÈÇÏ´Â function : Global ErrorHandler¸¦ ¼³Á¤. function init() { // ErrorHandler, WarningHandler ¼³Á¤. DWREngine.setErrorHandler(eh0); DWREngine.setWarningHandler(eh0); // Loading Message ¼³Á¤. DWRUtil.useLoadingMessage(); }
- µû¶ó¼ °´Ã¼ÀÇ ¸ðµç ¸Þ¼Òµå È£Ã⠽à ¿À·ù°¡ ¹ß»ýÇϸé À§¿¡¼ Á¤ÀÇÇÑ ´ë·Î ¸Þ½ÃÁö°¡ 󸮵˴ϴÙ.
- °´Ã¼ÀÇ Æ¯Á¤ ¸Þ¼Òµå È£Ãâ ½Ã(ex : DwrExample.getData1()) ó¸® ¸Þ½ÃÁö¸¦ ´Ù¸£°Ô º¸¿©ÁÖ¾î¾ß ÇÑ´Ù¸é ÇØ´ç ¸Þ¼Òµå¸¦ È£ÃâÇϱâ Àü¿¡ DWREngine.setErrorHandler() ¸¦ ´ÙÀ½°ú °°ÀÌ ÀçÁ¤ÀÇÇÏ¿©¾ß ÇÕ´Ï´Ù.
function getDataByAppliedErrorHandler() { // »õ·Î¿î ErrorHandler¸¦ Àû¿ë. DWREngine.setErrorHandler(eh1); DwrExample.getData1(getDataCallback); }
- ´Ü, À§ ¹æ¹ýÀº DWREngine.setErrorHandler() ¿¡ Á÷Á¢ ¼³Á¤ÇÏ´Â °ÍÀ¸·Î GlobalÇÏ°Ô Àû¿ëµÇ¹Ç·Î ¼·Î ´Ù¸¥ ¸Þ¼Òµå È£Ã⠽à °¢°¢ ´Ù¸¥ ¹æ¹ýÀ¸·Î ¸Þ½ÃÁö¸¦ ó¸®ÇÏ´Â °ÍÀº ºÎÀûÀýÇÕ´Ï´Ù.
- Global ErrorHandler ÀÇ ¼³Á¤À» ±×´ë·Î À¯ÁöÇÏ¸é¼ DwrExample.getData1() È£Ã⠽à ´ÙÀ½°ú °°ÀÌ Á¤ÀÇÇÏ¿© ƯÁ¤ ¸Þ½ÃÁö¸¦ ó¸®ÇÒ ¼ö ÀÖ½À´Ï´Ù.
function getDataByLocalErrorHandler() { // »õ·Î¿î Local ErrorHandler¸¦ Àû¿ë. DwrExample.getData1({ callback : getDataCallback, errorHandler : function(msg, ex) { alert("Local ErrorHandler : " + msg); } }); }
- À§¿Í °°ÀÌ ÀÛ¼ºÇϸé Global ErrorHandler ÀÇ ¼³Á¤°ú Local ErrorHandler ÀÇ ¼³Á¤À» ºÐ¸®ÇÒ ¼ö ÀÖ½À´Ï´Ù.
»ç¿ëÀÚ Á¤ÀÇ Exception ó¸®
- 'dwr_ex' ¸ðµâ ³» WebContent/dwr_ex01.html À» ÂüÁ¶ÇϽʽÿä.
- »ç¿ëÀÚ Á¤ÀÇÀÇ FunkyException Ŭ·¡½º¸¦ ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÕ´Ï´Ù.
package fullbox.dwr.test; import java.util.Date; public class FunkyException extends RuntimeException { private final static long serialVersionUID = 1L; private Date date; public FunkyException(String msg) { super(msg); } public FunkyException(String msg, Date date) { super(msg); this.date = date; } public Date getWhen() { return date; } }
- ¸ÕÀú ±¸ÇöÇÑ Exception (ex : FunkyException) À» dwr.xml ÀÇ bean converter·Î ¼³Á¤ÇÏ¿©¾ß ÇÕ´Ï´Ù.
<convert match="fullbox.dwr.test.FunkyException" converter="bean" />
- ´ÙÀ½Àº DwrExample Ŭ·¡½º¸¦ ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÕ´Ï´Ù.
package fullbox.dwr.test; import java.util.Date; public class DwrExample { public String getData1() { ... } public String getData2() { Date when = new Date(); // FunkyException ¿¹¿Ü ¹ß»ý. throw new FunkyException("FunkyException occurred!", when); } }
- dwr_ex01.html ¿¡¼ °´Ã¼ÀÇ Æ¯Á¤ ¸Þ¼Òµå È£Ãâ ½Ã(ex : DwrExample.getData2()) ó¸® ¸Þ½ÃÁö¸¦ ´Ù¸£°Ô º¸¿©ÁÖ¾î¾ß ÇÑ´Ù¸é ÇØ´ç ¸Þ¼Òµå¸¦ È£ÃâÇϱâ Àü¿¡ DWREngine.setErrorHandler() ¸¦ ´ÙÀ½°ú °°ÀÌ ÀçÁ¤ÀÇÇÏ¿©¾ß ÇÕ´Ï´Ù.
function getDataThrownFunkyExceptionByAppliedErrorHandler() { // »õ·Î¿î ErrorHandler¸¦ Àû¿ë. DWREngine.setErrorHandler(eh2); DwrExample.getData2(getDataCallback); }
- ´Ü, À§ ¹æ¹ýÀº DWREngine.setErrorHandler() ¿¡ Á÷Á¢ ¼³Á¤ÇÏ´Â °ÍÀ¸·Î GlobalÇÏ°Ô Àû¿ëµÇ¹Ç·Î ¼·Î ´Ù¸¥ ¸Þ¼Òµå È£Ã⠽à °¢°¢ ´Ù¸¥ ¹æ¹ýÀ¸·Î ¸Þ½ÃÁö¸¦ ó¸®ÇÏ´Â °ÍÀº ºÎÀûÀýÇÕ´Ï´Ù.
- Global ErrorHandler ÀÇ ¼³Á¤À» ±×´ë·Î À¯ÁöÇÏ¸é¼ DwrExample.getData2() È£Ã⠽à ´ÙÀ½°ú °°ÀÌ Á¤ÀÇÇÏ¿© ƯÁ¤ ¸Þ½ÃÁö¸¦ ó¸®ÇÒ ¼ö ÀÖ½À´Ï´Ù.
function getDataThrownFunkyExceptionByLocalErrorHandler() { // »õ·Î¿î Local ErrorHandler¸¦ Àû¿ë. DwrExample.getData2({ callback : getDataCallback, errorHandler : function(msg, ex) { alert("Local ErrorHandler : " + msg + " , date=" + ex.when); } }); }
- À§¿Í °°ÀÌ ÀÛ¼ºÇϸé Global ErrorHandler ÀÇ ¼³Á¤°ú Local ErrorHandler ÀÇ ¼³Á¤À» ºÐ¸®ÇÒ ¼ö ÀÖ½À´Ï´Ù.
JavaBean °ª ¼ÂÆÃ
- 'dwr_ex' ¸ðµâ ³» WebContent/dwr_ex02.html À» ÂüÁ¶ÇϽʽÿä.
- À̹ø ¿¹Á¦´Â Javascript °´Ã¼¸¦ ÅëÇØ DwrExample JavaBean¿¡ °ªÀ» ¼ÂÆÃÇÏ°í °á°ú¸¦ Ãâ·ÂÇÏ´Â ¿¹Á¦ÀÔ´Ï´Ù.
- DwrExample Ŭ·¡½º¿¡ name À» ¼ÂÆÃÇÏ´Â setName() ¸Þ¼Òµå¿Í, Foo °´Ã¼¸¦ ¼ÂÆÃÇÏ´Â setFoo() ¸Þ¼Òµå¸¦ Ãß°¡ÇÕ´Ï´Ù.
package fullbox.dwr.test; import java.util.Date; public class DwrExample { ... ÀÌÀü ¿¹Á¦ÀÇ ¸Þ¼Òµå ... private Foo foo; public void setName(String name) { System.out.println("### name : " + name); } public void setFoo(Foo foo) { System.out.println("### foo.name : " + foo.getName()); System.out.println("### foo.title : " + foo.getTitle()); System.out.println("### foo.content : " + foo.getContent()); this.foo = foo; } public Foo getFoo() { return foo; } }
- Foo Ŭ·¡½º´Â name, title, content Çʵ带 °®°í °¢ set, get ¸Þ¼Òµå¸¦ °¡Áø Ŭ·¡½ºÀÔ´Ï´Ù. dwr_ex ¸ðµâ ³» src/fullbox/dwr/test/Foo.java ¸¦ ÂüÁ¶ÇϽʽÿä.
- dwr.xml ¿¡ º¸¸é Foo Ŭ·¡½º´Â ´ÙÀ½°ú °°ÀÌ bean converter ·Î ¼³Á¤µÇ¾î ÀÖ½À´Ï´Ù.
<convert match="fullbox.dwr.test.Foo" converter="bean"/>
- dwr_ex02.html ¿¡¼ ´ÙÀ½°ú °°ÀÌ function À» ÀÛ¼ºÇÕ´Ï´Ù.
// name °ªÀ» DwrExample JavaBean¿¡ ¼ÂÆÃ. function setName() { var name = frm.name.value; DwrExample.setName(name); } // name, title, content °ªÀ» DwrExample JavaBean¿¡ ¼ÂÆÃ. function setFoo() { var foo = { name : frm.name.value, title : frm.title.value, content : frm.content.value }; DwrExample.setFoo(foo); } // ÀúÀåµÈ Foo °ªÀ» °¡Á®¿À´Â function. function getFoo() { DwrExample.getFoo(getFooCallback); } // getFoo()ÀÇ callback function. function getFooCallback(foo) { DWRUtil.setValue("data", "name : " + foo.name + " , title : " + foo.title + " , content : " + foo.content); }
- ÀÔ·ÂÆûÀ» »ý¼ºÇÏ°í function setName(), setFoo() À» È£ÃâÇÏ¿© tomcat ÄÜ¼Ö ·Î±×â¿¡ ¼ÂÆÃµÈ °ªÀÌ Á¤»óÀûÀ¸·Î Ãâ·ÂµÇ´ÂÁö È®ÀÎÇÕ´Ï´Ù.
- getFoo() À» È£ÃâÇϸé div ÅÂ±× ³»¿¡ °ªÀÌ º¯°æµÇ´ÂÁö È®ÀÎÇÕ´Ï´Ù.
combobox µ¿Àû ±¸¼º
- 'dwr_ex' ¸ðµâ ³» WebContent/dwr_ex03.html À» ÂüÁ¶ÇϽʽÿä.
- À̹ø ¿¹Á¦´Â Javascript °´Ã¼¸¦ ÅëÇØ DwrExample JavaBean¿¡ °ªÀ» °¡Á®¿Í µ¿ÀûÀ¸·Î Combobox¸¦ »ý¼ºÇÏ´Â ¿¹Á¦ÀÔ´Ï´Ù.
- DwrExample Ŭ·¡½º¿¡ ÁÖ ¸®½ºÆ®¸¦ °¡Á®¿À´Â ¸Þ¼Òµå¿Í µµ½Ã ¸®½ºÆ®¸¦ °¡Á®¿À´Â ¸Þ¼Òµå¸¦ ´ÙÀ½°ú °°ÀÌ Á¤ÀÇÇÕ´Ï´Ù.
package fullbox.dwr.test; import java.util.Date; public class DwrExample { ... ÀÌÀü ¿¹Á¦ÀÇ ¸Þ¼Òµå ... private String[][] address = { {"Florida", "Bryceville"} ,{"Florida", "Elkton"} ,{"Florida", "Glen Saint Mary"} ,{"Michigan", "Birmingham"} ,{"Michigan", "Marine City"} ,{"Michigan", "Chesterfield"} ,{"Minnesota", "Almelund"} ,{"Minnesota", "Castle Rock"} ,{"Minnesota", "Dalbo"} ,{"California", "Los Angeles"} ,{"California", "Orange"} }; public Map getComboListState() { Map map = new HashMap(); String curState; String prevState = ""; for( int i = 0 ; i < address.length ; i++ ) { curState = address[i][0]; if(!curState.equals(prevState)) map.put(address[i][0], address[i][0]); prevState = curState; } return map; } public Map getComboListCity() { Map map = new HashMap(); for( int i = 0 ; i < address.length ; i++ ) { map.put(address[i][1], address[i][1]); } return map; } }
- dwr_ex03.html ¿¡¼ ´ÙÀ½°ú °°ÀÌ function À» ÀÛ¼ºÇÕ´Ï´Ù.
// dynamic Combobox ¼³Á¤ function. function getComboListState() { DwrExample.getComboListState(getListComboCallback); } // dynamic Combobox ¼³Á¤ function. function getComboListCity() { DwrExample.getComboListCity(getListComboCallback); } // callback function. function getListComboCallback(data) { DWRUtil.removeAllOptions("listCombo"); var defaultSelect = {"":" -- select -- "}; DWRUtil.addOptions("listCombo", defaultSelect); DWRUtil.addOptions("listCombo", data); }
- ºó select ű×ÀÇ name °ªÀ» 'listCombo' ·Î Á¤ÀÇÇÕ´Ï´Ù.
- function getComboListState(), getComboListCity() ¸¦ È£ÃâÇÏ¿´À» ¶§ listCombo ¹Ú½ºÀÇ ³»¿ëÀÌ µ¿ÀûÀ¸·Î º¯°æµÇ´ÂÁö È®ÀÎÇÕ´Ï´Ù.
»óÀ§ combobox ¼±Åÿ¡ µû¸¥ ÇÏÀ§ combobox µ¿Àû ±¸¼º
- 'dwr_ex' ¸ðµâ ³» WebContent/dwr_ex04.html À» ÂüÁ¶ÇϽʽÿä.
- À̹ø ¿¹Á¦´Â »óÀ§ Combobox ¿¡¼ ƯÁ¤ ÁÖ¸¦ ¼±Åà ½Ã ÇØ´çÇÏ´Â ÇÏÀ§ µµ½Ã ¸®½ºÆ®¸¦ sub Combobox¿¡ µ¿ÀûÀ¸·Î ¼ÂÆÃÇÏ´Â ¿¹Á¦ÀÔ´Ï´Ù.
- DwrExample Ŭ·¡½º¿¡¼ ÁÖ ¸®½ºÆ®¸¦ °¡Á®¿À´Â ¸Þ¼Òµå´Â combobox µ¿Àû ±¸¼º¸¦ ÂüÁ¶ÇÏ¸ç µµ½Ã ¸®½ºÆ®¸¦ °¡Á®¿À´Â ¸Þ¼Òµå´Â ´ÙÀ½°ú °°ÀÌ Á¤ÀÇÇÕ´Ï´Ù.
package fullbox.dwr.test; import java.util.Date; public class DwrExample { ... ÀÌÀü ¿¹Á¦ÀÇ ¸Þ¼Òµå ... private String[][] address = { ... }; public Map getComboListState() { ... } public Map getComboListCityByState(String state) { Map map = new HashMap(); for( int i = 0 ; i < address.length ; i++ ) { if(address[i][0].equals(state)) map.put(address[i][1], address[i][1]); } return map; } }
- dwr_ex04.html ¿¡¼ ´ÙÀ½°ú °°ÀÌ function À» ÀÛ¼ºÇÕ´Ï´Ù.
// init() function ¿¡ ÆäÀÌÁö ·Îµù ½Ã stateCombo¹Ú½º¸¦ ¼ÂÆÃÇÏ´Â °ÍÀ» È£ÃâÇÕ´Ï´Ù. function init() { ... ErrorHandler ¼³Á¤... // dynamic state Combobox ¼³Á¤ function. DwrExample.getComboListState(getComboListStateCallback); } // dynamic Combobox ¼³Á¤ function. function getComboListCityByState() { // $() À¸·Î ÇöÀç html doucument ³» ÁöÁ¤µÈ id, ids ¿¡ ÇØ´çÇÏ´Â element object¸¦ °¡Á®¿È. var state = $("stateCombo").value; DwrExample.getComboListCityByState(state, getComboListCityCallback); } // callback function. function getComboListStateCallback(data) { DWRUtil.removeAllOptions("stateCombo"); var defaultSelect = {"":" -- select -- "}; DWRUtil.addOptions("stateCombo", defaultSelect); DWRUtil.addOptions("stateCombo", data); } // callback function. function getComboListCityCallback(data) { DWRUtil.removeAllOptions("cityCombo"); var defaultSelect = {"":" -- select -- "}; DWRUtil.addOptions("cityCombo", defaultSelect); DWRUtil.addOptions("cityCombo", data); }
- µÎ°³ÀÇ ºó select ű׸¦ »ý¼ºÇÏ°í °¢°¢ name °ªÀ» 'stateCombo', 'cityCombo' ·Î Á¤ÀÇÇÕ´Ï´Ù.
- stateCombo ÀÇ onChange="getComboListCityByState();" ¸¦ ¼³Á¤ÇÕ´Ï´Ù.
- ÀÛ¼º¿Ï·á ÈÄ ÆäÀÌÁö ·Îµù ½Ã stateCombo ¹Ú½º¿¡ Á¤»óÀûÀ¸·Î °ªÀÌ ¼ÂÆõǴÂÁö È®ÀÎÇÕ´Ï´Ù.
- stateCombo¹Ú½ºÀÇ °ªÀ» º¯°æÇϸé Á¤»óÀûÀ¸·Î cityCombo¹Ú½ºÀÇ °ªÀÌ º¯°æµÇ´ÂÁö È®ÀÎÇÕ´Ï´Ù.
°Ë»ö¾îÃßõ ¹Ú½º ¸¸µé±â
- 'dwr_ex' ¸ðµâ ³» WebContent/dwr_ex05.html À» ÂüÁ¶ÇϽʽÿä.
- À̹ø ¿¹Á¦´Â ÀԷ¹ڽº¿¡¼ Çϳª¾¿ ÀÔ·ÂÇÒ ¶§¸¶´Ù ½Ç½Ã°£À¸·Î ÀÔ·ÂµÈ ´Ü¾î·Î ½ÃÀ۵Ǵ Ãßõ´Ü¾îµéÀ» °Ë»öÇØÁÖ´Â ¿¹Á¦ÀÔ´Ï´Ù.
´Ü, ÇöÀç 100 ~ 199 ±îÁöÀÇ ¼ýÀÚ¹®ÀÚ¿¸¸ ¹è¿¿¡ ÀúÀåµÇ¾î ÀÖÀ¸¹Ç·Î °Ë»ö¾î ¹üÀ§¸¦ 100 ~ 199 »çÀ̸¸ ÀÔ·ÂÇÏ¿©¾ß ÇÕ´Ï´Ù. ±×¸®°í °Ë»ö¾î Ãßõ ¸®½ºÆ®¿¡¼ ƯÁ¤ °Ë»ö¾î¸¦ ´õºíŬ¸¯Çϸé div ű׿¡ ¼±ÅÃÇÑ °Ë»ö¾î¸¦ Ç¥½ÃÇÕ´Ï´Ù.
- DwrExample Ŭ·¡½º¿¡¼ ´ÙÀ½°ú ³»¿ëÀ» ÀÛ¼ºÇÕ´Ï´Ù.
package fullbox.dwr.test; import java.util.Date; public class DwrExample { ... ÀÌÀü ¿¹Á¦ÀÇ ¸Þ¼Òµå ... private static String[] titles = new String[199]; static { for( int i = 100 ; i < titles.length ; i++ ) { titles[i] = "" + i; } } public List getRecommendSearch(String title) { List result = new ArrayList(); for( int i = 100 ; i < titles.length ; i++ ) { if(titles[i].startsWith(title)) { result.add(titles[i]); } } return result; } }
- dwr_ex05.html ¿¡¼ ´ÙÀ½°ú °°ÀÌ function À» ÀÛ¼ºÇÕ´Ï´Ù.
function recommendSearch() { var arg = $("title").value; DwrExample.getRecommendSearch(arg, recommendSearchCallback); } function recommendSearchCallback(data) { // table ³» °¢ ¿¿¡ ´ëÇÑ Á¤ÀǸ¦ ´ÙÀ½°ú °°ÀÌ °¢ ¿´ë·ÎÀÇ function À» Á¤ÀÇÇÔ var cellFuncs = [ function(data) { return "<input type='text' name='recommend' style='border:0px;cursor:hand' " + " value='" + data + "' onClick='selectRecommend(this.value)' readOnly />"; } ]; DWRUtil.removeAllRows("RecommendTable"); DWRUtil.addRows("RecommendTable", data, cellFuncs); } function selectRecommend(data) { DWRUtil.setValue("recommendDiv", data); }
- ´ÙÀ½Àº °Ë»ö¾î¸¦ ÀÔ·ÂÇÒ ÀԷ¹ڽº¿Í divű×, ±×¸®°í °Ë»ö¾î Ãßõ ¸®½ºÆ®¸¦ º¸¿©ÁÙ tableű׸¦ ´ÙÀ½°ú °°ÀÌ Á¤ÀÇÇÕ´Ï´Ù.
<form name="frm"> <table width="60%"> <tr> <td width="50%"> <input type="text" name="title" value="" onKeyUp="recommendSearch();" /> </td> <td width="50%"> <div id="recommendDiv" style="border:1px solid #000000;"> Recommended argments </div> </td> </tr> </table> </form> <table style="border:1px solid #000000;" cellspacing="0" cellpadding="0"> <tbody id="RecommendTable" border="0" > </tbody> </table>
- À§ ¼Ò½º¿¡¼ ÀԷ¹ڽº¿¡ ÀÖ´Â onKeyUp() À̺¥Æ® Çڵ鷯¸¦ ÅëÇؼ Å°¸¦ ´©¸¥ ÈÄ ¶ª ¶§¸¶´Ù °Ë»ö¾î Ãßõ¸®½ºÆ®¸¦ ¼¹ö¿¡¼ Á¶È¸ÇÏ°Ô µË´Ï´Ù. Á¤»óÀûÀ¸·Î ÀÛµ¿ÇÏ´Â Áö ÀԷ¹ڽº¿¡ ÇѴܾ ÀÔ·ÂÇÏ¿© Å×½ºÆ®ÇÕ´Ï´Ù.
- Á¶È¸µÈ °Ë»ö¾î Ãßõ ¸®½ºÆ®¿¡¼ ´õºíŬ¸¯ÇßÀ» ¶§ ÀԷ¹ڽº ¿·ÀÇ recommendDiv ¿¡ ¼±ÅÃÇÑ °Ë»ö¾î Ãßõ ´Ü¾î°¡ Á¤»óÀûÀ¸·Î ¼ÂÆõǴÂÁö È®ÀÎÇÕ´Ï´Ù.
°£´ÜÇÑ °Ô½ÃÆÇ(CRUD ±â´É) ¸¸µé±â
- 'dwr_ex' ¸ðµâ ³» WebContent/dwr_ex06.html À» ÂüÁ¶ÇϽʽÿä.
- À̹ø ¿¹Á¦´Â °Ë»öÆûÀ» ÀÌ¿ëÇÏ¿© °Ë»öÇÑ ¸®½ºÆ®¿¡¼ ÀÔ·Â,¼öÁ¤,»èÁ¦¸¦ ÇÏ´Â °£´ÜÇÑ °Ô½ÃÆÇÀ» ±¸ÇöÇÕ´Ï´Ù.
- ÀÌ °Ô½ÃÆÇÀº ÆäÀÌÁöÀÇ °»½Å¾øÀÌ CRUD °¡ ¼öÇàµÇ¹Ç·Î µ¿ÀûÀÎ ÆäÀÌÁöÀÇ º¯°æ ¹× ¸®½ºÆ®ÀÇ °»½Å µîÀ» ÇÊ¿ä·Î ÇÏ´Â º¹ÀâÇÑ È¸é¿¡¼ »ç¿ëÇϱ⿡ ÀûÀýÇÕ´Ï´Ù.
- DwrExample Ŭ·¡½º¿¡¼ ´ÙÀ½°ú °°ÀÌ µ¥ÀÌÅͺ£À̽ºÀÇ ¿¬°á¾øÀÌ static variable ·Î CRUD¸¦ ó¸®ÇÏ´Â ¸Þ¼Òµå¸¦ °£´ÜÈ÷ ±¸ÇöÇÕ´Ï´Ù.
package fullbox.dwr.test; import java.util.Date; public class DwrExample { ... ÀÌÀü ¿¹Á¦ÀÇ ¸Þ¼Òµå ... // µ¥ÀÌÅÍÀÇ ¼±¾ð private static Map datas = new HashMap(); static { for (int i = 100 ; i < 199 ; i++ ) { Foo foo = new Foo(); foo.setName("" + i); foo.setTitle("title" + i); foo.setContent("content" + i); datas.put(foo.getName(), foo); } } // Á¶È¸ ¸Þ¼Òµå public List listFoo(String name) { List result = new ArrayList(); Iterator it = new TreeMap(datas).values().iterator(); while(it.hasNext()) { Foo foo = (Foo)it.next(); if(foo.getName().startsWith(name)) { result.add(foo); } } return result; } // »ó¼¼³»¿ª Á¶È¸ ¸Þ¼Òµå public Foo viewFoo(String name) { return (Foo)datas.get(name); } // ÀÔ·Â, ¼öÁ¤ ¸Þ¼Òµå public void updateFoo(Foo foo) { datas.remove(foo.getName()); datas.put(foo.getName(), foo); } // »èÁ¦ ¸Þ¼Òµå public void deleteFoo(Foo foo) { datas.remove(foo.getName()); } }
- dwr_ex06.html ¿¡¼ ´ÙÀ½°ú °°ÀÌ function À» ÀÛ¼ºÇÕ´Ï´Ù.
// Á¶È¸ function function listFoo() { var arg = $("search").value; // ù¹ø° ¸Å°³º¯¼ö´Â ½Ç¸Å°³º¯¼ö·Î, µÎ¹ø°´Â callback functionÀ» ¼ÂÆÃ. DwrExample.listFoo(arg, listFooCallback); } // Á¶È¸ callback function function listFooCallback(foos) { // fooTable tbody ³»¿¡¼ ´Ù½Ã Á¶È¸ µÇ¾úÀ» ¶§ id °¡ 'pattern'ÀÎ trű׸¸ ³²°ÜµÎ°í ³ª¸ÓÁö »èÁ¦. DWRUtil.removeAllRows("fooTable", { filter : function(tr) { return (tr.id != "pattern"); } }); // ·çÇÁ µ¹¸é¼ foo ¸®½ºÆ®¸¦ °¢ span ű×ÀÇ id¿¡ ÇØ´çÇÏ´Â À§Ä¡¿¡ °ª ¼ÂÆÃ. for (var i = 0; i < foos.length; i++) { var foo = foos[i]; var name = foo.name; DWRUtil.cloneNode("pattern", { idSuffix:name }); DWRUtil.setValue("tname" + name, name); DWRUtil.setValue("ttitle" + name, foo.title); DWRUtil.setValue("tcontent" + name, foo.content); // º¹»çÇÑ tr ű׸¦ ȸ鿡 ³ªÅ¸³ª°Ô ÇÔ. $("pattern" + name).style.display = ""; } } // »ó¼¼³»¿ª Á¶È¸ function function viewFoo(pttnid) { // pttnid ´Â 'pattern110' ÀÌ·± ÇüÅÂÀ̹ǷΠ'pattern' prefix¸¦ Àß¶ó³½ ³ª¸ÓÁö°¡ foo.name ÀÓ. var name = pttnid.substring(7); DwrExample.viewFoo(name, function(foo) { DWRUtil.setValue("name", foo.name); DWRUtil.setValue("title", foo.title); DWRUtil.setValue("content", foo.content); // ¼öÁ¤, »èÁ¦ ½Ã name Çʵå´Â readonly·Î ¼ÂÆÃ. $("name").readonly = true; }); } // ÀÔ·Â,¼öÁ¤ function function insertFoo() { var foo = { name : $("name").value, title : $("title").value, content : $("content").value }; // DWREngineÀÇ batch ´ÜÀ§·Î ¹¾î¼ ÀÏ°ýó¸® ÇÔ. performance Çâ»ó. DWREngine.beginBatch(); DwrExample.updateFoo(foo); listFoo(); DWREngine.endBatch(); } // »èÁ¦ function function deleteFoo() { var foo = { name : $("name").value, title : null, content : null }; // DWREngineÀÇ batch ´ÜÀ§·Î ¹¾î¼ ÀÏ°ýó¸® ÇÔ. performance Çâ»ó. DWREngine.beginBatch(); DwrExample.deleteFoo(foo); listFoo(); frmReset(); DWREngine.endBatch(); } // Æû ¸®¼Â function function frmReset() { var val = frm.search.value; frm.reset(); frm.search.value = val; frm.name.readonly = false; }
- À§ ½ºÅ©¸³Æ®´Â ±â´Éº°·Î ±¸ÇöÇÑ °ÍÀ̹ǷΠfunction ³» ÁÖ¼®À» ÂüÁ¶ÇÏ¸é ½±°Ô ÀÌÇØÇÒ ¼ö ÀÖ½À´Ï´Ù.
- ´ÙÀ½Àº °Ë»ö¾î¸¦ ÀÔ·ÂÇÒ ÀԷ¹ڽº¿Í Á¶È¸¹öÆ°¿¡ ´ëÇÑ Å±׸¦ ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÕ´Ï´Ù. À̺¥Æ® Çڵ鷯´Â onclick ÀÔ´Ï´Ù.
<table width="60%"> <tr> <td> <input type="text" name="search" value="" /> <input type="button" name="listfoo" value="search" onclick="listFoo();" /> </td> </tr> </table>
- ´ÙÀ½Àº ¸®½ºÆ®¸¦ Ç¥½ÃÇÒ Å×À̺í°ú »ó¼¼³»¿ª Å×À̺íÀ» ´ÙÀ½°ú °°ÀÌ ÀÛ¼ºÇÕ´Ï´Ù. ¸®½ºÆ® Å×À̺íÀÇ trÅÂ±× ³»ÀÇ viewFoo() function ÀÌ onDblClick À̺¥Æ®Çڵ鷯·Î ¼³Á¤µÇ¾î ÀÖ½À´Ï´Ù.
<table width="60%" style="border:1px solid #000000;" cellspacing="0" cellpadding="0"> <thead> <tr> <th width="20%">Name</th> <th width="40%">Title</th> <th width="40%">Content</th> </tr> </thead> <tbody id="fooTable"> <tr id="pattern" style="display:none;cursor:hand;" onDblClick="viewFoo(this.id);" > <td><span id="tname">Name</span></td> <td><span id="ttitle">Title</span></td> <td><span id="tcontent">Content</span></td> </tr> </tbody> </table> <br /> <table width="60%"> <tr> <td>Name</td> <td width="80%"><input type="text" id="name" name="name" value="" /></td> </tr> <tr> <td>Title</td> <td><input type="text" id="title" name="title" value="" /></td> </tr> <tr> <td>Content</td> <td><input type="text" id="content" name="content" value="" /></td> </tr> </table>
- À§ ¼Ò½º¿¡¼ viewFoo() ÀÇ ¸Å°³º¯¼öÀÇ °ªÀ¸·Î tr ű×ÀÇ id °ªÀ» ³Ñ°ÜÁÖ´Â µ¥ ÀÌ´Â 'pattern' + 'name °ª' À̹ǷΠ°¢ trű׸¶´Ù À¯ÀÏÇÏ°Ô Á¤ÀǵǾî ÀÖ½À´Ï´Ù. ±×·¯¹Ç·Î prefix ÀÎ 'pattern'À» Á¦¿ÜÇÑ 'name °ª'À» ÇØ´ç trű×ÀÇ Å°°ªÀ¸·Î ÇÏ¿© °¢ foo ¸¦ ¼öÁ¤Çϰųª »èÁ¦ÇÒ ¼ö ÀÖ½À´Ï´Ù.
- ´ÙÀ½Àº CUD ¹öÆ°À» ÀÛ¼ºÇÕ´Ï´Ù. °¢°¢ functionÀº button ÀÇ onclick À̺¥Æ® Çڵ鷯·Î ¼³Á¤µÇ¾î ÀÖ½À´Ï´Ù.
<table width="60%"> <tr> <td> <input type="button" name="insert" value="insert Foo" onclick="insertFoo();" /> <input type="button" name="update" value="update Foo" onclick="insertFoo();" /> <input type="button" name="delete" value="delete Foo" onclick="deleteFoo();" /> </td> </tr> </table>
- dwr_ex06.html ÀÇ ÄÚµå ÀÛ¼º ¿Ï·á ÈÄ Å×½ºÆ®¸¦ À§ÇÏ¿© '100' ~ '199' (µ¥ÀÌÅÍ°ª) ÀÇ Æ¯Á¤ °ªÀ» ÀÔ·ÂÇÏ¿© 'search' ¹öÆ°À» ¼±ÅÃÇÕ´Ï´Ù.
- Á¶È¸µÈ ¸®½ºÆ®¿¡¼ ƯÁ¤ µ¥ÀÌÅ͸¦ ¼±ÅÃÇÕ´Ï´Ù. ±×¸®°í ¾Æ·¡ »ó¼¼³»¿ª¿¡¼ title, content Ç׸ñÀ» ¼öÁ¤ ÈÄ 'update Foo' ¹öÆ°À» ¼±ÅÃÇϸé Á¤»óÀûÀ¸·Î ¼öÁ¤µÇ°í Á¶È¸µÇ´ÂÁö È®ÀÎÇÕ´Ï´Ù.
- Á¶È¸µÈ ¸®½ºÆ®¿¡¼ ƯÁ¤ µ¥ÀÌÅ͸¦ ¼±ÅÃÇÕ´Ï´Ù. ±×¸®°í ¾Æ·¡ »ó¼¼³»¿ª¿¡¼ 'delete Foo' ¹öÆ°À» ¼±ÅÃÇϸé Á¤»óÀûÀ¸·Î »èÁ¦µÇ°í Á¶È¸ ÈÄ µ¥ÀÌÅÍ°¡ »èÁ¦µÇ¾ú´ÂÁö È®ÀÎÇÕ´Ï´Ù.
- ¾Æ·¡ »ó¼¼³»¿ª ÃʱâÈ »óÅ¿¡¼ name, title, content Ç׸ñÀ» ÀÔ·ÂÈÄ 'insert Foo' ¹öÆ°À» ¼±ÅÃÇϸé Á¤»óÀûÀ¸·Î ÀԷµǰí Á¶È¸µÇ´ÂÁö È®ÀÎÇÕ´Ï´Ù.
Web Framework Integration
- struts, spring, webwork, jsf µî web framework ÀÇ bean ¼³Á¤ ÆÄÀÏ¿¡ µî·ÏµÈ JavaBeans¸¦ DWR ¿¡¼ Javascript ·Î Á¶ÀÛ°¡´ÉÇÏ°Ô ÇÏ´Â °ÍÀ¸·Î °£´ÜÇÑ ¼³Á¤¸¸À¸·Î ¿¬µ¿ÀÌ °¡´ÉÇÕ´Ï´Ù.
- ÀÚ¼¼ÇÑ ³»¿ëÀº http://getahead.ltd.uk/dwr/integration À» ÂüÁ¶ÇϽʽÿä.
Struts Integration
- DWR º¸´Ù Struts ÀÇ ¼³Á¤ÀÌ ¸ÕÀú ÃʱâȵǾî¾ß ÇϹǷΠweb.xml ¿¡ Servlet(Struts ÀÇ ActionServlet, DWRÀÇ DWRServlet) ¼³Á¤ ½Ã load-on-startup ű׷ΠÃʱâÈ ¼ø¼¸¦ Á¤ÇØ¾ß ÇÕ´Ï´Ù.
<web-app> ... <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionServlet</servlet-class> ... <load-on-startup>1</load-on-startup> </servlet> <servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class> ... <load-on-startup>2</load-on-startup> </servlet> ... </web-app>
- Struts ÀÇ ¼³Á¤ÆÄÀÏÀÎ struts-config.xml ¿¡ ´ÙÀ½°ú °°ÀÌ DwrExample À» ¼³Á¤ÇÕ´Ï´Ù.
<struts-config> .. <form-beans> <form-bean name="DwrExample" type="fullbox.dwr.test.DwrExample" /> </form-beans> .. </struts-config>
- DWR ÀÇ ¼³Á¤ÆÄÀÏÀÎ dwr.xml ¿¡ struts-config.xml ¿¡ ¼³Á¤µÈ DwrExample À» ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÕ´Ï´Ù.
<allow> ... <create creator="struts" javascript="DwrExample"> <param name="formBean" value="DwrExample"/> </create> ... </allow>
- À̷νá Struts ¿¡ ¼³Á¤µÈ DwrExample À» DWR ¿¡¼ Á¶ÀÛ°¡´ÉÇÕ´Ï´Ù.
Spring Integration
- 'dwr_ex' ¸ðµâ ³» WebContent/dwr_ex06_spring.html À» ÂüÁ¶ÇϽʽÿä.
- SpringÀÇ ¼³Á¤ÆÄÀÏÀ» ·ÎµùÇϱâ À§ÇØ web.xml ¿¡ ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÕ´Ï´Ù.
<web-app> ... <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/beans.xml</param-value> </context-param> <listener> <listener-class> org.springframework.web.context.ContextLoaderListener </listener-class> </listener> ... </web-app>
- Spring ÀÇ ¼³Á¤ÆÄÀÏÀÎ beans.xml ¿¡ ´ÙÀ½°ú °°ÀÌ DwrExample À» ¼³Á¤ÇÕ´Ï´Ù.
<beans> ... <bean id="DwrExample" class="fullbox.dwr.test.DwrExample" /> ... </beans>
- DWR ÀÇ ¼³Á¤ÆÄÀÏÀÎ dwr.xml ¿¡ beans.xml ¿¡ ¼³Á¤µÈ DwrExample À» ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÇÕ´Ï´Ù.
<allow> ... <create creator="spring" javascript="DwrExample"> <param name="beanName" value="DwrExample"/> </create> ... </allow>
- À̷νá Spring ¿¡ ¼³Á¤µÈ DwrExample À» DWR ¿¡¼ Á¶ÀÛ°¡´ÉÇÕ´Ï´Ù.