KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > fr > improve > struts > taglib > layout > PopupTag


1 package fr.improve.struts.taglib.layout;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4
5 import fr.improve.struts.taglib.layout.renderer.BasicPopupRenderer;
6 import fr.improve.struts.taglib.layout.util.LayoutUtils;
7 import fr.improve.struts.taglib.layout.util.PanelInterface;
8 import fr.improve.struts.taglib.layout.util.TagUtils;
9
10 /**
11  * Useful tag to create a popup.
12  *
13  * @author JN RIBETTE
14  */

15 public class PopupTag extends PanelTag {
16     /**
17      * Constants, indicating if the popup Js code has already been loaded or not.
18      */

19     public static final String JavaDoc POPUP_KEY = "fr.improve.struts.taglib.layout.PopupTag.POPUP_KEY";
20     
21     /**
22      * Javascript id of the DIV element.
23      */

24     private String JavaDoc styleId;
25     
26     public void doStartLayout() throws JspException JavaDoc {
27         // Start TR/TD for Struts-Layout compatibility.
28
super.doStartLayout();
29         
30         // Generate Javascript code.
31
loadScript();
32         
33         // Generate DIV.
34
TagUtils.write(pageContext, "<div id=\"");
35         TagUtils.write(pageContext, styleId);
36         TagUtils.write(pageContext, "\" style=\"position:absolute; left:100px; top:100px; z-index:10; visibility:hidden;\">\n");
37     }
38     
39     public void doEndLayout() throws JspException JavaDoc {
40         // GenerateDIV.
41
TagUtils.write(pageContext, "</div>\n");
42         
43         // End TD/TR for Struts-Layout compatibility.
44
super.doEndLayout();
45     }
46     
47     /**
48      * Load the required Javascript code.
49      */

50     protected void loadScript() throws JspException JavaDoc {
51         if (pageContext.getRequest().getAttribute(POPUP_KEY)==null) {
52             TagUtils.write(pageContext, "<script SRC=\"");
53             TagUtils.write(pageContext, LayoutUtils.getSkin(pageContext.getSession()).getConfigDirectory(pageContext.getRequest()));
54             TagUtils.write(pageContext, "/popup.js\"></script>");
55             TagUtils.write(pageContext, "<div id=\"slpdiv\" style=\"display:none;position:absolute;left:0px;top:0px; width:100%; height:100%; z-index:9;\"></div>");
56             pageContext.getRequest().setAttribute(POPUP_KEY, "");
57         }
58     }
59
60     public String JavaDoc getStyleId() {
61         return styleId;
62     }
63
64     public void setStyleId(String JavaDoc styleId) {
65         this.styleId = styleId;
66     }
67
68     public void init() {
69         try {
70             panel = (PanelInterface) getSkin().getPopupClass(model).newInstance();
71         } catch (Exception JavaDoc e) {
72             panel = new BasicPopupRenderer();
73         }
74     }
75 }
76
Popular Tags