KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > jsfext > component > factory > basic > LavaChannelHrefFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the "License"). You may not use this file except
5  * in compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * glassfish/bootstrap/legal/CDDLv1.0.txt or
9  * https://glassfish.dev.java.net/public/CDDLv1.0.html.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * HEADER in each file and include the License file at
15  * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
16  * add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your
18  * own identifying information: Portions Copyright [yyyy]
19  * [name of copyright owner]
20  */

21 package com.sun.enterprise.tools.jsfext.component.factory.basic;
22
23 import com.sun.enterprise.tools.jsfext.component.factory.ComponentFactoryBase;
24 import com.sun.enterprise.tools.jsfext.layout.descriptor.LayoutComponent;
25 import com.sun.enterprise.tools.jsfext.component.LavaChannelHref;
26
27 import com.sun.web.ui.component.Hyperlink;
28
29 import javax.faces.component.UIComponent;
30 import javax.faces.context.FacesContext;
31
32
33 /**
34  * <p> This factory is responsible for instantiating a <code>Hyperlink
35  * UIComponent</code> that is configured to submit a LavaChannel
36  * request.</p>
37  *
38  * <p> All properties are passed through the underlying
39  * <code>Hyperlink</code> UIComponent.</p>
40  *
41  * @author Ken Paulsen (ken.paulsen@sun.com)
42  */

43 public class LavaChannelHrefFactory extends ComponentFactoryBase {
44
45     /**
46      * <p> This is the factory method responsible for creating the
47      * <code>UIComponent</code>. You should specify the
48      * <code>lavaTarget</code> for this component. See
49      * {@link #LAVA_CHANNEL_TARGET}.</p>
50      *
51      * @param context The <code>FacesContext</code>
52      * @param descriptor The {@link LayoutComponent} descriptor associated
53      * with the requested <code>UIComponent</code>.
54      * @param parent The parent <code>UIComponent</code>
55      *
56      * @return The newly created <code>LavaChannelHref</code>.
57      */

58     public UIComponent create(FacesContext context, LayoutComponent descriptor, UIComponent parent) {
59     // Create the UIComponent
60
Hyperlink href = new Hyperlink();
61
62     // This needs to be done here (before setOptions) so that $...{...}
63
// expressions can be resolved... may want to defer these?
64
if (parent != null) {
65         addChild(context, descriptor, parent, href);
66     }
67
68     // Set all the attributes / properties
69
setOptions(context, descriptor, href);
70
71     // Setup the LavaChannel Request
72
// FIXME: support javascript function to handle return value
73
// FIXME: support extra NVPs?? Maybe not needed? UIParameter instead? May be easier as a &n=v&... string.
74
String JavaDoc clientId = href.getClientId(context);
75 // FIXME: XXX DEAL WITH THIS!!!
76
// FIXME: BUG: JSF automatically converts the '&' characters in attributes to &amp; this causes a problem... talk to LH and JSF about this.
77
// String extraNVPs = "'&" + clientId + "_submittedField=" + clientId + "'";
78
String JavaDoc extraNVPs = "'" + clientId + "_submittedField=" + clientId + "'";
79     String JavaDoc jsHandlerFunction = "null";
80 // FIXME: Perhaps we can support multiple targets? If I render multiple sections of the UIComponent tree and return a document describing the results...
81
String JavaDoc target = (String JavaDoc) descriptor.getEvaluatedOption(context, LAVA_CHANNEL_TARGET, href);
82     if ((target == null) || target.equals("")) {
83         target = clientId;
84     }
85     href.setOnClick("submitLavaChannel('" + target + "', " +extraNVPs + ", " + jsHandlerFunction + "); return false;");
86
87     // Return the component
88
return href;
89     }
90
91     /**
92      * <p> This is the property that specifies the target for the
93      * lavaChannelRequest. If not specified, the link itself will be the
94      * target (which is likely not the desired target of the
95      * XMLHttpRequest). The target should be the clientId (i.e. the "id"
96      * you see in the HTML source) of the UIComponent.</p>
97      *
98      * <p> The property name is: <code>lavaTarget</code>.</p>
99      */

100     public static final String JavaDoc LAVA_CHANNEL_TARGET = "lavaTarget";
101 }
102
Popular Tags