1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.myfaces.tobago.internal.taglib.component;
21
22 import org.apache.myfaces.tobago.apt.annotation.BodyContent;
23 import org.apache.myfaces.tobago.apt.annotation.Tag;
24 import org.apache.myfaces.tobago.apt.annotation.TagAttribute;
25 import org.apache.myfaces.tobago.apt.annotation.TagGeneration;
26 import org.apache.myfaces.tobago.component.Attributes;
27 import org.apache.myfaces.tobago.event.PopupActionListener;
28
29 import javax.el.ValueExpression;
30 import javax.faces.component.ActionSource;
31 import javax.faces.component.UIComponent;
32 import javax.faces.context.FacesContext;
33 import javax.faces.webapp.UIComponentClassicTagBase;
34 import javax.faces.webapp.UIComponentELTag;
35 import javax.servlet.jsp.JspException;
36 import javax.servlet.jsp.tagext.TagSupport;
37
38
39
40
41
42 @Tag(name = "popupReference", bodyContent = BodyContent.EMPTY)
43 @TagGeneration(className = "org.apache.myfaces.tobago.internal.taglib.PopupReferenceTag")
44 public abstract class PopupReferenceTag extends TagSupport {
45
46 private static final long serialVersionUID = 2L;
47
48 private javax.el.ValueExpression forValue;
49
50 public int doStartTag() throws JspException {
51
52
53 UIComponentClassicTagBase tag =
54 UIComponentELTag.getParentUIComponentClassicTagBase(pageContext);
55 if (tag == null) {
56
57 throw new JspException("Not nested in faces tag");
58 }
59
60 if (!tag.getCreated()) {
61 return (SKIP_BODY);
62 }
63
64 UIComponent component = tag.getComponentInstance();
65 if (component == null) {
66
67 throw new JspException("Component Instance is null");
68 }
69 if (!(component instanceof ActionSource)) {
70
71 throw new JspException("Component " + component.getClass().getName() + " is not instanceof ActionSource");
72 }
73 ActionSource actionSource = (ActionSource) component;
74
75 component.setValueExpression(Attributes.FOR, forValue);
76
77 if (forValue.isLiteralText()) {
78 actionSource.addActionListener(new PopupActionListener(
79 (String) forValue.getValue(FacesContext.getCurrentInstance().getELContext())));
80 } else {
81 component.setValueExpression(Attributes.FOR, forValue);
82 }
83 return (SKIP_BODY);
84 }
85
86
87
88
89 @TagAttribute(required = true, name = "for", type = "java.lang.String")
90 public void setFor(ValueExpression forValue) {
91 this.forValue = forValue;
92 }
93
94 }