01: package com.icesoft.faces.el;
02:
03: import javax.faces.el.MethodBinding;
04: import javax.faces.el.EvaluationException;
05: import javax.faces.el.MethodNotFoundException;
06: import javax.faces.context.FacesContext;
07: import java.io.Serializable;
08:
09: /**
10: * The EL that Facelets uses allows for a MethodBinding with
11: * "true" or "false" that will resolve to Boolean.TRUE or
12: * Boolean.FALSE. The EL with JSF1.1-JSP doesn't seem so
13: * forgiving. So we need this helper class to act as a
14: * MethodBinding, but just return a constant Boolean value.
15: *
16: * @author Mark Collette
17: * @since 1.6
18: */
19: public class LiteralBooleanMethodBinding extends MethodBinding
20: implements Serializable {
21: private String svalue;
22: private Boolean value;
23:
24: public LiteralBooleanMethodBinding(String svalue) {
25: this .svalue = svalue;
26: this .value = resolve(svalue);
27: }
28:
29: public Object invoke(FacesContext facesContext, Object[] objects)
30: throws EvaluationException, MethodNotFoundException {
31: return value;
32: }
33:
34: public Class getType(FacesContext facesContext)
35: throws MethodNotFoundException {
36: return Boolean.class;
37: }
38:
39: public String getExpressionString() {
40: return svalue;
41: }
42:
43: private static Boolean resolve(String value) {
44: Boolean ret = Boolean.FALSE;
45: if (value != null) {
46: try {
47: ret = Boolean.valueOf(value);
48: } catch (Exception e) {
49: } // Leave it as Boolean.FALSE
50: }
51: return ret;
52: }
53: }
|