01: /*
02: * Copyright 2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.apache.myfaces.shared_impl.util;
17:
18: import javax.faces.component.UIComponent;
19: import javax.faces.context.FacesContext;
20: import javax.faces.el.ValueBinding;
21:
22: import org.apache.myfaces.shared_impl.renderkit.html.util.FormInfo;
23:
24: /**
25: * @author Mathias Brökelmann (latest modification by $Author: dennisbyrne $)
26: * @version $Revision: 511707 $ $Date: 2007-02-26 03:58:32 +0100 (Mo, 26 Feb 2007) $
27: */
28: public final class _ComponentUtils {
29: public static final String COMPONENT_FAMILY = "javax.faces.Form";
30:
31: private _ComponentUtils() {
32: }
33:
34: public static String getStringValue(FacesContext context,
35: ValueBinding vb) {
36: Object value = vb.getValue(context);
37: if (value != null) {
38: return value.toString();
39: }
40: return null;
41: }
42:
43: public static FormInfo findNestingForm(UIComponent uiComponent,
44: FacesContext facesContext) {
45: UIComponent parent = uiComponent.getParent();
46: while (parent != null
47: && !COMPONENT_FAMILY.equals(parent.getFamily())) {
48: parent = parent.getParent();
49: }
50:
51: if (parent != null) {
52: //link is nested inside a form
53: String formName = parent.getClientId(facesContext);
54: return new FormInfo(parent, formName);
55: }
56:
57: return null;
58: }
59: }
|