Struts, Tiles, JavaServer Faces ÅëÇÕÀÇ Èû
Srikanth
Shenoy, J2EE Consultant, Objectseek Inc. Nithin
Mallya , J2EE Consultant, Objectseek
Inc.
2003³â 9¿ù 23ÀÏ
JavaServer Faces (JSF)ÀÇ
ÇÁ·ÐÆ®-¿£µå ¼º´É, TilesÀÇ ÄÜÅÙÆ® Æ÷¸Ë ´É·Â, Struts ÄÜÆ®·Ñ·¯ÀÇ À¯¿¬¼ºÀÌ J2EE À¥
¾ÖÇø®ÄÉÀ̼ǿ¡ µé¾îÀÖ´Ù¸é? ¿£ÅÍÇÁ¶óÀÌÁî ÀÚ¹Ù Àü¹®°¡ Srikanth Shenoy¿Í Nithin Mallya´Â
ÀÌ ¼¼ °³ÀÇ Æ¯Â¡À» ÅëÇÕÇÏ´Â ¹æ¹ýÀ» º¸¿©ÁØ´Ù.
Struts, Tiles, JavaServer Faces (JSF)¸¦ ÇÔ²² »ç¿ëÇÔÀ¸·Î¼ °³¹ßÀÚµéÀº °ü¸® ¹×
ÀçÈ°¿ëÀÌ ½¬¿î °·ÂÇÏ°í Ç¥Çö¼ºÀÌ ¶Ù¾î³ À¥ ¾ÖÇø®ÄÉÀ̼ÇÀ» ¸¸µé ¼ö ÀÖ´Ù.
Struts ÇÁ·¹ÀÓ¿÷Àº ²Ï ¿À·§µ¿¾È Á¸ÀçÇß°í »ç½Ç»ó J2EE À¥ ¾ÖÇø®ÄÉÀ̼ÇÀ» °³¹ßÇÒ ¶§ ÀÇÁ¸ÇÏ°Ô µÇ´Â
Ç¥ÁØÀÌ´Ù. Tiles ÇÁ·¹ÀÓ¿÷Àº Struts ÀÌÈÄ¿¡ µîÀåÇß°í ÄÄÆ÷³ÍÆ® ºÎºÐµéÀ» »ç¿ëÇÏ¿© ÇÁ¸®Á¨Å×ÀÌ¼Ç ÆäÀÌÁö¸¦
¾î¼Àºí¸µÇÏ´Â ±â´ÉÀ» ¼±º¸ÀÓÀ¸·Î¼ À§»óÀ» ´ÙÁ³´Ù. À¥ ¾ÖÇø®ÄÉÀÌ¼Ç ÇÁ·¹ÀÓ¿÷ÀÇ ½Å»ý¾ÆÀÎ JSF´Â ÀÎDzÀÇ Å¸´ç¼º°Ë»ç¿Í
À¯Àú À̺¥Æ®ÀÇ Çڵ鸵À» À§ÇÑ ¸ÞÄ¿´ÏÁòÀ» Á¦°øÇÑ´Ù. ¹«¾ùº¸´Ù Áß¿äÇÑ°ÍÀº ÀÌ°ÍÀÌ ÇÁ·ÎÅäÄÝ¿¡¼ µ¶¸³ÀûÀÎ ¹æ½ÄÀ¸·Î
»ç¿ëÀÚ ÀÎÅÍÆäÀ̽º ÄÄÆ÷³ÍÆ®µéÀ» ·»´õ¸µÇÑ´Ù´Â Á¡ÀÌ´Ù. ("The major
players")
Struts¿Í JSFÀÇ ¸î¸î ±â´ÉµéÀº °ãÄ¡±â´Â ÇÏÁö¸¸ ´Ù¸¥ ¹æ½ÄÀ¸·Î º¸¿ÏÀÌ µÈ´Ù. ÀÌ ¼¼ ±â¼úÀÇ °áÇÕÀº À¥
¾ÖÇø®ÄÉÀ̼ÇÀ» °³¹ßÇÏ°í ÇÁ¸®Á¨Å×À̼ÇÀ» ±¸¼ºÇÏ°í Ä¿½ºÅÒ À¯Àú ÀÎÅÍÆäÀ̽º ÄÄÆ÷³ÍÆ®¸¦ ÇÁ·ÎÅäÄÝ°ú µ¶¸³ÀûÀ¸·Î ·»´õ¸µÇÏ´Â
È¿À²ÀûÀÎ ¹æ¹ýÀ» Á¦°øÇÒ ¼ö ÀÖ´Ù.
ÀÌ ±ÛÀÇ »ùÇà Äڵ带 ½ÇÇàÇÏ·Á¸é Struts 1.1, Tiles, JavaServer Faces
Reference Implementation (JSF-RI) Early Access Release 4.0,
Struts-Faces 0.4°¡ ÇÊ¿äÇÏ´Ù.
JSF JSF ¾ÖÇø®ÄÉÀ̼ÇÀº JSF ÇÁ·¹ÀÓ¿÷À» »ç¿ëÇÏ´Â
ÀϹÝÀûÀÎ J2EE À¥ ¾ÖÇø®ÄÉÀ̼ÇÀÌ´Ù. ÀÌ ÇÁ·¹ÀÓ¿÷Àº dzºÎÇÑ GUI ÄÄÆ÷³ÍÆ® ¸ðµ¨À» Á¦°øÇÑ´Ù. ¾î¶² ƯÁ¤ ±â¼úÀÌ
³î¶ó¿öµµ ·è¾ØÇÊÀº ´õ¿í ¹ßÀüÇÒ ÇÊ¿ä°¡ ÀÖ´Ù´Â ¸»À» µé¾îº»ÀûÀÌ ÀÖÀ» °ÍÀÌ´Ù. HTML ÄÄÆ÷³ÍÆ®·Î ÆòÀÌÇÑ ¹Ù´Ò¶ó
ÆäÀÌÁö°¡ ÀÖ´ø ½ÃÀýÀº Áö³ª°¬°í ¶Ù¾î³ GUI ·è¾ØÇÊÀ» ±¸ÇöÇÒ ¼ö ÀÖ´Ù. Æ®¸® ÄÄÆ÷³ÍÆ®, ¸Þ´º ÄÄÆ÷³ÍÆ®, ±×·¡ÇÁ´Â
±âÁ¸¿¡ Á¸ÀçÇß´ø UI ÄÄÆ÷³ÍÆ®ÀÌ°í ÀÌ°ÍÀº JSF°¡ ´ç¿¬È÷ Á¦°øÇØ¾ß ÇÏ´Â °ÍÀÌ´Ù. JSF´Â ÀÌ¿¡ ´õÇÏ¿© ½±°Ô
API¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Â ¹æ¹ýÀ» Á¦°øÇÏ¿© Ä¿½ºÅÒ ÄÄÆ÷³ÍÆ®ÀÇ »ý¼ºÀ» µ½´Â´Ù.
Note:
À§¿¡ ¾ð±ÞÇÑ UI ÄÄÆ÷³ÍÆ®´Â Sun¿¡¼ Á¦°øÇÑ »ùÇÃÀÇ ÀϺÎÀÌ´Ù.
Model-View-Controller (MVC) ÆÐÅÏÀ» »ç¿ëÇÏ´Â ÀüÅëÀûÀÎ À¥ ¾ÖÇø®ÄÉÀ̼ǿ¡¼, GUI
ÄÄÆ÷³ÍÆ®µéÀº ÇÁ¸®Á¨Å×À̼ǰú ºñÁö´Ï½º ·ÎÁ÷À» ÇÚµéÇÏ´Â Ä¿½ºÅÒ Å±׿¡ ÀÇÇØ Ç¥ÇöµÈ´Ù. À̴ Ŭ¶óÀ̾ðÆ® ÀåÄ¡±îÁö
ÄÚµùÇؾßÇÏ´Â ¹®Á¦¸¦ ³º¾Ò´Ù.
JSF´Â ±¸Á¶ÀûÀ¸·Î ÇÁ¸®Á¨Å×ÀÌ¼Ç ·ÎÁ÷°ú UI ÄÄÆ÷³ÍÆ®ÀÇ ºñÁö´Ï½º ·ÎÁ÷ÀÌ ºÐ¸®µÇ¾îÀÖ´Ù. JSP ÆäÀÌÁö¿¡¼
JSF ű׸¦ »ç¿ëÇÏ¿© ·»´õ·¯(RENDERER)¿Í UI ÄÄÆ÷³ÍÆ®¸¦ °áÇÕÇÒ ¼ö ÀÖ´Ù. ÇϳªÀÇ UI ÄÄÆ÷³ÍÆ®´Â ´Ù¸¥
·»´õ·¯¸¦ »ç¿ëÇÏ¿© ´Ù¾çÇÑ ¹æ½ÄÀ¸·Î ·»´õ¸µ µÉ ¼ö ÀÖ´Ù. UI ÄÄÆ÷³ÍÆ® ½ºÆÑÀÇ ÄÚµå´Â ¼¹ö¿¡¼ ½ÇÇàµÇ°í »ç¿ëÀÚ
¾×¼ÇÀ¸·Î »ý¼ºµÈ À̺¥Æ®¿¡ ÀÀ´äÇÑ´Ù.
JSF-RI´Â UI ÄÄÆ÷³ÍÆ®¿¡¼ HTMLÀ» ·»´õ¸µÇÏ´Â µ¥ ¾²ÀÌ´Â Ä¿½ºÅÒ ÅÂ±× ¶óÀ̺귯¸®¿Í ÇÔ²² ·»´õ ŶÀ»
Á¦°øÇÑ´Ù. ÄÄÆ÷³ÍÆ®µéÀÇ ·è¾ØÇÊÀ» Ä¿½ºÅ͸¶ÀÌ¡ ÇÏ´Â ±â´Éµµ Á¦°øÇÑ´Ù. Ưº°ÇÑ ÄÄÆ÷³ÍÆ®°¡ ÇÊ¿äÇϸé ƯÁ¤ Ŭ¶óÀ̾ðÆ®
ÀåÄ¡¿ë Ä¿½ºÅÒ Å±׸¦ ¸¸µé ¼ö ÀÖ°í UI ÄÄÆ÷³ÍÆ®¿Í Ä¿½ºÅÒ ·»´õ·¯¿Í À̸¦ °áÇÕÇÒ ¼ö ÀÖ´Ù. ´Ù¸¥ µð¹ÙÀ̽ºÀÇ °æ¿ì
´Ù¾çÇÑ ·»´õ·¯¸¦ ÁöÁ¤ÇÏ¸é µÈ´Ù.
JSF¿Í UI
ÄÄÆ÷³ÍÆ® Java AWT ¶Ç´Â Swing API¸¦ »ç¿ëÇÏ¿© Java GUI
¾ÖÇø®ÄÉÀ̼ÇÀ» ¸¸µç °æÇèÀÌ ÀÖ´Ù¸é JSFÀÇ UIComponent ¿¡µµ Àͼ÷ÇÒ °ÍÀÌ´Ù.
ÀÌ°ÍÀº ÀÚ½Ä ÄÄÆ÷³ÍÆ®ÀÇ Æ®¸®¸¦ ÀúÀåÇÏ°í Ŭ¶óÀ̾ðÆ® ÂÊ¿¡¼ ¹ß»ýÇÑ ¾×¼Çµé¿¡ ´ëÇØ Ç¥ÁØ À̺¥Æ®¸¦ ¸¸µç´Ù. ÀÌ
À̺¥Æ®µéÀº FacesContext ¿¡ ij½ÌµÈ´Ù. Ä¿½ºÅÒ Å±׸¦ »ç¿ëÇÏ¿© ÀÌµé °¢ À̺¥Æ®¿ë
Çڵ鷯µéÀ» °áÇÕÇÒ ¼ö ÀÖ´Ù. ¿¹¸¦ µé¾î Ä¿½ºÅÒ ActionListener °¡ ÀÖ´Ù¸é »ç¿ëÀÚ
Ŭ¸¯ ¶Ç´Â Çü½Ä Á¦ÃâÀ» ÇÚµéÇÏ°Ô µÈ´Ù.
JSF UIComponent , Renderer , ű״Â
¾ðÁ¦³ª ÇÔ²²ÇÑ´Ù. ¸ðµç JSF Ä¿½ºÅÒ Å±״ UIComponentTag ¸¦ ÇÏÀ§Å¬·¡½º·Î
³ª´®À¸·Î¼ »ý¼ºµÈ´Ù. doStart ¿Í doEnd ¸Þ¼Òµå´Â
UIComponentTag Ŭ·¡½º¿¡ ÀÌ¹Ì ±¸ÇöµÇ¾ú´Ù. ÀÌ ÅÂ±× Å¬·¡½º¿¡ Ãß°¡ ±â´É¸¸
Á¦°øÇÏ¸é µÈ´Ù.
±×¸² 1Àº Ä¿½ºÅÒ Å±×, UI ÄÄÆ÷³ÍÆ®, ·»´õ·¯ÀÇ °ü°èÀÌ´Ù. Ŭ¶óÀ̾ðÆ® ºê¶ó¿ìÀú°¡ UI ÄÄÆ÷³ÍÆ®
(MyComponent )¿ë JSF ű×(jsf:myTag )¸¦
ÀÌ¿ëÇÏ¿© JSP ÆäÀÌÁö¿¡ ¾×¼¼½ºÇÑ´Ù. UI ÄÄÆ÷³ÍÆ®´Â ¼¹ö¿¡¼ ½ÇÇàµÇ°í ÀûÀýÇÑ
·»´õ·¯(MyRenderer )¸¦ »ç¿ëÇÏ´Â HTML·Î¼ ´Ù½Ã Ŭ¶óÀ̾ðÆ®·Î ·»´õ¸µµÈ´Ù. JSP
ÆäÀÌÁö´Â HTML¿¡¼ À̵éÀ» ÄÚµùÇϱ⠺¸´Ù´Â JSF-RIÀÇ Ä¿½ºÅÒ Å±׸¦ »ç¿ëÇÏ¿© »ç¿ëÀÚ ÀÎÅÍÆäÀ̽º ÄÄÆ÷³ÍÆ®¸¦
Ç¥ÇöÇÑ´Ù.
¿¹¸¦ µé¾î, ±×¸² 1Àº h:panel:group ű×ÀÇ »ç¿ë¹æ¹ýÀ» º¸¿©ÁÖ°í ÀÖ´Ù.
ÀÌ Å±״ ÇÑ ºÎ¸ð ¹ØÀÇ ÄÄÆ÷³ÍÆ®µéÀ» ±×·ìÇÎÇϴµ¥ »ç¿ëµÈ´Ù. panel_grid ¿Í
panel_data °°Àº ´Ù¸¥ ÆгΠű׿ÍÀÇ °áÇÕ¿¡ »ç¿ëµÉ ¶§ ÀÌ°ÍÀº ·±Å¸Àӽà HTML
Å×À̺íÀÇ Ä®·³À» À§ÇÑ ¸¶Å©¾÷À» ¸¸µç´Ù. JSF-RI°¡ Á¦°øµÇ´Â html_basic
ÅÂ±× ¶óÀ̺귯¸®´Â ÅؽºÆ® Çʵå, ¹öÆ° µîÀÇ HTML ÄÄÆ÷³ÍÆ®¸¦ Ç¥ÇöÇϴµ¥ »ç¿ëµÈ´Ù.
±×¸² 1. JSF ÆäÀÌÁö ·»´õ¸µ
JSF ¼ö¸í
ÁÖ±â JSF ¼ö¸í ÁÖ±â´Â 6°³ÀÇ ´Ü°è·Î ±¸¼ºµÇ¾î ÀÖ´Ù. ÀÎÄ¿¹Ö ¸®Äù½ºÆ®´Â ¸ðµç °ÍÀ»
Åë°úÇϰųª ¸®Äù½ºÆ®, ¹ë¸®µ¥À̼Ç, ¼ö¸í ÁÖ±â¾È¿¡ ÀϾ´Â º¯È¯ ¿¡·¯, ÀÀ´ä À¯Çü¿¡ µû¶ó ¾î¶² ´Ü°èµµ Åë°úÇÏÁö
¾ÊÀ» ¼ö ÀÖ´Ù. JSP ÆäÀÌÁö¿¡¼ »ý¼ºµÈ faces
request´Â JSF ÇÁ·¹ÀÓ¿÷¿¡ ÀÇÇØ ÇÚµéµÇ°í faces ¶Ç´Â
non-faces ÀÀ´äÀÌ ¸®ÅϵȴÙ.
JSF Æû(form)ÀÌ Á¦ÃâµÇ°Å³ª »ç¿ëÀÚ°¡ URL¿¡ /faces ¶ó´Â
Á¢µÎ»ç¸¦ °¡Áø ÆäÀÌÁö¸¦ °¡¸£Å°´Â ¸µÅ©¸¦ Ŭ¸¯ÇÒ ¶§ faces
request°¡ ¹ß»ýÇÑ´Ù. ¸ðµç faces
request´Â FacesServlet ¿¡ ÀÇÇØ ÇÚµéµÈ´Ù.
¾î¶² JSF ÄÄÆ÷³ÍÆ®µµ ¾øÀÌ ¿äûÀÌ ¼ºí¸´À̳ª JSP ÆäÀÌÁö·Î º¸³»Áø ¸®Äù½ºÆ®´Â non-faces
request ¶ó°í ÇÑ´Ù. °á°ú ÆäÀÌÁö¿¡ JSF űװ¡ ÀÖÀ¸¸é faces
response ¶ó°í ÇÑ´Ù. JSF űװ¡ ¾øÀ¸¸é ÀÌ°ÍÀº non-faces
responseÀÌ´Ù.
JSF ¼ö¸í Áֱ⿡´Â ¿©¼¸ ´Ü°è°¡ ÀÖ´Ù:
- Reconstitute request tree(¸®Äù½ºÆ® Æ®¸® À籸¼º)
- Apply request values(¸®Äù½ºÆ® °ª Àû¿ë)
- Process validations(Ÿ´ç¼º °Ë»ç)
- Update model values(¸ðµ¨ °ª ¾÷µ¥ÀÌÆ®)
- Invoke application(¾ÖÇø®ÄÉÀÌ¼Ç È£Ãâ)
- Render response(ÀÀ´ä ·»´õ¸µ)
JSF ½ºÆÑ¿¡ µû¸£¸é °¢ ´Ü°è´Â ¸®Äù½ºÆ® ÇÁ·Î¼¼½Ì ¼ö¸íÁÖ±âÀÇ ³í¸®Àû °³³äÀ» ³ªÅ¸³»°í ÀÖ´Ù. ÇÏÁö¸¸
JSF-RI¿¡¼ ÀÌ ´Ü°èµéÀº ½ÇÁ¦ Ŭ·¡½º¿Í ÀÌ°ÍÀÇ À̸§À¸·Î Ç¥ÇöµÈ´Ù.
faces ¸®Äù½ºÆ®
´Ù·ç±â JSF ¸®Äù½ºÆ® ÇÁ·Î¼¼½ÌÀ» ÀÌÇØÇÏ·Á¸é FlightSearch.jsp¸¦ ¿¬±¸Çؾß
ÇÑ´Ù.(Listing 1)
JSF Çü½Ä¿¡´Â µµÂø/Ãâ¹ß µµ½Ã¿ë ÀÎDz ÅؽºÆ® Çʵå, Ãâ¹ß/µµÂø ³¯Â¥, Çü½Ä Á¦Ãâ ¹× ¸®¼Â¿ë ¹öÆ°ÀÌ Æ÷ÇԵǾî
ÀÖ´Ù.
¸®Äù½ºÆ®°¡ FacesServlet ¿¡ ÀÇÇØ ¹Þ¾Æµé¿©Áö¸é ÀÀ´äÀÌ Å¬¶óÀ̾ðÆ®¿¡°Ô·Î
·»´õ¸µµÇ±â Àü¿¡ ´Ù¾çÇÑ ´Ü°è¸¦ °ÅÄ£´Ù. ±×¸² 2´Â JSF
¸®Äù½ºÆ®°¡ 󸮵Ǵ ¹æ¹ýÀÌ´Ù.
1. ¸®Äù½ºÆ®
¹Þ±â
FacesServlet ˼
¸®Äù½ºÆ®¸¦ ¹Þ¾Æ FacesContextFactory ¿¡¼
FacesContext ÀÇ ÀνºÅϽº¸¦ ÃëÇÑ´Ù.
2. ¼ö¸í ÁÖ±â
ÇÁ·Î¼¼½Ì Àü´ÞÇϱâ
FacesServlet ˼
faces ÄÜÅؽºÆ®·Î Àü´ÞµÈ Lifecycle ±¸Çö¿¡ ´ëÇÑ
execute ¸Þ¼Òµå¸¦ È£ÃâÇÔÀ¸·Î¼ Lifecycle ÀÎÅÍÆäÀ̽º·Î
¼ö¸í ÁÖ±â ÇÁ·Î¼¼½ÌÀ» Àü´ÞÇÑ´Ù.
3. °¢ ´Ü°è ¸¶´Ù
¶óÀÌÇÁ»çÀÌŬ ½ÇÇà
Lifecycle
±¸ÇöÀº Reconstitute Component Tree ´Ü°è¸¦ ½ÃÀÛÀ¸·Î ÇÏ¿© °¢ ´Ü°è¸¦ ½ÇÇàÇÑ´Ù.
4. ÄÄÆ÷³ÍÆ® Æ®¸®
»ý¼º Reconstitute
Component Tree ´Ü°è¿¡¼ ÄÄÆ÷³ÍÆ® Æ®¸®°¡ travelForm ÀÇ ÄÄÆ÷³ÍÆ®µé°ú
ÇÔ²² ¸¸µé¾îÁø´Ù. ÀÌ Æ®¸®´Â ·çÆ®(root)·Î¼ UIForm À», ÀÌ°ÍÀÇ ÀÚ½ÄÀ¸·Î¼ ´Ù¾çÇÑ
ÅؽºÆ® Çʵå¿Í ¹öÆ°À» °®´Â´Ù.
fromCity Çʵå´Â °ø¹éÀÌ µÉ ¼ö ¾øÀ½À» ÁöÁ¤Çϴ Ÿ´ç¼º ±ÔÄ¢À» °®°íÀÖ´Ù.
(validate_required ű×) ÀÌ Å±״ JSF
Validator °¡ ÀÖ´Â fromCity ÅؽºÆ® Çʵ带
¸µÅ©ÇÑ´Ù.
JSF´Â ¿©·¯ ºôÆ®ÀÎ ¹ë¸®µ¥ÀÌÅÍ°¡ ÀÖ´Ù. »óÀÀÇÏ´Â Validator ´Â ÀÌ ´Ü°è¿¡¼
ÃʱâȵȴÙ. ÀÌ ÄÄÆ÷³ÍÆ® Æ®¸®´Â FacesContext ¿¡ ij½ÌµÇ°í ÄÜÅؽºÆ®´Â ´ÙÀ½
´Ü°è¿¡¼ »ç¿ëµÇ¾î Æ®¸®¿¡ ¾×¼¼½ºÇÏ°í À̺¥Æ® Çڵ鷯¸¦ È£ÃâÇÑ´Ù. UIForm ½ºÅ×ÀÌÆ®´Â
ÀÚµ¿À¸·Î ÀúÀåµÈ´Ù. µû¶ó¼ ÀÌ ÆäÀÌÁö°¡ ¸®ÇÁ·¹½¬ µÇ¸é ÀÌ Çü½ÄÀÇ ¿ø¸® ÄÜÅÙÃ÷°¡ µð½ºÇ÷¹À̵ȴÙ.
5. Æ®¸®¿¡¼ °ª
»Ì¾Æ³»±â Apply Request
Values ´Ü°è¿¡¼ JSF ±¸ÇöÀº ÄÄÆ÷³ÍÆ® Æ®¸®¸¦ Æ®·¡¹ö½ºÇÏ°í decode ¸Þ¼Òµå¸¦
»ç¿ëÇÏ¿© ¸®Äù½ºÆ®¿¡¼ °ªÀ» »Ì¾Æ °¢ ÄÄÆ÷³ÍÆ®¿¡ ¸Â°Ô ·ÎÄ÷Π¼³Á¤ÇÑ´Ù. ÀÌ ÇÁ·Î¼¼½º µ¿¾È ¿¡·¯°¡ ÀÖ´Ù¸é
FacesContext ¿¡ ³õÀ̰Եǰí Render Response ´Ü°è¿¡¼ »ç¿ëÀÚ¿¡°Ô
µð½ºÇ÷¹À̵ȴÙ.
¶ÇÇÑ »ç¿ëÀÚ ¾×¼ÇÀÇ °á°ú·Î ¸¸µé¾îÁ®¼ ÀÌ ´Ü°è¿¡ ³õÀÌ°Ô µÈ À̺¥Æ®µéÀº µî·ÏµÈ ¸®½º³Ê¿¡°Ô ºê·Îµåij½ºÆõȴÙ.
¸®Äù½ºÆ® ¹öÆ°À» Ŭ¸¯Çϸé ÅؽºÆ® ÇʵåÀÇ °ªÀÌ ¿ø·¡ °ªÀ¸·Î ¼³Á¤µÈ´Ù.
6. Process
Validations Process
Validations ´Ü°è¿¡¼ °¢ ÄÄÆ÷³ÍÆ®¿Í °ü·ÃµÈ ¹ë¸®µ¥À̼ÇÀº Apply Request Values ´Ü°è¿¡¼
¼³Á¤µÈ ·ÎÄà °ª¿¡ ´ëÇØ ¼öÇàÇÑ´Ù. ÀÌ°ÍÀº JSF ±¸ÇöÀÌ °¢°¢ÀÇ µî·ÏµÈ ¹ë¸®µ¥ÀÌÅÍ¿¡ ´ëÇØ
validate ¸Þ¼Òµå¸¦ È£ÃâÇÒ ¶§ ¹ß»ýÇÑ´Ù.
¹ë¸®µ¥À̼ÇÀÌ ½ÇÆÐÇÏ¸é ¼ö¸í ÁÖ±â´Â °°Àº ÆäÀÌÁö°¡ ·»´õ¸µµÇ´Â Render Response ´Ü°è·Î ÁøÇàµÈ´Ù.
ÇÏÁö¸¸ ¿¡·¯ ¸Þ½ÃÁöµµ ÇÔ²²´Ù. ÀÌ ´Ü°è¿¡¼ ³õ¿©Áø À̺¥Æ®µéÀº µî·ÏµÈ ¸®½º³Ê¿¡°Ô ºê·Îµåij½ºÆà µÈ´Ù.
JSF ±¸ÇöÀº ¼Ò½º Çʵ忡 ´ëÇÑ ¹ë¸®µ¥ÀÌÅ͸¦ ó¸®ÇÑ´Ù. µ¥ÀÌÅÍ°¡ ¹«È¿°¡ µÇ¸é ÄÜÆ®·ÑÀº Render
Response ´Ü°è·Î Àü´ÞµÇ´Âµ¥ ÀÌ°÷Àº FlightSearch.jsp°¡ °ü·Ã ÄÄÆ÷³ÍÆ®¿¡ ´ëÇØ µð½ºÇ÷¹À̵È
¹ë¸®µ¥ÀÌ¼Ç ¿¡·¯¿Í ÇÔ²² ´Ù½Ã ·»´õ¸µ µÇ´Â °÷ÀÌ´Ù. JSP ÆäÀÌÁö¿¡¼
output_errors ¸¦ ¼±¾ðÇÔÀ¸·Î¼ ÀÌ ÆäÀÌÁöÀÇ ¸ðµç ¿¡·¯´Â ÆäÀÌÁö ÇÏ´Ü¿¡
µð½ºÇ÷¹À̵ȴÙ.
7. ¸ðµ¨ °´Ã¼ °ª
¼³Á¤Çϱâ Update Model
Values ´Ü°è¿¡¼ ¸ðµç ¹ë¸®µ¥À̼ÇÀÌ ¼º°øÀûÀ¸·Î ó¸®µÈ ÈÄ¿¡ JSF ±¸ÇöÀº °¢ ÄÄÆ÷³ÍÆ®¿¡ ´ëÇÑ
updateModel ¸Þ¼Òµå¸¦ È£ÃâÇÏ¿© À¯È¿ÇÑ °ÍÀ¸·Î ¸ðµ¨ °´Ã¼ °ªÀ» ¼³Á¤ÇÑ´Ù. ·ÎÄÃ
µ¥ÀÌÅ͸¦ ¸ðµ¨ °´Ã¼ ¼Ó¼º¿¡ ÀÇÇØ ÁöÁ¤µÈ À¯ÇüÀ¸·Î º¯È¯ÇÏ´Â µ¿¾È ¿¡·¯°¡ ¹ß»ýÇÏ¸é ¼ö¸í ÁÖ±â´Â Render
Response ´Ü°è·Î ¿Å°Ü°£´Ù. ÀÌ°÷¿¡¼ ¿¡·¯°¡ µð½ºÇ÷¹À̵ȴÙ. Çü½Ä ÇÊµå ¼Ó¼ºÀÇ °ªÀº ¸ðµ¨ °´Ã¼ÀÇ ¾ÖÆ®¸®ºäÆ®
°ªÀ¸·Î ÆÄǽ·¹ÀÌÆ® µÈ´Ù.
8.
ActionListener È£Ãâ
ActionListener ¿Í
»ç¿ëÀÚ ¾×¼ÇÀ» °áÇÕÇÒ ¼ö ÀÖ´Ù.(Listing 1)
Invoke Application ´Ü°è¿¡¼ processAction ¸Þ¼Òµå´Â
FlightSearchActionListener ¿¡ È£ÃâµÈ´Ù. È£Ãâ ½Ã
processAction ¸Þ¼Òµå´Â ½ÇÁ¦ ½Ã³ª¸®¿À¿¡¼ ±âÁØ¿¡ ¸Â´Â ºñÇà µ¥ÀÌÅͺ£À̽º¸¦
°Ë»öÇÏ°í ÄÄÆ÷³ÍÆ®ÀÇ ¾×¼Ç ¾ÖÆ®¸®ºäÆ®¿¡¼ °á°ú¸¦ °Ë»öÇÑ´Ù.
9.ÀÀ´ä
·»´õ¸µ Render Respons
´Ü°è¿¡¼ faces ¼³Á¤ ÆÄÀÏ¿¡¼ °Ë»öµÇ¾î ¾ò¾îÁø ÆäÀÌÁö(FlightList.jsp)´Â faces ÄÜÅؽºÆ®¿¡
¿¡·¯°¡ ¾ø´Ù¸é µð½ºÇ÷¹À̵ȴÙ. ÀÌÀü ÆäÀÌÁöÀÇ ¿¡·¯ ¶§¹®¿¡ ÄÜÆ®·ÑÀÌ ÀÌ ´Ü°è¿¡ ¿À¸é
FlightSearch.jsp´Â ¿¡·¯ ¸Þ½ÃÁö¿Í ÇÔ²² ´Ù½Ã µð½ºÇ÷¹À̵ȴÙ.
±×¸² 2. JSF ¸®Äù½ºÆ®
ÇÁ·Î¼¼½º ±×¸²º¸±â. Listing 1. FlightSearch.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<f:use_faces>
<h:form id="flightForm" formName="flightForm" >
<h:input_text id="fromCity" valueRef="FlightSearchBean.fromCity">
<f:validate_required/>
<h:input_text/>
<h:input_text id="toCity" valueRef="FlightSearchBean.toCity">
<h:input_text id="departureDate"
valueRef="FlightSearchBean.departureDate">
<h:input_text id="arrivalDate"
valueRef="FlightSearchBean.arrivalDate">
<h:command_button id="submit" action="success"
label="Submit" commandName="submit" >
<f:action_listener
type="foo.bar.FlightSearchActionListener"/>
</h:command_button>
<h:command_button id="reset" action="reset" label="Reset"
commandName="reset" />
<h:output_errors/>
</h:form>
</f:use_faces>
|
JSF-RIÀÇ µÎ °³ÀÇ ÅÂ±× ¶óÀ̺귯¸®°¡ ÀÌ Äڵ忡 »ç¿ëµÈ´Ù. html_basic
ÅÂ±× ¶óÀ̺귯¸®´Â ÀϹÝÀûÀ¸·Î »ç¿ëµÇ´Â HTML ÄÄÆ÷³ÍÆ®¿ë ű׸¦ Á¤ÀÇÇÏ°í jsf-core ű×
¶óÀ̺귯¸®¿¡´Â ¸®½º³Ê¿Í º§¸®µ¥ÀÌÅ͸¦ µî·ÏÇϴµ¥ »ç¿ëµÇ´Â űװ¡ Æ÷ÇԵǾî ÀÖ´Ù. ±âŸ ű׷δÂ:
f:use_faces ű״ JSF ±¸Çö¿¡ ÀÌ Å±װ¡ faces ű׶ó´Â °ÍÀ»
°¡¸£Å²´Ù.
f:validate_required ű״ ¾îÅÂÄ¡ µÇ´Â Çʵ尡 Çü½ÄÀÌ Á¦ÃâµÇ±â
Àü¿¡ °ªÀ» °¡Á®¾ß ÇѴٴ°ÍÀ» ³ªÅ¸³½´Ù.
h:form °ú h:input_text ű״Â
flightSearchForm À̶ó°í ÇÏ´Â HTML Çü½Ä°ú ´Ù¾çÇÑ ÅؽºÆ® Çʵ带 °¢°¢
³ªÅ¸³½´Ù.
h:command_button ű״ Submit°ú Reset¹öÆ°À» ±¸Çö¿¡
»ç¿ëµÈ´Ù.
- ¸¶Áö¸·À¸·Î
h:output_errors ű״ Struts
html:errors ÅÂ±×¿Í ºñ½ÁÇÏ°í Çü½Ä ÇʵåÀÇ ¹ë¸®µ¥ÀÌ¼Ç µ¿¾È ¹ß»ýÇÑ ¿¡·¯¸¦
µð½ºÇ÷¹ÀÌÇÑ´Ù.
FlightSearchBeanÀ̶ó°í ÇÏ´Â JavaBeanÀº Updated Model Values ´Ü°è¿¡
ÀÖ´Â µ¿¾È UIComponent µ¥ÀÌÅÍ ºÎÅÍ ¾÷µ¥ÀÌÆ®µÇ´Â ¸ðµ¨À» ³ªÅ¸³½´Ù. ÀϹÝÀûÀ¸·Î
JavaBeanÀº jsp:useBean ÅÂ±×¿Í ÇÔ²² JSP ÆäÀÌÁö¿¡¼ ¼±¾ðµÈ´Ù.
FlightSearch.jsp¿¡¼ ¼öÇàµÇÁö ¾Ê¾Ò´Ù´Â °Í¿¡ ÁÖ¸ñÇ϶ó. faces ¼³Á¤ ÆÄÀÏÀÇ JSP ÆäÀÌÁöµé¿¡
ÀÇÇØ »ç¿ëµÇ´Â ¸ðµç JavaBean ÄÄÆ÷³ÍÆ®µéÀ» ¼±¾ðÇÒ ¼ö ÀÖ´Â °÷¿¡¼ Managed
Beans ¶ó°í ÇÏ´Â JSF ±â´ÉÀ» »ç¿ëÇÒ ¼ö Àֱ⠶§¹®ÀÌ´Ù. ¼³Á¤ÇÒ ¶§ ¼ºí¸´ ÄÜÅ×À̳ʴ ÀÌ·¯ÇÑ
JavaBean ÄÄÆ÷³ÍÆ®¸¦ ÃʱâÈÇÑ´Ù. faces-config.xml ÆÄÀÏÀÇ FlightSearchBean¿ë
¿£Æ®¸®´Â Listing 2¿¡ ³ªÅ¸³ªÀÖ´Ù: Listing 2.
TravelInfoBean¿ë faces-config.xml ¿£Æ®¸®
<managed-bean>
<managed-bean-name>FlightSearchBean</managed-bean-name>
<managed-bean-class>
foo.bar.FlightSearchBean
</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
|
faces ÀÀ´ä ·»´õ¸µ °á°ú JSP ÆäÀÌÁöµéÀÌ JSF ű׸¦
Æ÷ÇÔÇÏ°í ÀÖÀ» ¶§ faces ÀÀ´äÀº Faces ¾ÖÇø®ÄÉÀ̼ǿ¡ ÀÇÇØ »ý¼ºµÈ´Ù. ÀÌ ÀÀ´äÀº faces ¶Ç´Â
non-faces ¸®Äù½ºÆ®ÀÇ °á°ú°¡ µÉ ¼ö ÀÖ´Ù.
¿ì¸® ¿¹Á¦¿¡¼ Listing 1ÀÇ ÆäÀÌÁö ·»´õ¸µÀº faces ÀÀ´äÀÌ´Ù.
doStartTag() ¿Í doEndTag() ¸Þ¼Òµå¿¡ Àͼ÷ÇÒ
°ÍÀÌ´Ù. JSF¿Í Struts-Faces¿¡¼ °¢ ű״ UIComponentTag ¿¡¼
È®ÀåµÈ´Ù. UIComponentTag ´Â doStartTag() ¿Í
doEndTag() ¸Þ¼Òµå¸¦ ±¸ÇöÇÑ´Ù.
¶ÇÇÑ Ãß»ó ¸Þ¼ÒµåÀÎ getComponentType() °ú
getRendererType() À» °®°íÀÖ´Ù. ÀÌ ±¸Ã¼Àû ÅÂ±× Å¬·¡½º¿¡ ÀÌ µÎ °³ÀÇ
¸Þ¼Òµå¸¦ ±¸ÇöÇÔÀ¸·Î¼ ÄÄÆ÷³ÍÆ®¿Í ·»´õ·¯¸¦ °¢°¢ ÁöÁ¤ÇÒ ¼ö ÀÖ´Ù.
ÅؽºÆ® Çʵ带 °¡Áø JSF Çü½ÄÀ» »ý°¢Çغ¸ÀÚ. ´ÙÀ½ ¼ø¼´Â JSF Çü½ÄÀÌ ·»´õ¸µ µÉ ¶§ ½ÇÇàµÈ´Ù.
1.
doStartTag() ¸Þ¼Òµå È£ÃâÇϱâ Servlet ÄÜÅ×À̳ʴÂ
FormTag ¿¡ doStartTag() ¸Þ¼Òµå¸¦ È£ÃâÇÑ´Ù.
2.
UIComponent ¾ò±â
FormTag ´Â
getComponentType() ¸Þ¼Òµå¿¡¼
UIComponent ¸¦ ¾ò´Â´Ù. UIComponentTag ´Â
getComponentType() À» »ç¿ëÇÏ¿© faces-config.xml ÆÄÀϷκÎÅÍ ÀÌ
ÄÄÆ÷³ÍÆ®¿¡ ´ëÇÑ Å¬·¡½º À̸§À» »ìÇÇ°í UIComponent(FormComponent) ÀÇ
ÀνºÅϽº¸¦ ¸¸µç´Ù.
3. ·»´õ·¯
¾ò±â
FormTag ´Â
getRendererType ¸Þ¼Òµå¿¡¼ Renderer ¸¦ ¾ò´Â´Ù.
ÄÄÆ÷³ÍÆ® À¯Çü¿¡¼Ã³·³ ·»´õ·¯ À̸§Àº faces-config.xml ÆÄÀÏ¿¡¼ °Ë»öµÈ´Ù.
4.ÀÎÄÚµù ¸Þ¼Òµå
È£Ãâ
FormComponent ¿Í
FormRenderer °¡ ¸¸µé¾îÁø ÈÄ¿¡ encodeBegin()
¸Þ¼Òµå´Â FormComponent ¿¡ È£ÃâµÈ´Ù. °¢ ű׸¦ À§ÇØ ·»´õ¸µÀº
encodeBegin() À¸·Î ½ÃÀÛÇÏ°í encodeEnd() ·Î
³¡³´Ù. encodeBegin() ¸Þ¼Òµå´Â Áßø ¼ø¼·Î È£ÃâµÈ´Ù.
5. ű×ÀÇ ³¡°ú
HTML ·»´õ¸µ ¼ºí¸´ ÄÁÅ×À̳ʴ ÀÌ Å±׿¡
´ëÇØ doEndTag() ¸Þ¼Òµå¸¦ È£ÃâÇÑ´Ù. encodeEnd()
¸Þ¼Òµå´Â °¢ ÄÄÆ÷³ÍÆ®¿¡ ´ëÇØ ÁßøÀÇ ¿ª¼øÀ¸·Î È£ÃâµÈ´Ù. °á±¹ Form°ú ¸ðµç ÁßøµÈ ÄÄÆ÷³ÍÆ®µéÀº HTML·Î¼
·»´õ¸µµÈ´Ù. ÀÌ ÁöÁ¡¿¡¼ HTML »ý¼ºÀº Á¾·áµÇ°í JSP¿Í µ¿µîÇÑ HTMLÀÌ ·»´õ¸µµÈ´Ù.
±×¸² 3Àº faces ÀÀ´äÀÇ »ý¼ºÀ» ±¸¼ºÇÏ´Â À̺¥Æ® ¼ø¼ÀÌ´Ù.
±×¸² 3. faces ÀÀ´ä
·»´õ¸µ ±×¸²º¸±â.
ÅëÇÕÀÇ
ÀÌÀ¯ JSP¿Í °ü·Ã ½ºÆÑÀÌ ¹ßÀüÇÔ¿¡ µû¶ó JSF¿Í JSP Standard Tag
Library °°Àº »õ·Î¿î Ç¥ÁØÀÌ µîÀåÇÏ°í ÀÖ´Ù. ´ÙÀ½Àº ÀÌ »õ·Î¿î ±â¼úµéÀ» ÇϳªÀÇ ÅëÇÕµÈ Àüü·Î¼ »ç¿ëÇÒ ¶§ÀÇ
ÀÌÁ¡µéÀÌ´Ù:
- ÀÛµ¿°ú ÇÁ¸®Á¨Å×À̼ÇÀÇ ±ú²ýÇÑ ºÐ¸®. ű×, ·»´õ·¯, ÄÄÆ÷³ÍÆ®ÀÇ ºÐ¸®·Î ÆäÀÌÁö ÀÛ¼ºÀÚ¿Í
¾ÖÇø®ÄÉÀÌ¼Ç °³¹ßÀÚÀÇ ¿ªÇÒÀº Á¤ÀÇ°¡ ´õ ºÐ¸íÇØÁø´Ù.
- ÄÄÆ÷³ÍÆ®ÀÇ ÇÁ¸®Á¨Å×ÀÌ¼Ç º¯°æÀÌ Å« ¿µÇâÀ» ³¢Ä¡Áö ¸øÇÑ´Ù. ÀÌÁ¦´Â ·»´õ·¯¸¸ ½±°Ô º¯°æÇϸé
µÈ´Ù. ÀüÅëÀûÀÎ MVC ¸ðµ¨¿¡¼ ű×ÀÇ ¸ðµç º¯°æÀº ºñÁö´Ï½º ·ÎÁ÷ÀÇ º¯°æ±îÁö ¼ö¹ÝÇß´Ù.
- ·»´õ·¯ µ¶¸³. ´ÙÁßÀÇ ·»´õ·¯·Î ´ÙÁßÀÇ ÇÁ¸®Á¨Å×ÀÌ¼Ç µð¹ÙÀ̽º¿ë ÄÄÆ÷³ÍÆ® ·ÎÁ÷À»
Àç»ç¿ëÇÔÀ¸·Î¼ ÇÁ·ÎÅäÄÝ µ¶¸³µµ °¡´ÉÇÏ´Ù. ´Ù¾çÇÑ ·»´õ·¯¸¦ »ç¿ëÇÒ ¼ö ÀÖ´Ù´Â °ÍÀº ƯÁ¤ µð¹ÙÀ̽º¿¡ ´ëÇÑ Àüü
ÇÁ¸®Á¨Å×ÀÌ¼Ç Æ¼¾îÀÇ ÄÚµù Çʿ伺µµ °¨¼ÒÇÑ´Ù´Â °ÍÀ» ÀǹÌÇÑ´Ù.
- Ä¿½ºÅÒ ÄÄÆ÷³ÍÆ®ÀÇ ¾î¼Àºí¸µ°ú Àç»ç¿ë Ç¥ÁØ. JSF´Â "Çü½Ä°ú Çʵå"¸¦ ³Ñ¾î »ý°¢ÇÏ°í
Ä¿½ºÅÒ GUI ÄÄÆ÷³ÍÆ® ·»´õ¸µ¿¡ dzºÎÇÑ ÄÄÆ÷³ÍÆ® ¸ðµ¨À» Á¦°øÇÑ´Ù. JSF¸¦ »ç¿ëÇÏ¿© °¢ ÆäÀÌÁö¸¶´Ù ÄÄÆ÷³ÍÆ®ÀÇ
¸ð½À°ú ÀÛµ¿À» Ä¿½ºÅ͸¶ÀÌ¡ ÇÒ ¼ö ÀÖ´Ù. °³¹ßÀÚµéÀº ±×µé¸¸ÀÇ GUI ÄÄÆ÷³ÍÆ®¸¦ ¸¸µé ¼ö ÀÖ´Â µ¥´Ù°¡ °£´ÜÇÑ
Ä¿½ºÅÒ Å±׷Π¸ðµç JSP ÆäÀÌÁö¿¡ ½±°Ô Æ÷ÇÔ½Ãų ¼ö ÀÖ´Ù. ÀÚ¹Ù ÇÁ·ÐÆ®¿£µå GUI ÄÄÆ÷³ÍÆ®ÀÎ AWT¿Í
Swing°ú ¸¶Âù°¡Áö·Î À¥ ÆäÀÌÁö¿¡ ´ëÇÑ Ä¿½ºÅÒ ÄÄÆ÷³ÍÆ®µéÀÌ ÀÖ´Ù!
Struts´Â ÀÌ¹Ì »ç¿ëÀÚ ±â¹ÝÀÌ ³Ð°Ô Çü¼ºµÇ¾î ÀÖ´Â ÇÁ·¹ÀÓ¿÷ÀÌ´Ù. ¸¹Àº IT ºÎ¼µéÀº MVC ÇÁ·¹ÀÓ¿÷ÀÇ
°¡Ä¡¸¦ ÀνÄÇß°í ²Ï ¿À·§µ¿¾È »ç¿ëÇØ¿Ô´Ù. JSF´Â StrutsÀÇ °·ÂÇÑ ÄÁÆ®·Ñ·¯ ¾ÆÅ°ÅØÃĸ¦ °®°íÀÖÁö ¾Ê´Ù.
¸¶Âù°¡Áö·Î Ç¥ÁØÈµÈ ActionForm °ú Actions µµ ¾ø´Ù.
Tiles¸¦ ÅëÇÕÇÏ¸é ¿Ïº®ÇÑ ¹æ½ÄÀ¸·Î ·¹À̾ƿôÀ» Àç»ç¿ë ¹× º¯°æÇÒ ¼ö ÀÖ´Ù.
JSF°¡ °¡´ÉÇÑ Struts ¾ÖÇø®ÄÉÀ̼ÇÀÇ ¸¶À̱׷¹À̼ÇÀº µÎ °¡Áö µµÀü°úÁ¦°¡ ÀÖ´Ù. Çϳª´Â Struts
űװ¡ JSF ȣȯÀÌ ¾Æ´Ï¶ó´Â Á¡ÀÌ´Ù. ´Ù½Ã¸»Çϸé JSF ½ºÆÑ¿¡¼ ¿ä±¸ÇÏ´Â ´ë·Î
UIComponentTag ¸¦ È®ÀåÇÏÁö ¾Ê´Â´Ù. µû¶ó¼ JSF´Â
UIComponent ¿Í Renderers ¸¦ Çؼ®ÇÒ ¼öµµ °áÇÕÇÒ
¼öµµ ¾ø´Ù.
µÎ ¹ø°, FacesServlet °ú RequestProcessor
»çÀÌ¿¡ ¾î¶² ¿¬°áµµ ¾ø´Ù. Struts ¾ÖÇø®ÄÉÀ̼ǿ¡¼
RequestProcessor ´Â ÄÝ¹é ¸Þ¼Òµå·Î
ActionForm °ú Actions Ŭ·¡½º·ÎÀÇ ¸ð½ÀÀ» °ü¸®ÇÑ´Ù.
ActionForm ÇÁ·ÎÆÛƼ¿ë °ÔÅÍ¿Í ¼¼ÅÍ¿Í validate() ´Â
ActionForm ÀÇ ÄÝ¹é ¸Þ¼ÒµåÀÌ´Ù. Action ÀÇ °æ¿ì
execute() °¡ ÄÝ¹é ¸Þ¼ÒµåÀÌ´Ù.
RequestProcessor °¡ È£ÃâµÇÁö ¾Ê´ÂÇÑ Struts
ActionForm °ú Actions Ŭ·¡½ºÀÇ ÄÝ¹é ¸Þ¼Òµå´Â
ºñÁö´Ï½º ·ÎÁ÷À» È£ÃâÇÒ ±âȸ¸¦ °¡Áú ¼ö ¾ø´Ù.
Struts¿Í JSF¸¦ Struts-Faces¿Í ÅëÇÕÇϱâ ÀÌÂëµÇ¸é,
Struts¿Í JSF¸¦ ÅëÇÕÇÒ ¼ö ÀÖ´Â ¼ÒÇÁÆ®¿þ¾î°¡ ÀÖ´Ù¸é ¶Ç´Â ÅëÇÕ ¼ÒÇÁÆ®¿þ¾î¸¦ Á÷Á¢ ÀÛ¼ºÇÏ´Â ¹æ¹ý¿¡ ´ëÇØ
±Ã±ÝÇÒ °ÍÀÌ´Ù.
ÁÁÀº ¼Ò½ÄÀÌ ÀÖ´Ù. ¼ÒÇÁÆ®¿þ¾î´Â ÀÌ¹Ì Á¸ÀçÇÏ°í ÀÖ´Ù. Struts-Faces´Â
Struts JSF ÅëÇÕ ¶óÀ̺귯¸®ÀÇ Ãʱ⠸±¸®½ºÀÌ´Ù. ÀÌ ¶óÀ̺귯¸®´Â Craig McClanahanÀÌ ¸¸µé¾ú°í
±âÁ¸ Struts ¾ÖÇø®ÄÉÀ̼ÇÀ» JSF¿¡ ¸¶À̱׷¹À̼ÇÇÒ ¼ö ÀÖµµ·Ï Çß´Ù. Struts-Faces´Â JSF¸¦
ÀÌ¿ëÇÑ ±ò²ûÇÑ ÅëÇÕÀ» À§ÇØ ³ë·ÂÇÏ°í ÀÖ´Ù. JSF°¡ ÇÁ·ÐÆ®¿£µå¿¡¼ »ç¿ëµÇ°í ¹é¿£µå¿¡´Â Àͼ÷ÇÑ Struts
ÄÄÆ÷³ÍÆ®°¡ ÀÖµµ·Ï ¸»ÀÌ´Ù.
±×¸² 4´Â Struts-Faces¿Í JSF Ŭ·¡½º °ü°èÀÌ´Ù. ÆĶõ»ö Ŭ·¡½ºµéÀº Struts-Faces¿¡
¼ÓÇÑ´Ù.
±×¸² 4.
Struts-Faces Ŭ·¡½º ´ÙÀ̾î±×·¥ ±×¸²º¸±â.
´ÙÀ½Àº Struts-FacesÀÇ ÁÖ¿ä ÄÄÆ÷³ÍÆ®µéÀÌ´Ù:
FacesRequestProcessor Ŭ·¡½º´Â ¸ðµç faces ¸®Äù½ºÆ®¸¦
ÇÚµéÇÑ´Ù. Non-faces ¸®Äù½ºÆ®´Â ºÎ¸ðÀÎ RequestProcessor ·Î
º¸³»Áø´Ù.
ActionListenerImpl Ŭ·¡½º´Â
ActionEvents ¸¦ ÇÚµéÇÑ´Ù.
FormComponent ´Â JSF Form Component ·Î ºÎÅÍ
È®ÀåÇÏÁö¸¸ Struts ¼ö¸í Áֱ⠳»¿¡ È£ÃâµÈ´Ù.
- ·»´õ·¯
FormComponent ¿ë ű×.
- ¾Æ¿ôDz Àü¿ëÀ¸·Î ·»´õ¸µµÇ´Â µ¥ÀÌÅÍ¿ë ÅÂ±×¿Í ·»´õ·¯.
ServletContextListener ÀÇ ±¸ÇöÀº ÃʱâÈ µ¿¾È ÀûÀýÇÑ
RequestProcessor ¸¦ µî·ÏÇÑ´Ù.
- filefaces-config.xml ÆÄÀÏ. struts-faces.jar ÆÄÀÏ¿¡ ¹øµéµÈ´Ù.
Listing 3Àº Struts-Faces ű׸¦ »ç¿ëÇÏ´Â FlightSearch.jsp ÀÌ´Ù. Listing 3. Struts-Faces ű׸¦ »ç¿ëÇÏ´Â
FlightSearch.jsp
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-faces"
prefix="s" %>
<f:use_faces>
<s:form action="/listFlights">
<h:input_text id="fromCity" valueRef="FlightSearchForm.fromCity"/>
<h:input_text id="toCity" valueRef="FlightSearchForm.toCity"/>
<h:input_text id="departureDate"
valueRef="FlightSearchForm.departureDate">
<h:input_text id="arrivalDate"
valueRef="FlightSearchForm.arrivalDate">
<h:command_button id="submit" action="success" label="Submit"
commandName="submit" />
<h:command_button id="reset" action="reset" label="Reset"
commandName="reset" />
<s:errors/>
</s:form>
</f:use_faces>
|
s:form ű״ HTML Çü½ÄÀ» ¸¸µå´Âµ¥ »ç¿ëµÈ´Ù. ÀÌ Çü½Ä ¾×¼Ç ¾ÖÆ®¸®ºäÆ®´Â
Listing 1¿¡
ÁöÁ¤µÈ Çü½Ä À̸§ flightForm
´ë½Å /listFlights
ÀÌ´Ù. JSF¿¡¼ Çü½Ä À̸§Àº UIForm¿¡ ÇÒ´çµÈ À̸§ÀÏ »ÓÀÌ´Ù.
FlightSearchBean Àº JSF Form¿ë ¸ðµ¨ÀÌ°í Update Model
Values ´Ü°è¿¡¼ °ªÀ» ¾ò´Â´Ù. ÇÏÁö¸¸ Struts¿¡¼ Çü½Ä ¾×¼ÇÀº Struts Configuration
File, struts-config.xmlÀÇ ActionMapping À» °¡¸£Å²´Ù. ÀÛµ¿
¹æ¹ýÀ» ¾Ë·Á¸é Listing 4ÀÇ struts-config.xml ÆÄÀÏÀ» ÂüÁ¶ÇÑ´Ù.
/listFlights
¿ë ActionMapping ÀÌ, URI-path¿ë
ActionForm ÀÌ foo.bar.FlightSearchForm
ÀÌ°í Action Ŭ·¡½º´Â
foo.bar.FlightSearchAction À» ³ªÅ¸³½´Ù´Â °ÍÀ» ¾Ë°ÔµÉ °ÍÀÌ´Ù. Listing 4. struts-config.xmlÀÇ Action
¼±¾ð
<form-bean name="FlightSearchForm"
type="foo.bar.FlightSearchForm"/>
<!-- ========== Action Mapping Definition ========================= -->
<action-mappings>
<!-- List Flights action -->
<action path="/listFlights"
type="foo.bar.FlightSearchAction"
name="FlightSearchForm"
scope="request"
input="/faces/FlightSearch.jsp">
<forward name="success" path="/faces/FlightList.jsp"/>
</action>
</action-mappings>
|
Struts¿Í Tiles¸¦ ÅëÇÕÇÏ´Â ´Ù¼¸
´Ü°è
1. JSP¸¦ ¸¸µé¾î »çÀÌÆ® ·¹À̾ƿôÀ» Ç¥ÇöÇÑ´Ù. ÀÌ°ÍÀÌ ¸¶½ºÅÍ JSP·Î¼ Çì´õ, ¹Ùµð, DzÅ͸¦
À§ÇÑ Ç÷¹À̽ºÈ¦´õ¸¦ °®°íÀÖ´Ù. ÀÌµé °¢°¢Àº Tiles ű׸¦ »ç¿ëÇÏ¿© ¸ÞÀÎ JSP ÆäÀÌÁö¿¡
Ãß°¡µÈ´Ù.
2. Tiles Á¤ÀÇ ÆÄÀÏÀ» ¸¸µé°í ¾î¶² JSP ÆäÀÌÁö°¡ Àüü ÆäÀÌÁöÀÇ Ç÷¹À̽ºÈ¦´õ¿¡ Æ÷ÇԵǾî¾ß
ÇÏ´ÂÁö¸¦ Á¤ÇÑ´Ù. ¸ðµç ÆäÀÌÁö¸¦ °íÀ¯ÀÇ À̸§À¸·Î ÁöÁ¤ÇÑ´Ù.
3. struts-config.xml ÆÄÀÏ¿¡¼ ±Û·Î¹ú°ú ·ÎÄà Æ÷¿öµå¸¦ º¯°æÇÏ¿© ÀÌÀü ´Ü°è¿¡¼
ÁöÁ¤ÇÑ °íÀ¯ À̸§µéÀ» »ç¿ëÇÑ´Ù.
4. TilesPlugIn À» »ç¿ëÇÏ¿© ½ÃÀÛÇÏ´Â µ¿¾È Tiles Á¤ÀÇ
ÆÄÀÏÀ» ·ÎµùÇÑ´Ù. TilesPlugIn ¿£Æ®¸®¸¦
struts-config.xml ÆÄÀÏ¿¡ Ãß°¡ÇÑ´Ù.
5. TilesRequestProcessor ¿£Æ®¸®¸¦
struts-config.xml ÆÄÀÏ¿¡ Ãß°¡ÇÑ´Ù. ÀÌ°ÍÀÌ Tiles-Struts ¾ÖÇø®ÄÉÀÌ¼Ç¿ë µðÆúÆ®
¿äû ÇÁ·Î¼¼½ºÀÌ´Ù. |
.do¿¡
¾×¼Ç ¾ÖÆ®¸®ºäÆ®°¡ ¾ø´Â°ÍÀ» ´«Ä¡Ã«À» °ÍÀÌ´Ù. Struts-Faces°¡ Çü½Ä À̸§À¸·Î Çü½Ä ¾×¼ÇÀ» »ç¿ëÇϱâ
¶§¹®ÀÌ´Ù.
¶ÇÇÑ JSF validation ű׸¦ ¿©±â¼´Â »ç¿ëÇÏÁö ¾Ê¾Ò´Ù. Struts¿¡¼
¹ë¸®µ¥À̼ÇÀº ActionForm Ŭ·¡½º¿¡ ´ëÇÑ validate()
¸Þ¼Òµå¿¡¼ ¹ß»ýÇϱ⠶§¹®ÀÌ´Ù. s:errors ű״ Struts ¿¡·¯ ÅÂ±×¿Í ºñ½ÁÇÏ°í
¹ë¸®µ¥ÀÌ¼Ç µ¿¾È ¹ß»ýÇÑ ¿¡·¯ ¸Þ½ÃÁö¸¦ µð½ºÇ÷¹ÀÌÇϴµ¥ »ç¿ëµÈ´Ù.
¾î¶² ActionListener µµ Submit ¹öÆ°°ú °áÇÕµÇÁö ¾Ê¾Ò´Ù.
ActionListener °¡ ÀÌ¹Ì Struts-Faces¿¡ Á¦°øµÇ°í ¾ðÁ¦³ª
ActionEvents¿Í ÇÔ²² faces ¸®Äù½ºÆ®¸¦
FacesRequestProcessor ·Î º¸³»±â ‹š¹®ÀÌ´Ù.
Struts ¾ÖÇø®ÄÉÀ̼ÇÀ» JSF¿¡
¸¶À̱׷¹ÀÌ¼Ç Çϱ⠴ÙÀ½Àº Struts À¥ ¾ÖÇø®ÄÉÀ̼ÇÀ» JSF¿Í ÅëÇÕÇÏ´Â
´Ü°èÀÌ´Ù:
- JSF-specific JARs (jsf-api.jar, jsf-ri.jar)¿Í ÇÔ²²
struts-faces.jar ÆÄÀÏÀ» À¥ ¾ÖÇø®ÄÉÀ̼ÇÀÇ WEB-INF/lib µð·ºÅ丮¿¡
Ãß°¡ÇÑ´Ù.
- JSF¿Í JSTLÀ» »ç¿ë ÇÒ °èȹÀ̸é JSTL-specific JARs (jstl.jar,
standard.jar)¸¦ WEB-INF/lib Æú´õ¿¡ Ãß°¡ÇÑ´Ù. ÀÌ ´Ü°è´Â ÀϹÝÀû
Tomcat¿¡ Àü°³ ÇÒ °æ¿ì¿¡¸¸ ÇÊ¿äÇÏ´Ù. JWSDP´Â ÀÌ¹Ì ÀÌ·¯ÇÑ JAR¸¦ Á¦°øÇÑ´Ù.
- À¥ ¾ÖÇø®ÄÉÀÌ¼Ç Àü°³ µð½ºÅ©¸³ÅÍ (/WEB-INF/web.xml)¸¦ º¯°æÇÏ¿© Faces
Servlet Á¤ÀÇ(Listing 5)¿ë ¿£Æ®¸®¸¦ °®´Â´Ù.
- JSP ÆäÀÌÁö¸¦ º¯°æÇÏ¿© Struts ÅÂ±× ´ë½Å JSF¿Í Struts-Faces ű׸¦ »ç¿ëÇÑ´Ù.
ƯÈ÷
html , base , form ,
errors ű׸¦ Struts-FacesÀÇ ÇØ´çÇÏ´Â °ÍÀ¸·Î ´ëüÇÑ´Ù.
text , textarea , radio
ű׸¦ ÀÌ¿¡ »óÀÀÇÏ´Â JSF ű׷Π´ëüÇÑ´Ù. Struts-Faces´Â À̸¦ À§ÇÑ °³º° ű׸¦ °®°íÀÖÁö
¾Ê´Ù. Çʼö»çÇ×Àº ¾Æ´ÏÁö¸¸ Struts Logic ű׸¦ ÇØ´ç JSTL ű׷Π´ëüÇÏ´Â °Íµµ °í·ÁÇÒ ¼ö
ÀÖ´Ù.
- JSF ű׸¦ »ç¿ëÇÏ°í struts-config.xml ÆÄÀÏÀ» º¯°æÇÏ¿© JSPÀ» °¡¸£Å°´Â Action
MappingsÀÇ global-forwards ¿Í local-forwardsÀÇ
/faces Á¢µÎ»ç¸¦ Ãß°¡ÇÑ´Ù.
- À¥ ¾ÖÇø®ÄÉÀ̼ÇÀÌ ÀÚ½ÅÀÌ ¸¸µç Ä¿½ºÅÒ ÄÄÆ÷³ÍÆ®¸¦ »ç¿ëÇÑ´Ù¸é À̵éÀ» JSF ±¸ÇöÀÇ µðÆúÆ®
RenderKitÀ¸·Î µî·ÏÇؾßÇÑ´Ù. WEB-INF Æú´õÀÇ faces-config.xml¿¡ ÆÄÀÏÀ»
¸¸µé°í °¢ ÄÄÆ÷³ÍÆ®¿Í ·»´õ·¯¿ë ¿£Æ®¸®¸¦ Ãß°¡ÇÏ¿© ¼öÇàÇÑ´Ù. ÇÏÁö¸¸ faces-config.xml ÆÄÀÏÀº
Struts-FacesÀÚ ÆÄÀÏ¿¡ ÀÌ¹Ì ¹øµéµÇ¾î ÀÖ´Ù. struts-faces.jar ÆÄÀÏ¿¡¼ À̸¦ »©¾î³»¾î
ÄÜÅÙÃ÷¿¡ Ãß°¡ÇÏ°í WEB-INF Æú´õ ¹Ø¿¡ ³õ´Â´Ù.
Listing 5. web.xmlÀÇ FacesServlet
¼±¾ð
<!-- JavaServer Faces Servlet Configuration -->
<servlet>
<servlet-name>faces</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- JavaServer Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>faces</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
|
Struts-Faces¿Í Tiles
ÅëÇÕÀÇ ¹®Á¦Á¡ Struts-Faces ¶óÀ̺귯¸®´Â Struts¿Í JSF »çÀÌ¿¡ È¿À²ÀûÀÎ
´Ù¸®¸¦ Á¦°øÇÑ´Ù. J2EE À¥ ¾ÖÇø®ÄÉÀ̼ǿ¡ dzºÎÇÑ ÇÁ¸®Á¨Å×ÀÌ¼Ç ·¹À̾ °¡´ÉÇÏ°Ô ÇÑ´Ù. ÀÌ °áÇÕ¹°¿¡
Tiles¸¦ Ãß°¡ÇÏ¿© º¸´Ù dzºÎÇÏ°Ô ÇÁ¸®Á¨Å×ÀÌ¼Ç ·¹À̾ ¸¸µé ¼ö ÀÖ´Ù. µû¶ó¼ Struts¿Í JSF °áÇÕ¿¡¼
À̵浵 º¸°í ´Ù¾çÇÑ JSP ÆäÀÌÁö¸¦ È¿À²ÀûÀ¸·Î Àç»ç¿ëÇÒ ¼ö ÀÖ´Ù.
ÀÌ ±Û¿¡¼´Â ÀÌ¹Ì Struts¿Í JSFÀÇ ÅëÇÕÀ» ¼³¸íÇß´Ù. ±×·¸´Ù¸é Tiles¸¦ ¿©±â¿¡ Ãß°¡ÇÏ´Â °ÍÀº
½ÄÀºÁ× ¸Ô±â ¾Æ´Ï°Ú´Â°¡?
ºÒÇàÈ÷µµ JSF´Â ¾ÆÁ÷ Ãʱ⠴ܰ迡 ¸Ó¹°·¯ÀÖ´Ù. Struts-Faces ÅëÇÕ ¼ÒÇÁÆ®¿þ¾î´Â °è¼Ó °³¹ßµÇ¾î
JSFÀÇ ´Ù¾çÇÑ ±â´ÉÀ» ¼ö¿ëÇÏÁö¸¸ ¾ÆÁ÷ Tiles´Â Áö¿øÇÏÁö ¾Ê´Â´Ù.
Struts¿Í Tiles´Â ¿Ïº®È÷ »óÈ£ ÀÛµ¿ÇÒ ¼ö ÀÖ´Ù. ÇÏÁö¸¸ ÅëÇÕÇÒ ¶§ Àå¾Öµµ ÀÖ´Ù. ´ÙÀ½ ¼½¼Ç¿¡¼´Â
Struts-Faces ÅëÇÕ ¶óÀ̺귯¸®¸¦ Tiles¿Í ÇÔ²² »ç¿ëÇÒ ¶§ÀÇ ÀϹÝÀûÀÎ ¹®Á¦Á¡À» ¼³¸íÇÑ´Ù.
Listing 6Àº Flight Search ÆäÀÌÁö¿ë ·¹À̾ƿôÀÌ´Ù. À̸¦ FlightSearch.jsp°¡
¾Æ´Ñ Flight Search·Î ºÎ¸£´Â°Í¿¡ ÁÖ¸ñÇ϶ó. FlightSearch JSP°¡ foobar ¿©Çà»ç À¥
»çÀÌÆ®»ó¿¡¼ »ç¿ëÀÚ°¡ º¸´Â Àüü ÆäÀÌÁöÀÇ ¹ÙµðÀ̱⠶§¹®ÀÌ´Ù.
ÀÌÁ¦ºÎÅÍ FlightSearch.jsp¸¦ ÀÖ´Â ±×´ë·Î Àû¿ëÇÒ °ÍÀÌ´Ù. ¾ÕÀ¸·Î ÁøÇàÇØ°¡¸é¼ º¯°æÇÒ °ÍÀÌ´Ù.
¿©·¯ºÐÀº Flight Search ÆäÀÌÁö¿ë Á¤ÀÇ¿Í ÇÔ²² Tiles Á¤ÀÇ ÆÄÀÏÀ» ¸¸µé¾î¾ß ÇÑ´Ù. Listing
7Àº Tiles Á¤ÀÇ ÆÄÀÏÀÇ Flight Search Page¿ë ¿£Æ®¸®ÀÌ´Ù. ¸¶½ºÅÍ ·¹À̾ƿô ÅÛÇø´°ú
extends ¾ÖÆ®¸®ºäÆ®°¡ Àç»ç¿ëµÇ¾ú´Ù. Listing 6. Flight Search ·¹À̾ƿô ¿¹Á¦
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-faces"prefix="s" %>
<!-- Layout component parameters: header, menu, body, footer -->
<s:html>
<head>
<title> <tiles:getAsString name="title"/></title>
<s:base/>
</head>
<body>
<TABLE border="0" width="100%" cellspacing="5">
<tr>
<td><tiles:insert attribute="header"/></td>
</tr>
<tr>
<td><tiles:insert attribute="body"/></td>
</tr>
<tr><td><hr></td></tr>
<tr>
<td><tiles:insert attribute="footer" /></td>
</tr>
</TABLE>
</body>
</s:html>
|
Listing 7. Flight Search Page¿¡ ´ëÇÑ Tiles
Á¤ÀÇ.
<!-- Master Layout definition -->
<definition name="foobar.master-layout"
path="/faces/layout/MasterLayout.jsp">
<put name="title" value="Welcome to Foo Bar Travels" />
<put name="header" value="/faces/common/header.jsp" />
<put name="footer" value="/faces/common/footer.jsp" />
<put name="body" value="" />
</definition>
<!-- Definition for Flight Search Page -->
<definition name="/foobar.flight-search"
extends="foobar.master-layout">
<put name="body" value="/faces/FlightSearch.jsp" />
</definition>
|
ÀÀ´ä Ä¿¹Ô Flight Search Form¿¡ ¾×¼¼½º¸¦ ½ÃµµÇÏÀÚ¸¶ÀÚ
º¸°ÔµÉ ù ¹ø° ¹®Á¦°¡ ¹Ù·Î ÀÌ°ÍÀÌ´Ù. ½ºÅà Ʈ·¹À̽º¸¦ ÀÚ¼¼È÷ »ìÆ캸ÀÚ. ¹®Á¦´Â
com.sun.faces.lifecycle.ViewHandlerImpl Ŭ·¡½º¿¡ ÀÖ´Ù´Â
°ÍÀ» ¾Ë ¼ö ÀÖ´Ù. ÀÌ°ÍÀº ViewHandler ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇÏ´Â JSF-RI
Ŭ·¡½ºÀÌ´Ù.
±×¸² 2 ´Â
ViewHandler °¡ ¼öÇàÇÏ´Â ¿ªÇÒÀÌ´Ù. ÀÌ°ÍÀº ¸®Äù½ºÆ®¸¦ ´ÙÀ½ ÆäÀÌÁö·Î º¸³»´Â
Ŭ·¡½ºÀÌ´Ù. ¸®Äù½ºÆ®¸¦ º¸³¾ ¶§ º¸³»±â Àü¿¡ ÀÀ´ä »óŸ¦ °Ë»çÇÏÁö ¾Ê´Â´Ù. ÀÌ°ÍÀº Tiles¸¦ »ç¿ëÇÒ ¶§¸¸
¹ß»ýÇϴµ¥ Tiles´Â JSP ÆäÀÌÁö¸¦ ÀÀ´ä¿¡ Æ÷ÇÔ½ÃÅ°±â ¶§¹®ÀÌ´Ù. ±×¸®°í JSF-RI´Â ù ¹ø° Æ÷¿öµå ÈÄ¿¡
ÀÀ´äÀ» Ä¿¹ÔÇÏ°í ±×·±´ÙÀ½ ´Ù½Ã ´ÙÀ½ Tiles·Î º¸³»±â¸¦ ½ÃµµÇÑ´Ù.
ÀÌ ¹®Á¦¸¦ ÇØ°áÇÏ·Á¸é ÀÀ´äÀÌ Ä¿¹Ô µÇ¾ú´ÂÁöÀÇ ¿©ºÎ¸¦ °áÁ¤ÇÒ ¼ö ÀÖµµ·Ï ÀÀ´ä »óŸ¦ °Ë»çÇÒ Ä¿½ºÅÒ
ViewHandler ¸¦ ±¸ÇöÇØ¾ß ÇÑ´Ù. ÀÀ´äÀÌ Ä¿¹ÔµÇÁö ¾ÊÀ¸¸é ¸®Äù½ºÆ®´Â ´ÙÀ½ ÆäÀÌÁö·Î
³Ñ¾î°£´Ù. ±×·¸Áö¾ÊÀ¸¸é ¸®Äù½ºÆ®´Â Æ÷ÇԵǰí Àû´çÇÑ JSP°¡ µð½ºÇ÷¹À̵ȴÙ.
ViewHandler ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇÏ°í ÇÊ¿äÇÑ
renderView() ¸Þ¼Òµå¸¦ ±¸ÇöÇÏ´Â
STFViewHandlerImpl Ŭ·¡½º¸¦ ¸¸µé °ÍÀÌ´Ù. (Listing 8):
Listing 8. STFViewHandlerImplÀÇ
renderView() ¸Þ¼Òµå
RequestDispatcher rd = null;
Tree tree = context.getTree();
String requestURI = context.getTree().getTreeId();
rd = request.getRequestDispatcher(requestURI);
/** If the response is committed, include the resource **/
if( !response.isCommitted() ) {
rd.forward(request, context.getServletResponse());
}
else {
rd.include(request, context.getServletResponse());
}
|
Ä¿½ºÅÒ ViewHandler ¸¦ ±¸ÇöÇßÀ¸´Ï JSF-RI¿¡°Ô µðÆúÆ® ±¸Çö ´ë½Å ÀÚ½ÅÀÇ
ViewHandler ¸¦ »ç¿ëÇÑ´Ù°í ¾î¶»°Ô °øÁöÇϰڴ°¡? ÀÌ Áú¹®¿¡ ´ëÇÑ ´äÀ¸·Î
FacesServlet ÀÇ ÀÛµ¿À» ÀÌÇØÇØ¾ß ÇÑ´Ù.
Faces ÃʱâÈ °úÁ¤ Áß FacesServlet ´Â
LifecycleFactory ±¸Çö¿¡ Lifecycle Ŭ·¡½º
±¸ÇöÀ» ¸®ÅÏÇÒ °ÍÀ» ÀÇ·ÚÇÑ´Ù. (Listing 9): Listing
9. FacesServletÀÇ Faces ÃʱâÈ
//Get the LifecycleFactory from the Factory Finder
LifecycleFactory factory = (LifecycleFactory)
FactoryFinder.getFactory("javax.faces.lifecycle.LifecycleFactory");
//Get the context param from web.xml
String lifecycleID =
getServletContext().getInitParameter("javax.faces.lifecycle.LIFECYCLE_ID");
//Get the Lifecycle Implementation
Lifecycle lifecycle = factory.getLifecycle(lifeCycleID);
|
Lifecycle ±¸Çö °´Ã¼´Â Render Response ´Ü°è¿¡¼ »ç¿ëµÉ
ViewHandler ¸¦ °®°í ÀÖ´Ù. Lifecycle ±¸Çö¿¡
setViewHandler ¸Þ¼Òµå¸¦ È£ÃâÇÏ¿© ViewHandler
±¸ÇöÀÌ µðÆúÆ®°¡ µÇµµ·Ï ÇÒ ¼ö ÀÖ´Ù.
ÀÌÁ¦ Áú¹®Àº µðÆúÆ® Lifecycle ±¸ÇöÀ» ¾î¶»°Ô ¾òÀ» ¼ö ÀÖ´À³ÄÀÌ´Ù. ´äÀº ÀÌ·²
ÇÊ¿ä°¡ ¾ø´Ù´Â °ÍÀÌ´Ù. ±×Àú »õ·Î¿î ±¸ÇöÀ» ¸¸µé¾î °íÀ¯ ID¸¦ °¡Áø
LifecycleFactory ·Î À̸¦ µî·ÏÇϸéµÈ´Ù. (Listing 10): Listing 10. Ä¿½ºÅÒ ViewHandler¿Í Lifecycle
µî·ÏÇϱâ
//Get the LifecycleFactory from the Factory Finder
LifecycleFactory factory = (LifecycleFactory)
FactoryFinder.getFactory("javax.faces.lifecycle.LifecycleFactory");
//Create a new instance of Lifecycle implementation -
//com.sun.faces.lifecycle.LifecycleImpl
//According to the documentation, factory.getLifecycle("STFLifecycle")
//should work, but JSF-RI has a defect.
//Hence this workaround of creating a RI class explicitly.
LifecycleImpl stfLifecycleImpl = new LifecycleImpl();
//Create a new instance of our STFViewHandler and set it on the Lifecycle
stfLifecycleImpl.setViewHandler(new STFViewHandlerImpl());
//Register the new lifecycle with the factory with a unique
//name "STFLifecycle"
factory.addLifecycle("STFLifecycle", stfLifecycleImpl);
|
lifecycleId °¡ STFLifecycle ó·³
ÇϵåÄÚµùµÈ °ÍÀ» º¼ ¼ö ÀÖ´Ù. »ç½Ç ±×·¸Áö ¾Ê´Ù. Listing 9¸¦
´Ù½Ã º¸¸é ¸íÈ®ÇØÁø´Ù. FacesServlet Àº lifecycle ID¸¦
javax.faces.lifecycle.LIFECYCLE_ID ¶ó´Â À̸§°ú ÇÔ²²
web.xml ÆÄÀÏ¿¡¼ ¼±¾ðµÈ ÄÜÅؽºÆ® ¸Å°³º¯¼ö¿¡¼ ÃëÇÑ´Ù:
<context-param>
<param-name>javax.faces.lifecycle.LIFECYCLE_ID</param-name>
<param-value>STFLifecycle</param-value>
</context-param>
|
FacesServlet ÀÌ ÃʱâÈ µ¿¾È Lifecycle ±¸Çö
Ŭ·¡½º¿¡ ´ëÇØ °áÁ¤Çϱ⠶§¹®¿¡ Listing 10ÀÇ
ÄÚµå´Â FacesServlet ÀÌ ÃʱâÈ µÇ±â Àü¿¡ ½ÇÇàµÇ¾î¾ß ÇÑ´Ù. ¶Ç ´Ù¸¥ ¼ºí¸´À»
¸¸µé¾î FacesServlet Àü¿¡ À̸¦ ÃʱâÈÇÏ¿© À̸¦ ¼öÇàÇÒ ¼ö ÀÖ´Ù.
º¸´Ù Çö¸íÇÑ ¹æ¹ýÀº ServletContextListener ÀÎÅÍÆäÀ̽º¸¦ ±¸ÇöÇÏ´Â
°ÍÀÌ´Ù. ÀÌ Å¬·¡½º´Â µÎ °³ÀÇ ¸Þ¼ÒµåÀÎ contextInitialized() ¿Í
contextDestroyed() ¸¦ ¼±¾ðÇÑ´Ù. ÀÌ°ÍÀº À¥ ¾ÖÇø®ÄÉÀ̼ÇÀÌ ±¸ÇöµÉ ¶§¿Í À¥
¾ÖÇø®ÄÉÀ̼ÇÀÌ ¾ø¾îÁö±â Àü¿¡ È£ÃâµÈ´Ù. Listing 10ÀÇ
ÄÚµå´Â contextInitialized() ¸Þ¼Òµå¿¡¼ ½ÇÇàµÇ°í Ä¿½ºÅÒ
ViewHandler ´Â STFLifecycle À̶ó´Â À̸§À¸·Î
±¸ºÐµÈ Lifecycle ·Î µî·ÏµÈ´Ù. FacesServlet µµ
°¡´ÉÇÏ´Ù. ServletContextListener Ŭ·¡½º ÀÚü´Â web.xml ÆÄÀÏ¿¡¼
¼±¾ðµÈ´Ù.
<listener>
<listener-class>foo.bar.stf.application.STFContextListener
</listener-class>
</listener>
|
ÀÌ°ÍÀÌ Lifecycle À» Ä¿½ºÅÒ ViewHandler ·Î
µî·ÏÇÏ´Â À¯ÀÏÇÑ Á¢±Ù¹æ½ÄÀº ¾Æ´Ï´Ù. »ç½Ç FactoryFinder ´Â °íÀ¯ÀÇ ¹ß°ß
¾Ë°í¸®ÁòÀ» ±¸ÇöÇÏ¿© LifecycleFactory ¸¦ Æ÷ÇÔÇÏ¿©
Factory °´Ã¼¸¦ ¹ß°ßÇÑ´Ù. ÀÌ ¸ÞÄ¿´ÏÁòÀº ½±±â´Â ÇÏÁö¸¸ ¸Å·ÂÀûÀÌÁö´Â ¾Ê´Ù.
404 Resource Not
Found Ä¿¹ÔµÈ ÀÀ´ä ¹®Á¦°¡ ÇØ°áµÇ¸é ¾Æ¹« Tiles ½ºÆÑ ¸µÅ©¸¦ Ŭ¸¯Çϰųª
Faces ÀÀ´äÀ» ·»´õ¸µÇÏ´Â URLÀ» ÀÔ·ÂÇÑ´Ù. ÀÌ °æ¿ì URLÀ» ÀÔ·ÂÇÏ¿©
FlightSearchForm À» µð½ºÇ÷¹ÀÌ ÇÒ ¼ö ÀÖ´Ù.
ÀÌ·¸°Ô Çϸé foobar.flight-search
- 404 Resource Not Found ¿¡·¯°¡ ³ªÅ¸³´Ù.
foobar.flight-search ´Â Flight Search ÆäÀÌÁö¿ë Tiles Á¤ÀÇ
À̸§ÀÌ´Ù. FacesRequestProcessor ´Â Tiles ¸®Äù½ºÆ®¸¦ ó¸® ÇÒ ´É·ÂÀÌ
¾ø´Ù. µû¶ó¼ ¿¡·¯°¡ »ý±ä´Ù.
ÀÌ ¹®Á¦¸¦ ÇØ°áÇÏ·Á¸é STFRequestProcessor ¶ó´Â »õ·Î¿î ¸®Äù½ºÆ®
ÇÁ·Î¼¼¼¸¦ ¸¸µé¾î¾ß ÇÑ´Ù. Áö±Ý±îÁö´Â FacesRequestProcessor ÀÇ ¸ðµç
Äڵ带 »õ·Î¿î Ŭ·¡½º¿¡ º¹»çÇß´Ù. À¯ÀÏÇÑ Â÷ÀÌÁ¡Àº ÀϹÝÀûÀÎ
RequestProcessor ¸¦ ÇÏÀ§Å¬·¡½º·Î ³ª´©´Â ´ë½Å
STFRequestProcessor °¡
TilesRequestProcessor ¸¦ ÇÏÀ§Å¬·¡½º·Î ³ª´«´Ù´Â Á¡ÀÌ´Ù. ÀÌ »õ·Î¿î
RequestProcessor °¡ Tiles ¸®Äù½ºÆ®¸¦ ÇÚµéÇÒ ¼ö ÀÖ´Ù. (Listing
11) Listing 11.
STFRequestProcessor.java
public class STFRequestProcessor extends TilesRequestProcessor
{
protected void doForward(String uri, HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException
{
//copy code from FacesRequestProcessor
}
protected void doInclude(String uri, HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
//copy code from FacesRequestProcessor
}
protected String processPath(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
//copy code from FacesRequestProcessor
}
protected String processPopulate(HttpServletRequest request,
HttpServletResponse response)
throws IOException
{
//copy code from FacesRequestProcessor
}
private void selectTree(FacesContext context, String uri)
{
//copy code from FacesRequestProcessor
}
}
|
¾Ë´Ù½ÃÇÇ Struts ÇÁ·¹ÀÓ¿÷¿ë RequestProcessor ´Â
struts-config.xml ÆÄÀÏ¿¡¼ ÁöÁ¤µÈ´Ù. STFRequestProcessor ´Â
´ÙÀ½ ¿£Æ®¸®°¡ struts-config.xml ÆÄÀÏ¿¡ Ãß°¡µÉ ¶§ ÇÁ·Î¼¼¼°¡ µÈ´Ù.
<controller processorClass="foobar.stf.application.STFRequestProcessor" />
|
Form
submission
STFRequestProcessor ´öÅÿ¡
Flight Search ÆäÀÌÁö¸¦ °Ë»öÇÏ°í º¼ ¼ö ÀÖ´Ù. ÇÏÁö¸¸ Flight Search Çü½ÄÀ» Á¦ÃâÇÏÀÚ¸¶ÀÚ
ÀÀ´äÀ¸·Î °°Àº Çü½ÄÀ» ¹Þ°ÔµÈ´Ù. ±×·¸Áö¸¸ Çì´õ¿Í DzÅÍ°¡ ¾ø´Ù. ¹ë¸®µ¥ÀÌ¼Ç ¿¡·¯µµ ¾ø´Ù. »ç½Ç ¹ë¸®µ¥ÀÌ¼Ç ÀÚü°¡
¾ø´Â°ÍÀÌ´Ù.
¾î¶² »óȲÀÎÁö ¾Ë°í½Í´Ù¸é Flight Search ÆäÀÌÁö·Î ´Ù½Ã°¡¼ HTML ¼Ò½º¸¦ º¸ÀÚ. ´ÙÀ½°ú °°Àº
¿£Æ®¸®¸¦ º¸°Ô µÉ °ÍÀÌ´Ù.
<form name="FlightSearchForm" method="post"
action="/flightapp/faces/FlightSearch.jsp">
|
Çü½Ä ¾×¼ÇÀÌ ´ë½Å JSP ÆäÀÌÁö¸¦ °¡¸£Å°°í ÀÖ´Ù. ÀÌ°ÍÀÌ ¹Ù·Î ¹®Á¦ÀÌ´Ù. Tiles¿Í
Struts-Faces¸¦ »ç¿ëÇ߱⠶§¹®¿¡ ¹ß»ýÇÏ´Â »õ·Î¿î ¹®Á¦´Â ¾Æ´Ï´Ù. ÀÌ°ÍÀº Çü½Ä ¾×¼Ç°ú °°Àº JSP À̸§À»
°®±âÀ§ÇÑ Struts-FacesÀÇ µðÆúÆ® ÀÛµ¿ÀÌ´Ù. ÀÌ°ÍÀº ÇϳªÀÇ JSP ÆäÀÌÁö¸¦ °®°Ô µÇ¸é ¹®Á¦¾øÀÌ ½ÇÇàµÈ´Ù.
Listing 3˼
¿ø·¡ FlightSearch.jspÀÌ´Ù. ¾×¼ÇÀ» ´ÙÀ½°ú °°ÀÌ º¯°æÇغ¸ÀÚ.
<s:form action="/listFlights.do>
|
¹°·Ð º¯°æ ÀÚü·Î´Â ¹®Á¦¸¦ ÇØ°áÇÒ ¼ö ¾ø´Ù. ÀÌÁ¤µµÀÇ º¯°æÀ¸·Î´Â
STFRequestProcessor °¡ ActionForm À» ãÀ»¼ö
¾ø´Ù´Â °Íµµ ¾Ë°ÔµÉ °ÍÀÌ´Ù. ´õ ¸¹Àº º¯°æÀÌ ÇÊ¿äÇÏ´Ù.
°è¼Ó ÁøÇàÇϱâ Àü¿¡ ±×¸² 5¸¦ º¸ÀÚ. Struts-Faces Çü½Ä¿ë faces ÀÀ´äÀ» ·»´õ¸µÇÒ¶§ÀÇ À̺¥Æ®
°á°ú¸¦ º¸¿©ÁÖ°í ÀÖ´Ù. FormComponent ÀÇ ÇÏÀ̶óÀÌÆ®µÈ
createActionForm() ¸Þ¼Òµå¸¦ Á¦¿ÜÇÏ°í´Â ±×¸² 3°ú °°´Ù.
Struts-Faces API¿¡ ÀÇÇØ Á¦°øµÈ FormComponent Ŭ·¡½º´Â
javax.faces.component.UIForm ÀÇ Æ¯º°ÇÑ ¼ºêŬ·¡½º°í ¸®Äù½ºÆ® ¶Ç´Â
¼¼¼Ç ¹üÀ§¿¡¼ Çü½Ä ºóµéÀÇ ÀÚµ¿ »ý¼ºÀ» Áö¿øÇÑ´Ù.
±×¸² 5.
Struts-Faces ÀÀ´ä ·»´õ¸µ ±×¸²º¸±â.
createActionForm() ¸Þ¼Òµå´Â ¾×¼Ç À̸§À» »ç¿ëÇÏ¿© Struts ¼³Á¤
ÆÄÀÏ¿¡¼ ActionMapping À» ¾ò´Â´Ù. /listFlights.do¿ë
ActionMapping ÀÌ ¾ø±â¶§¹®¿¡ Struts´Â
ActionForm À» ãÀ» ¼ö ¾ø´Ù.
org.apache.struts.util.RequestUtils ¸¦ »ç¿ëÇÏ¿© ¹®Á¦¸¦
ÇØ°áÇÒ ¼ö ÀÖ´Ù. RequestUtils ÀÇ Á¤Àû ¸Þ¼ÒµåÀÎ
getActionMappingName() Àº °æ·Î(/x/y/z)³ª
Á¢¹Ì»ç(.do) ¸ÅÇÎÀ» ÀûÀýÇÑ ActionMapping À¸·Î ºÐÇØÇÒ ¼ö
ÀÖ´Ù.
Listing 12´Â createActionForm ¸Þ¼ÒµåÀÇ º¯°æ»çÇ×À» ±½°Ô
Ç¥½ÃÇÏ¿© º¸¿©ÁÖ°í ÀÖ´Ù. Struts-FacesÀÇ FormComponent ¸¦ º¯°æÇÏ´Â
´ë½Å FormComponent ¸¦ ÇÏÀ§Å¬·¡½º·Î ³ª´©°í
createActionForm() ¸Þ¼Òµå¸¦ ¿À¹ö¶óÀ̵å ÇÏ¿© »õ·Î¿î
STFFormComponent ¸¦ ¸¸µç´Ù. Listing 12. FormComponentÀÇ º¯°æµÈ
createActionForm() ¸Þ¼Òµå
// Look up the application module configuration information we need
ModuleConfig moduleConfig = lookupModuleConfig(context);
// Look up the ActionConfig we are processing
String action = getAction();
String mappingName = RequestUtils.getActionMappingName(action);
ActionConfig actionConfig = moduleConfig.findActionConfig(mappingName);
....
....
|
»õ·Î¿î STFFormComponent ¿¡ º¯°æÀÌ ´õ ÇÊ¿äÇÏ´Ù.
Struts-Faces´Â ¾×¼Ç À̸§À» Çü½Ä À̸§À¸·Î Ãë±ÞÇÑ´Ù. ¾×¼Ç¿¡´Â .do Á¢¹Ì»ç°¡ ÀÖ°í Çü½Ä
À̸§¿¡´Â .do Á¢¹Ì»ç°¡ ¾ø±â ¶§¹®¿¡ º¯°æÀÌ ÇÊ¿äÇÏ´Ù. µû¶ó¼ »õ·Î¿î ¼Ó¼ºÀÎ
action À» STFFormComponent ¿¡ Ãß°¡ÇÏ°í
getAction() °ú setAction() ¸Þ¼Òµå¸¦
¿À¹ö¶óÀ̵åÇÑ´Ù.
FormRenderer
º¯°æ Listing 10¿¡¼
Çß´ø º¯°æÀ» FormRenderer ÀÇ encodeBegin
¸Þ¼Òµå¿¡µµ ºñ½ÁÇÏ°Ô Àû¿ëÇØ¾ß ÇÑ´Ù.
FormRenderer ¸¦ ÇÏÀ§Å¬·¡½º·Î ³ª´©¸é µÈ´Ù. HTML·Î ÀÛ¼ºµÈ Çü½Ä ¾×¼Çµµ
º¯°æÇØ¾ß ÇÑ´Ù. (Listing 13): Listing 13.
FormRenderer º¯°æ
protected String action(FacesContext context, UIComponent component) {
String treeId = context.getTree().getTreeId();
StringBuffer sb = new StringBuffer
(context.getExternalContext().getRequestContextPath());
sb.append("/faces");
// sb.append(treeId); -- This is old code, replaced with
// the two lines below.
STFFormComponent fComponent = (STFFormComponent) component;
sb.append(fComponent.getAction());
return (context.getExternalContext().encodeURL(sb.toString()));
}
|
FormTag º¯°æ ÀÌ¹Ì ¾Ë°íÀÖ°ÚÁö¸¸ ÄÄÆ÷³ÍÆ®¿Í ·»´õ·¯¸¦ º¯°æÇÒ ¶§
ÀÌ ÅÂ±× ¿ª½Ã º¯°æÇØ¾ß ÇÑ´Ù. ÀÌ °æ¿ì Struts-FacesÀÇ FormTag ¿¡¼
ÇÏÀ§Å¬·¡½º·Î ³ª´©¾î STFFormTag ¶ó´Â »õ·Î¿î ű׸¦ ¸¸µç´Ù. ±â´ÉÀûÀÎ ºÎºÐÀº ¹Ù²Ü
ÇÊ¿ä°¡ ¾ø´Ù. getComponentType() °ú
getRendererType() ¸Þ¼Òµå¸¦ ¿À¹ö¶óÀ̵å ÇϸéµÈ´Ù. (Listing
14): Listing 14. FormTag
º¯°æ
public String getComponentType()
{
return ("STFFormComponent");
}
public String getRendererType()
{
return ("STFFormRenderer");
}
|
faces-config.xml ÆÄÀÏ º¯°æ Ä¿½ºÅÒ ÄÄÆ÷³ÍÆ®¿Í ·»´õ·¯´Â
faces-config.xml ÆÄÀÏ¿¡¼ ¼±¾ðµÇ¾î JSF ÇÁ·¹ÀÓ¿÷ÀÌ À̵éÀ» ÃʱâÈÇÏ¿© »ç¿ëÇÒ ¼ö ÀÖµµ·Ï ÇÑ´Ù.
Áö±Ý±îÁö »õ·Î¿î ÄÄÆ÷³ÍÆ®ÀÎ STFFormComponent ¸¦ ¸¸µé¾ú°í »õ·Î¿î ·»´õ·¯ÀÎ
STFFormRenderer ¸¦ ¸¸µé¾ú´Ù.
ÀÌÁ¦ Listing 15¿¡¼ ¼³¸íÇÑ °Í ó·³ faces-config.xml ÆÄÀÏ¿¡ ¼±¾ðÀ» Ãß°¡ÇÒ °ÍÀÌ´Ù.
component-class´Â ¿ÏÀüÈ÷ °ËÁõµÈ ÄÄÆ÷³ÍÆ®¿ë Ŭ·¡½º À̸§ÀÌ´Ù.
component-typeÀº STFFormTag (Listing 12)¿¡
»ç¿ëµÈ À̸§À» ¶æÇϸç ÄÄÆ÷³ÍÆ®¸¦ ±¸ºÐÇÑ´Ù. ·»´õ·¯µµ ºñ½ÁÇÑ ¹æ½ÄÀ¸·Î ÀÎÅÍÇÁ¸®Æà ¹× ¹ß°ßµÈ´Ù.
faces-config.xml ÆÄÀÏÀÌ struts-faces.jar ÆÄÀÏ¿¡ Á¸ÀçÇÑ´Ù´Â °ÍÀ» ±â¾ïÇ϶ó.
struts-faces.jar ÆÄÀÏ¿¡¼ ÀÌ ÆÄÀÏÀ» Áö¿ì°í À̸¦ À¥ ¾ÖÇø®ÄÉÀ̼ÇÀÇ WEB-INF Æú´õ
¹Ø¿¡ ³õ°í À̸¦ ¼öÁ¤ÇÑ´Ù. Listing 15.
faces-config.xml¿¡¼ Ä¿½ºÅÒ ÄÄÆ÷³ÍÆ® ¹× ·»´õ·¯ ¼±¾ð
<faces-config>
<!-- Custom Components -->
<component>
<component-type>STFFormComponent</component-type>
<component-class>
foobar.stf.component.STFFormComponent
</component-class>
</component>
..
..
..
<!-- Custom Renderers -->
<render-kit>
<renderer>
<renderer-type>STFFormRenderer</renderer-type>
<renderer-class>
foobar.stf.renderer.STFFormRenderer
</renderer-class>
</renderer>
..
..
..
</render-kit>
</faces-config>
|
struts-faces.tld ÆÄÀÏ º¯°æ »ùÇÃ
Struts-Faces ¾ÖÇø®ÄÉÀ̼ǿ¡¼ struts-faces.tld ÆÄÀÏÀ» ãÀ» ¼ö ¾øÀ» °ÍÀÌ´Ù.
struts-faces.jar ÆÄÀÏ°ú ÇÔ²² ÆÐÅ°Áö µÇ±â ¶§¹®ÀÌ´Ù. ÀÌ°ÍÀº
org.apache.struts.faces.taglib.LifecycleListener ¶ó´Â
Ŭ·¡½º¸¦ ¼±¾ðÇÑ´Ù. ÀÌ°ÍÀº ServletContextListener ¸¦ ±¸ÇöÇÏ°í
FacesRequestProcessor ¸¦ ÃʱâÈÇÑ´Ù.
»õ·Î¿î STFRequestProccessor ¸¦ »ç¿ëÇϱ⠿øÇϴ¸¸Å
struts-faces.jar ÆÄÀÏ¿¡¼ ÀÌ ÆÄÀÏÀ» Á¦°ÅÇÏ°í WEB-INF Æú´õ ¹Ø¿¡ ³õÀº ´ÙÀ½ ¸®½º³Ê ¼±¾ðÀ»
»èÁ¦ÇÑ´Ù. tld ÆÄÀÏÀ» ±×´ë·Î ³²°ÜµÎ¸é FacesRequestProcessor ´Â À¥
¾ÖÇø®ÄÉÀ̼ÇÀÌ ÃʱâÈ µÉ ¶§ STFRequestProcessor ¿Í ´õºÒ¾î
ÀνºÅϽºÈµÈ´Ù.
base href ÅÂ±× º¯°æ Áö±Ý±îÁö Struts, Tiles,
JSF ÅëÇÕÀÇ ¸ðµç °ü¹®À» Åë°úÇß´Ù. Flight Search ÆäÀÌÁö¸¦ °Ë»öÇÏ°í ºñÇà ¿ä±Ýµµ °Ë»öÇÒ ¼ö ÀÖ´Ù.
ÀÌÁ¦ Flight List ÆäÀÌÁö¿¡¼ Flight Search Form À¸·Î ¿Å°Ü°¡º¸ÀÚ. HTTP 400
error¸¦ ¸¸³ª°Ô µÉ °ÍÀÌ´Ù. ÀÌÀ¯´Â HTML base href ÅÂ±× ¶§¹®ÀÌ´Ù. ÀÌ°ÍÀº
Master Layout ÆäÀÌÁö·Î ¼³Á¤µÇ¾îÀÖ´Ù.
<base href=
"http://localhost:8080/stf-example/faces/layout/MasterLayout.jsp" />
|_________| |_____________________|
Context Servlet Path
|
¸ðµç ÆäÀÌÁö °Ë»öÀÌ ·¹À̾ƿô ÆäÀÌÁö¿Í °ü·ÃÇÏ¿© °è»êµÇ°í ÀÖ´Ù. base href
űװ¡ À¥ ¾ÖÇø®ÄÉÀÌ¼Ç ÄÜÅؽºÆ®±îÁö Æ÷ÇԵǾî ÀÖÀ¸¸é ´õ Æí¸®ÇÒ °ÍÀÌ´Ù:
<base href="http://localhost:8080/stf-example/" />
|
Struts-Faces BaseTag ¸¦ Ä¿½ºÅ͸¶ÀÌ¡ ÇϸéµÈ´Ù. ÀÌ Å¬·¡½ºÀÇ º¯°æÀº
¸Å¿ì °£´ÜÇÏ´Ù. base href¿¡¼
HttpServletRequest.getServletPath() ¸¦ Á¦°ÅÇÏ¸é µÈ´Ù.
ÀÌ·¯ÇÑ º¯È°¡ µð½ºÇ÷¹ÀÌ¿Í °ü·ÃµÇ±â ¶§¹®¿¡ STFBaseRenderer ¶ó´Â »õ·Î¿î
·»´õ·¯°¡ ¸¸µé¾îÁø´Ù. ÀÌ »õ·Î¿î ű״ STFBaseTag ÀÌ°í
STFBaseRenderer ¸¦ ¼±¾ðÇÑ´Ù. »õ·Î¿î ÄÄÆ÷³ÍÆ®°¡ ÇÊ¿ä¾ø´Ù.
»õ·Î¿î STFBaseTag ´Â BaseTag ¸¦ ÇÏÀ§Å¬·¡½º·Î
³ª´©°í getRendererType À» ¿À¹ö¶óÀ̵ùÇÏ¿© ¸¸µé¾îÁø´Ù.
public String getRendererType()
{
return ("STFBaseRenderer");
}
|
Âü°íÀÚ·á
|