| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.seasar.teeda.core.util; |
| 17 | |
|
| 18 | |
import javax.faces.application.Application; |
| 19 | |
import javax.faces.component.UIComponent; |
| 20 | |
import javax.faces.context.FacesContext; |
| 21 | |
import javax.faces.el.ValueBinding; |
| 22 | |
|
| 23 | |
import org.seasar.framework.container.ExternalContext; |
| 24 | |
import org.seasar.framework.container.S2Container; |
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
public class BindingUtil { |
| 31 | |
|
| 32 | 0 | private BindingUtil() { |
| 33 | 0 | } |
| 34 | |
|
| 35 | |
public static String getExpression(String componentName) { |
| 36 | 0 | return "#{" + componentName + "}"; |
| 37 | |
} |
| 38 | |
|
| 39 | |
public static String getExpression(String componentName, String propertyName) { |
| 40 | 0 | return "#{" + componentName + "." + propertyName + "}"; |
| 41 | |
} |
| 42 | |
|
| 43 | |
public static boolean isValueReference(String value) { |
| 44 | 734 | if (value == null) { |
| 45 | 0 | return false; |
| 46 | |
} |
| 47 | 734 | int start = value.indexOf("#{"); |
| 48 | 734 | if (start < 0) { |
| 49 | 726 | return false; |
| 50 | |
} |
| 51 | 8 | int end = value.lastIndexOf('}'); |
| 52 | 8 | return (end >= 0 && start < end); |
| 53 | |
} |
| 54 | |
|
| 55 | |
public static Object getValue(S2Container container, String name) { |
| 56 | 9 | Object var = getValue(container.getExternalContext(), name); |
| 57 | 9 | if (var != null) { |
| 58 | 0 | return var; |
| 59 | |
} |
| 60 | 9 | if (container.hasComponentDef(name)) { |
| 61 | 9 | return container.getComponent(name); |
| 62 | |
} |
| 63 | 0 | return null; |
| 64 | |
} |
| 65 | |
|
| 66 | |
public static Object getValue(ExternalContext externalContext, String name) { |
| 67 | 9 | Object var = externalContext.getRequestMap().get(name); |
| 68 | 9 | if (var != null) { |
| 69 | 0 | return var; |
| 70 | |
} |
| 71 | 9 | var = externalContext.getRequestParameterMap().get(name); |
| 72 | 9 | if (var != null && !"null".equals(var)) { |
| 73 | 0 | return var; |
| 74 | |
} |
| 75 | 9 | var = externalContext.getSessionMap().get(name); |
| 76 | 9 | if (var != null) { |
| 77 | 0 | return var; |
| 78 | |
} |
| 79 | 9 | return null; |
| 80 | |
} |
| 81 | |
|
| 82 | |
public static Object resolveBinding(String value) { |
| 83 | 0 | FacesContext context = FacesContext.getCurrentInstance(); |
| 84 | 0 | Application app = context.getApplication(); |
| 85 | 0 | ValueBinding vb = app.createValueBinding(value); |
| 86 | 0 | return vb.getValue(context); |
| 87 | |
} |
| 88 | |
|
| 89 | |
public static String resolveBindingNoException(String value) { |
| 90 | 0 | Object ret = null; |
| 91 | |
try { |
| 92 | 0 | ret = resolveBinding(value); |
| 93 | 0 | } catch (Exception ignore) { |
| 94 | 0 | return null; |
| 95 | 0 | } |
| 96 | 0 | return (ret != null) ? ret.toString() : null; |
| 97 | |
} |
| 98 | |
|
| 99 | |
public static Object getBindingValue(UIComponent component, |
| 100 | |
String propertyName) { |
| 101 | 0 | ValueBinding binding = component.getValueBinding(propertyName); |
| 102 | 0 | if (binding != null) { |
| 103 | 0 | FacesContext ctx = FacesContext.getCurrentInstance(); |
| 104 | 0 | return binding.getValue(ctx); |
| 105 | |
} |
| 106 | 0 | return null; |
| 107 | |
} |
| 108 | |
|
| 109 | |
public static void setValueBinding(UIComponent component, String name, |
| 110 | |
String value) { |
| 111 | 2 | FacesContext ctx = FacesContext.getCurrentInstance(); |
| 112 | 2 | Application app = ctx.getApplication(); |
| 113 | 2 | ValueBinding binding = app.createValueBinding(value); |
| 114 | 2 | component.setValueBinding(name, binding); |
| 115 | 2 | } |
| 116 | |
} |