1 /*
2 * $Id: LinkSubscriptionTag.java 471754 2006-11-06 14:55:09Z husted $
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22
23 package org.apache.struts.webapp.example;
24
25
26 import javax.faces.component.UIComponent;
27 import javax.faces.context.FacesContext;
28 import javax.faces.el.ValueBinding;
29 import javax.faces.webapp.UIComponentTag;
30
31
32 /**
33 * Generate a URL-encoded hyperlink to the specified URI, with
34 * associated query parameters selecting a specified Subscription.
35 *
36 * @author Craig R. McClanahan
37 * @version $Rev: 471754 $ $Date: 2006-11-06 08:55:09 -0600 (Mon, 06 Nov 2006) $
38 */
39
40 public class LinkSubscriptionTag extends UIComponentTag {
41
42
43 // -------------------------------------------------------------- Attributes
44
45
46 /**
47 * The attribute name.
48 */
49 protected String name = "subscription";
50
51 public void setName(String name) {
52 this.name = name;
53 }
54
55
56 /**
57 * The context-relative URI.
58 */
59 protected String page = null;
60
61 public void setPage(String page) {
62 this.page = page;
63 }
64
65
66 // ---------------------------------------------------------- Public Methods
67
68
69 /**
70 * Return the component type for this tag.</p>
71 */
72 public String getComponentType() {
73
74 return ("javax.faces.Output");
75
76 }
77
78
79 /**
80 * <p>Return the renderer type associated with this tag.</p>
81 */
82 public String getRendererType() {
83
84 return ("org.apache.struts.webapp.example.LinkSubscription");
85
86 }
87
88
89 /**
90 * <p>Release resources allocated to this tag instance.</p>
91 */
92 public void release() {
93
94 super.release();
95 this.name = "subscription";
96 this.page = null;
97
98 }
99
100
101 // ------------------------------------------------------- Protected Methods
102
103
104 /**
105 * <p>Override attributes set on this tag instance.</p>
106 *
107 * @param component Component whose attributes should be overridden
108 */
109 protected void setProperties(UIComponent component) {
110
111 super.setProperties(component);
112 FacesContext context = getFacesContext();
113 if (name != null) {
114 if (isValueReference(name)) {
115 ValueBinding vb =
116 context.getApplication().createValueBinding(name);
117 component.setValueBinding("name", vb);
118 } else {
119 component.getAttributes().put("name", name);
120 }
121 }
122 if (page != null) {
123 if (isValueReference(page)) {
124 ValueBinding vb =
125 context.getApplication().createValueBinding(page);
126 component.setValueBinding("page", vb);
127 } else {
128 component.getAttributes().put("page", page);
129 }
130 }
131
132 }
133
134
135 }