KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icesoft > faces > el > LiteralBooleanMethodBinding


1 package com.icesoft.faces.el;
2
3 import javax.faces.el.MethodBinding;
4 import javax.faces.el.EvaluationException;
5 import javax.faces.el.MethodNotFoundException;
6 import javax.faces.context.FacesContext;
7 import java.io.Serializable JavaDoc;
8
9 /**
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
20     extends MethodBinding
21     implements Serializable JavaDoc
22 {
23     private String JavaDoc svalue;
24     private Boolean JavaDoc value;
25     
26     public LiteralBooleanMethodBinding(String JavaDoc svalue) {
27         this.svalue = svalue;
28         this.value = resolve(svalue);
29     }
30     
31     public Object JavaDoc invoke(FacesContext facesContext, Object JavaDoc[] objects)
32         throws EvaluationException, MethodNotFoundException
33     {
34         return value;
35     }
36     
37     public Class JavaDoc getType(FacesContext facesContext)
38         throws MethodNotFoundException
39     {
40         return Boolean JavaDoc.class;
41     }
42     
43     public String JavaDoc getExpressionString() {
44         return svalue;
45     }
46     
47     private static Boolean JavaDoc resolve(String JavaDoc value) {
48         Boolean JavaDoc ret = Boolean.FALSE;
49         if( value != null ) {
50             try {
51                 ret = Boolean.valueOf(value);
52             }
53             catch(Exception JavaDoc e) {} // Leave it as Boolean.FALSE
54
}
55         return ret;
56     }
57 }
58
Popular Tags